public Computer(Dictionary <char, Dictionary <int, positionInfo> > positions, Dictionary <PictureBox, ChessPosition> positionOnBoard, Dictionary <PictureBox, ChessPiece> boardPieces, List <ChessPiece> myPieces, List <ChessPiece> enemyPieces, Dictionary <char, Dictionary <int, PictureBox> > boardPos) { Positions = positions; PositionOnBoard = positionOnBoard; BoardPieces = boardPieces; MyPieces = myPieces; EnemyPieces = enemyPieces; BoardPos = boardPos; random = new Random(); moves = new MovesTree(Positions, EnemyPieces, MyPieces, null); }
public Moves evaluate() { moves = new MovesTree(Positions, EnemyPieces, MyPieces, null); InitializeTree(3, moves.Root, true, Positions); List <int> nodes = new List <int>(); foreach (var Child in moves.Root.Children) { nodes.Add(moves.AlphaBeta(Child, 2, int.MinValue, int.MaxValue, true)); } int min = int.MaxValue; foreach (var nodeValues in nodes) { if (nodeValues < min) { min = nodeValues; } } MovesNode move = moves.Root.Children[nodes.IndexOf(min)]; if (move.move.PieceTaken) { EnemyPieces.Remove(Positions[move.move.destiny_X][move.move.destiny_Y].piece); Controls.Remove(Positions[move.move.destiny_X][move.move.destiny_Y].piece.Piece); BoardPieces.Remove(Positions[move.move.destiny_X][move.move.destiny_Y].piece.Piece); Positions[move.move.destiny_X][move.move.destiny_Y].ocupied = true; Positions[move.move.destiny_X][move.move.destiny_Y].piece = Positions[move.move.startX][move.move.startY].piece; Positions[move.move.startX][move.move.startY].ocupied = false; Positions[move.move.startX][move.move.startY].piece = null; Positions[move.move.destiny_X][move.move.destiny_Y].piece.MovePiece(move.move.destiny_X, move.move.destiny_Y); AnimateMovement(BoardPos[move.move.destiny_X][move.move.destiny_Y], Positions[move.move.destiny_X][move.move.destiny_Y].piece.Piece); return(move.move); } else { Positions[move.move.destiny_X][move.move.destiny_Y].ocupied = true; Positions[move.move.destiny_X][move.move.destiny_Y].piece = Positions[move.move.startX][move.move.startY].piece; Positions[move.move.startX][move.move.startY].ocupied = false; Positions[move.move.startX][move.move.startY].piece = null; Positions[move.move.destiny_X][move.move.destiny_Y].piece.MovePiece(move.move.destiny_X, move.move.destiny_Y); AnimateMovement(BoardPos[move.move.destiny_X][move.move.destiny_Y], Positions[move.move.destiny_X][move.move.destiny_Y].piece.Piece); return(move.move); } }