如何实现c#方法的父级
这种方法是先对当前棋盘进行所有移动,然后对对手进行所有移动,然后对玩家1进行未来移动,并评估最佳移动。 如何获得此最佳移动的根或父级 这是我的密码如何实现c#方法的父级,c#,logic,artificial-intelligence,parent,lookahead,C#,Logic,Artificial Intelligence,Parent,Lookahead,这种方法是先对当前棋盘进行所有移动,然后对对手进行所有移动,然后对玩家1进行未来移动,并评估最佳移动。 如何获得此最佳移动的根或父级 这是我的密码 public override Move GetMove(Board board) { List<Move> moves = board.getMoveList(); double bestValue, currentValue; ; Move bestMove = moves.First(); Board
public override Move GetMove(Board board)
{
List<Move> moves = board.getMoveList();
double bestValue, currentValue; ;
Move bestMove = moves.First();
Board firstBoard = board.DeepClone();
firstBoard.Move(bestMove);
bestValue = Evaluator(firstBoard);
List<Move> tieMoves = new List<Move>();
foreach (Move aMove in moves)
{
Board board2 = board.DeepClone();
board2.Move(aMove);
// If there is a move in one take it and leave
if (board2.WhoWon() == side)
return aMove;
// check player 2 moves
foreach (Move bMove in moves)
{
Board board3 = board2.DeepClone();
board3.Move(bMove);
// If there is a move in one take it and leave
if (board3.WhoWon() == side)
return aMove;
// check player 1 future moves
foreach (Move bMove in moves)
{
Board board4 = board3.DeepClone();
board4.Move(cMove);
// If there is a move in one take it and leave
if (board4.WhoWon() == side)
return aMove;
currentValue = Evaluator(board4);
if (
(side == Pieces.ATTACK && currentValue > bestValue)
|| (side == Pieces.DEFEND && currentValue < bestValue)
)
{
tieMoves = new List<Move>();
tieMoves.Add(aMove);
bestMove = aMove;
bestValue = currentValue;
}
}
}
}
// Pick one from the candidate moves with the same value
return tieMoves.ElementAt(random.Next(tieMoves.Count));
}
公共覆盖移动GetMove(板)
{
列表移动=board.getMoveList();
双最佳值,当前值;
Move bestMove=moves.First();
Board firstBoard=Board.DeepClone();
第一板。移动(最佳移动);
最佳值=评估者(第一板);
List tieMoves=新列表();
foreach(移动aMove in moves)
{
Board board2=Board.DeepClone();
2.搬家(搬家);
//如果有一个人要搬家,就把它带走
如果(board2.whowen()==侧)
回归爱情;
//检查玩家2个动作
foreach(移动b在移动中移动)
{
Board board3=board2.DeepClone();
3.移动(b移动);
//如果有一个人要搬家,就把它带走
如果(board3.whowen()==侧)
回归爱情;
//检查玩家1未来的移动
foreach(移动b在移动中移动)
{
Board board4=board3.DeepClone();
董事会4.移动(cMove);
//如果有一个人要搬家,就把它带走
如果(board4.whowen()==侧)
回归爱情;
currentValue=评估器(board4);
如果(
(side==Pieces.ATTACK&¤tValue>bestValue)
||(side==Pieces.defect&¤tValue
您应该只将aMove添加到tieMoves列表中,因为您只想执行其中一个aMove,但bestValue将保留为bMove、cMove、aMove或您选择的任何内容。通过这种方式,您可以比较最好的子级结果(即先a后B再C的结果),但您可以存储父级移动(移动是您需要执行的第一个移动)我意识到,在发布此消息后,由于我只是在某个事件中寻找领带,因此没有更好的移动。您没有问我们任何问题。请阅读。