public void ConvertBitBoardMoveToString_IsCorrectStringReturned_Equals() { ChessBoard chessBoard = new ChessBoard(); chessBoard.WhiteKnight.Bits = BoardSquare.B8 | BoardSquare.G8; ColoredBitBoard toCoordinate = new KnightBitBoard(ChessPieceColors.White); toCoordinate.Bits = BoardSquare.C6 | BoardSquare.G8; string correctMoveString = "b8c6"; StringBitboardConverter converter = new StringBitboardConverter(chessBoard, ChessPieceColors.White); Assert.Equal(correctMoveString, converter.ConvertBitBoardMoveToString(toCoordinate)); }
public void ConvertBitBoardMoveToString_IsCorrectPromotionKnightStringReturned_Equals() { ChessBoard chessBoard = new ChessBoard(); chessBoard.WhitePawn.Bits = BoardSquare.A2 | BoardSquare.B2 | BoardSquare.C2 | BoardSquare.D2 | BoardSquare.E7 | BoardSquare.F2 | BoardSquare.G2 | BoardSquare.H2; PawnBitBoard toCoordinate = new PawnBitBoard(ChessPieceColors.White); toCoordinate.Bits = BoardSquare.A2 | BoardSquare.B2 | BoardSquare.C2 | BoardSquare.D2 | BoardSquare.E8 | BoardSquare.F2 | BoardSquare.G2 | BoardSquare.H2; toCoordinate.Promote(PawnBitBoard.PromotionPiece.Knight); string correctMoveString = "e7e8n"; StringBitboardConverter converter = new StringBitboardConverter(chessBoard, ChessPieceColors.White); Assert.Equal(correctMoveString, converter.ConvertBitBoardMoveToString(toCoordinate)); }
private void DoMove() { if (whiteTurn && isFirstGo) { winboardColor = ChessPieceColors.Black; engineColor = ChessPieceColors.White; _winboardConverter = new StringBitboardConverter(chessBoard, winboardColor); _engineConverter = new StringBitboardConverter(chessBoard, engineColor); } #if DEBUG Stopwatch sw = new Stopwatch(); sw.Start(); #endif ColoredBitBoard bitBoardMoveTaken = NegaMax.GetBestMove(chessBoard, depth, engineColor, MoveGen.GenerateLegalMoves, Eval.EvaluateState); #if DEBUG sw.Stop(); Logger.OutputTime(sw.ElapsedMilliseconds.ToString()); sw.Reset(); #endif if ((bitBoardMoveTaken != null) && (chessBoard.State != ChessBoardGameState.Draw)) { string stringMoveTaken = _engineConverter.ConvertBitBoardMoveToString(bitBoardMoveTaken); Debug.Assert(STRINGMOVE_FORMAT.IsMatch(stringMoveTaken)); chessBoard.Update(bitBoardMoveTaken); Logger.OutputMove(stringMoveTaken); #if DEBUG_SOLO if (Enemy) { Console.WriteLine(stringMoveTaken); } else { OtherProcess.StandardInput.WriteLine(stringMoveTaken); } #else Console.WriteLine("move " + stringMoveTaken); #endif whiteTurn = !whiteTurn; } else { if (chessBoard.WhiteKing.IsChecked) { chessBoard.State = ChessBoardGameState.BlackMate; Console.WriteLine("result 0-1 {Black Wins by Checkmate}"); } else if (chessBoard.BlackKing.IsChecked) { chessBoard.State = ChessBoardGameState.WhiteMate; Console.WriteLine("result 1-0 {White Wins by Checkmate}"); } else { chessBoard.State = ChessBoardGameState.Draw; Console.WriteLine("result 1/2-1/2 {Draw}"); } } }