public void ExecuteMove(Move move) { move.Execute(Board); PastMoves.Push(move); CheckPawnPromotion(); ChangeTurns(); }
// read a board state and select a suitable move to return public string SelectMove(string fen) { var Board = new Board(fen); // load the board // store the enemy's last move if (LastBoard != null) { var LastMove = BoardDiff(LastBoard, Board); if (LastMove == null) { throw new Exception("could not determine last move using a board diff"); } if (PastMoves.Count == 8) { PastMoves.Dequeue(); } PastMoves.Enqueue(LastMove); } // assign engine's past moves to the board and search for the best move Board.PastMoves = PastMoves; MoveGen.MoveBoardPair Mbp = Searcher.Search(Board, Depth, QuiescentDepth, Alpha, Beta, MoveTimeLimit); LastBoard = Mbp.Board; return(Mbp.Move.ToString()); }
private void CheckPawnCaptures(Move move, List <Move> movesToRemove, List <Move> movesToAdd) { // Check For Capture if (move.Destination.X != move.Origin.X) { // No Past Moves Means It Can't Be En Passant Or Capture if (PastMoves.Count == 0) { movesToRemove.Add(move); Board.GetPieceAt(move.Origin).ValidMoves.Remove(move); } // Check For En Passant else if (Board.GetPieceAt(move.Destination) == null) { Move lastMove = PastMoves.Peek(); // Last Piece Moved Isn't A Pawn Or It Had Been Previously Moved if (lastMove.Moved.Type != PieceType.Pawn || lastMove.Moved.HasMoved) { movesToRemove.Add(move); Board.GetPieceAt(move.Origin).ValidMoves.Remove(move); } // Last Piece Moved Isn't In Correct Position For En Passant else if (lastMove.Destination.X != move.Destination.X || lastMove.Destination.Y != move.Origin.Y) { movesToRemove.Add(move); Board.GetPieceAt(move.Origin).ValidMoves.Remove(move); } // Move Is En Passant else { movesToRemove.Add(move); Board.GetPieceAt(move.Origin).ValidMoves.Remove(move); Move enpassant = new EnPassantMove(move.Moved, move.Origin, move.Destination, Board.GetPieceAt(new Position(move.Destination.X, move.Origin.Y))); movesToAdd.Add(enpassant); Board.GetPieceAt(enpassant.Origin).ValidMoves.Add(enpassant); } } // Can't Attack Own Piece else if (Board.GetPieceAt(move.Destination).Color == move.Moved.Color) { movesToRemove.Add(move); Board.GetPieceAt(move.Origin).ValidMoves.Remove(move); } } }