x01.Weiqi.4 人机大战
人工智能的发展,必将影响或危害到人类。这就像人类的发展已经影响或危害到老虎、狮子一样。但有此担忧,就放弃发展人工智能吗?大可不必:
1. 在危害到人类以前,人工智能对人类是有帮助的;
2. 比起不可预知的核战争或宇宙灾害,人工智能的危害要小;
3. 人工智能的发展,很有可能帮助人类应付不可预知的核战争或宇宙灾害。
当然,这一切都是假如。这个问题,还是留给历史学家,政治家,哲学家们去讨论吧。子不语怪力乱神,我们又何必杞人忧天呢?
人机大战的关键,在于寻找正确的落子点。这可是个天大的问题,还是让天下人共同解决之吧。我只实现了最简单的随机落子。添加一个类 WhereBoard,继承自 BoardBase。
代码文件 WhereBoard.cs 内容如下:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
namespace x01.Weiqi.Board
{
class WhereBoard : BoardBase
{
Timer m_Timer =new Timer();
Random m_rand =new Random();
bool m_CanDown =true;
public WhereBoard(int size =38)
: base(size)
{
m_Timer.Interval =1000;
m_Timer.Tick +=new EventHandler(Timer_Tick);
m_Timer.Start();
}
void Timer_Tick(object sender, EventArgs e)
{
if (m_CanDown)
{
return;
}
Pos pos = Think();
int col = pos.X;
int row = pos.Y;
if (NotIn(col, row))
{
return;
}
DrawChess(col, row);
Eat(col, row);
m_CanDown =true; ;
}
private Pos Think()
{
Pos pos =new Pos(0, 0);
while (true)
{
pos.X = m_rand.Next(0, 18);
pos.Y = m_rand.Next(0, 18);
if (Steps[pos.X, pos.Y].Color == ChessColor.Empty)
{
break;
}
}
return pos;
}
protectedoverridevoid OnMouseLeftButtonDown(System.Windows.Input.MouseButtonEventArgs e)
{
base.OnMouseLeftButtonDown(e);
if (!m_CanDown)
{
return;
}
int col = (int)e.GetPosition(this).X / ChessSize;
int row = (int)e.GetPosition(this).Y / ChessSize;
if (NotIn(col, row))
{
return;
}
DrawChess(col, row);
Eat(col, row);
m_CanDown =false;
}
}
}
{
class WhereBoard : BoardBase
{
Timer m_Timer =new Timer();
Random m_rand =new Random();
bool m_CanDown =true;
public WhereBoard(int size =38)
: base(size)
{
m_Timer.Interval =1000;
m_Timer.Tick +=new EventHandler(Timer_Tick);
m_Timer.Start();
}
void Timer_Tick(object sender, EventArgs e)
{
if (m_CanDown)
{
return;
}
Pos pos = Think();
int col = pos.X;
int row = pos.Y;
if (NotIn(col, row))
{
return;
}
DrawChess(col, row);
Eat(col, row);
m_CanDown =true; ;
}
private Pos Think()
{
Pos pos =new Pos(0, 0);
while (true)
{
pos.X = m_rand.Next(0, 18);
pos.Y = m_rand.Next(0, 18);
if (Steps[pos.X, pos.Y].Color == ChessColor.Empty)
{
break;
}
}
return pos;
}
protectedoverridevoid OnMouseLeftButtonDown(System.Windows.Input.MouseButtonEventArgs e)
{
base.OnMouseLeftButtonDown(e);
if (!m_CanDown)
{
return;
}
int col = (int)e.GetPosition(this).X / ChessSize;
int row = (int)e.GetPosition(this).Y / ChessSize;
if (NotIn(col, row))
{
return;
}
DrawChess(col, row);
Eat(col, row);
m_CanDown =false;
}
}
}
实在没有什么好说的,只不过把圈画圆而已。
源代码可从 http://www.cnblogs.com/china_x01 的download\code\x01.Weiqi 获取。
Copyright (c) 2011 by x01(china_x01@qq.com),未经许可,请勿转载。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步