Beispiel #1
0
        public void BestMoveTest_WhiteDepth2()
        {
            ChessBoard input = new ChessBoard();

            input.InitializeScenario(new ScenarioList {
                { BoardSquare.C2, ChessPieceType.Pawn, ChessPieceColors.White },
                { BoardSquare.B3, ChessPieceType.Pawn, ChessPieceColors.Black },
                { BoardSquare.H1, ChessPieceType.King, ChessPieceColors.White },
                { BoardSquare.B4, ChessPieceType.King, ChessPieceColors.Black },
                { BoardSquare.D3, ChessPieceType.Pawn, ChessPieceColors.Black }
            });

            //Used for depth 2
            bool            depth2MoveEqual = false;
            ColoredBitBoard depth2Test      = NegaMax.GetBestMove(input, 2, ChessPieceColors.White, GenerateStaticMoves_Depth12, GetStaticMaterialValueDepth2_White);
            PawnBitBoard    optimalMove     = new PawnBitBoard(ChessPieceColors.White);

            optimalMove.Bits = BoardSquare.D3;
            if (depth2Test is PawnBitBoard)
            {
                depth2Test = (PawnBitBoard)depth2Test;
                if (depth2Test.Bits == optimalMove.Bits)
                {
                    depth2MoveEqual = true;
                }
            }
            Assert.True(depth2MoveEqual);
        }
Beispiel #2
0
        public void NotTerminal_White()
        {
            ChessBoard notTerminal = new ChessBoard();

            notTerminal.InitializeScenario(new ScenarioList {
                { BoardSquare.A1, ChessPieceType.King, ChessPieceColors.White },
                { BoardSquare.H8, ChessPieceType.King, ChessPieceColors.Black },
                { BoardSquare.A2, ChessPieceType.Pawn, ChessPieceColors.White },
                { BoardSquare.H7, ChessPieceType.Pawn, ChessPieceColors.Black }
            });

            NegaMax.TerminalConditions resultWhiteNotTerminal = NegaMax.IsTerminal_Debug(notTerminal, ChessPieceColors.White, GenerateStaticMoves_White_Depth1);
            Assert.Equal(NegaMax.TerminalConditions.NotTerminal, resultWhiteNotTerminal);
        }
Beispiel #3
0
        public void BestMoveTest_BlackDepth1()
        {
            ChessBoard input = new ChessBoard();

            input.InitializeScenario(new ScenarioList {
                { BoardSquare.C2, ChessPieceType.Pawn, ChessPieceColors.White },
                { BoardSquare.B3, ChessPieceType.Pawn, ChessPieceColors.Black },
                { BoardSquare.H1, ChessPieceType.King, ChessPieceColors.White },
                { BoardSquare.B4, ChessPieceType.King, ChessPieceColors.Black },
                { BoardSquare.D3, ChessPieceType.Pawn, ChessPieceColors.Black }
            });
            PawnBitBoard bestMoveBlack1 = new PawnBitBoard(ChessPieceColors.Black);

            bestMoveBlack1.Bits = (input.BlackPawn.Bits ^ BoardSquare.D3) | BoardSquare.C2 | BoardSquare.B3;

            PawnBitBoard bestMoveBlack2 = new PawnBitBoard(ChessPieceColors.Black);

            bestMoveBlack2.Bits = (input.BlackPawn.Bits ^ BoardSquare.B3) | BoardSquare.C2 | BoardSquare.D3;

            Tuple <BitBoard, int> outputTuple_Black1 = new Tuple <BitBoard, int>(bestMoveBlack1, -1);
            Tuple <BitBoard, int> outputTuple_Black2 = new Tuple <BitBoard, int>(bestMoveBlack2, -1);

            BitBoard blackBoard1 = outputTuple_Black1.Item1;
            BitBoard blackBoard2 = outputTuple_Black2.Item1;

            int blackVal = outputTuple_Black1.Item2;

            //ÆNDRE TEST HER!
            BitBoard testTuple_Black = NegaMax.GetBestMove(input, 1, ChessPieceColors.Black, GenerateStaticMoves_Black_Depth1, Eval.EvaluateState);

            int blackVal_Test = outputTuple_Black1.Item2;

            bool blackBoardEqual    = false;
            bool blackBoardValEqual = false;

            //Black test comparison
            if (blackVal == blackVal_Test)
            {
                blackBoardValEqual = true;
            }
            if (testTuple_Black is PawnBitBoard)
            {
                if (testTuple_Black.Bits == blackBoard1.Bits | testTuple_Black.Bits == blackBoard2.Bits)
                {
                    blackBoardEqual = true;
                }
            }
            Assert.True(blackBoardValEqual && blackBoardEqual);
        }
Beispiel #4
0
        public void DrawTest_Black()
        {
            //Draw state test
            ChessBoard draw = new ChessBoard();

            draw.InitializeScenario(new ScenarioList {
                { BoardSquare.A8, ChessPieceType.King, ChessPieceColors.Black },
                { BoardSquare.B7, ChessPieceType.Rook, ChessPieceColors.White },
                { BoardSquare.H1, ChessPieceType.King, ChessPieceColors.White }
            });


            NegaMax.TerminalConditions resultBlackDraw = NegaMax.IsTerminal_Debug(draw, ChessPieceColors.Black, GenerateCheckMateMoves);
            Assert.Equal(NegaMax.TerminalConditions.Draw, resultBlackDraw);
        }
Beispiel #5
0
        public void CheckmateTest_Black()
        {
            //Checkmate state test
            ChessBoard checkmate = new ChessBoard();

            checkmate.InitializeScenario(new ScenarioList {
                { BoardSquare.G8, ChessPieceType.Rook, ChessPieceColors.White },
                { BoardSquare.D6, ChessPieceType.Knight, ChessPieceColors.White },
                { BoardSquare.D8, ChessPieceType.King, ChessPieceColors.Black }
            });
            checkmate.BlackKing.IsChecked = true;
            NegaMax.TerminalConditions result = NegaMax.IsTerminal_Debug(checkmate, ChessPieceColors.Black, GenerateCheckMateMoves);

            Assert.Equal(NegaMax.TerminalConditions.Win, result);
        }
Beispiel #6
0
        public void BestMoveTest_WhiteDepth1()
        {
            ChessBoard input = new ChessBoard();

            input.InitializeScenario(new ScenarioList {
                { BoardSquare.C2, ChessPieceType.Pawn, ChessPieceColors.White },
                { BoardSquare.B3, ChessPieceType.Pawn, ChessPieceColors.Black },
                { BoardSquare.H1, ChessPieceType.King, ChessPieceColors.White },
                { BoardSquare.B4, ChessPieceType.King, ChessPieceColors.Black },
                { BoardSquare.D3, ChessPieceType.Pawn, ChessPieceColors.Black }
            });

            //Used for Depth 1
            PawnBitBoard bestMoveWhite1 = new PawnBitBoard(ChessPieceColors.White);

            bestMoveWhite1.Bits = BoardSquare.B3;
            PawnBitBoard bestMoveWhite2 = new PawnBitBoard(ChessPieceColors.White);

            bestMoveWhite2.Bits = BoardSquare.D3;
            Tuple <BitBoard, int> outputTuple_White1 = new Tuple <BitBoard, int>(bestMoveWhite1, 1);
            Tuple <BitBoard, int> outputTuple_White2 = new Tuple <BitBoard, int>(bestMoveWhite2, 1);
            BitBoard whiteBoard1 = outputTuple_White1.Item1;
            BitBoard whiteBoard2 = outputTuple_White2.Item1;
            int      whiteVal    = outputTuple_White1.Item2;
            //ÆNDRE TEST HER!
            BitBoard testTuple_White = NegaMax.GetBestMove(input, 1, ChessPieceColors.White, GenerateStaticMoves_White_Depth1, Eval.EvaluateState);
            int      whiteVal_Test   = outputTuple_White1.Item2;


            bool whiteBoardEqual    = false;
            bool whiteBoardValEqual = false;

            //White test comparison
            if (whiteVal == whiteVal_Test)
            {
                whiteBoardValEqual = true;
            }
            if (testTuple_White is PawnBitBoard)
            {
                if (testTuple_White.Bits == whiteBoard1.Bits || testTuple_White.Bits == whiteBoard2.Bits)
                {
                    whiteBoardEqual = true;
                }
            }

            Assert.True(whiteBoardValEqual && whiteBoardEqual);
        }
Beispiel #7
0
        private static void EvalFail()
        {
            ChessBoard lolBoard = new ChessBoard();

            lolBoard.InitializeGame();
            //White
            PawnBitBoard pawnWhite = new PawnBitBoard(ChessPieceColors.White);

            pawnWhite.Bits = BoardSquare.A2 | BoardSquare.B2 | BoardSquare.C2 | BoardSquare.D2 | BoardSquare.E2 | BoardSquare.F2 | BoardSquare.G2 | BoardSquare.H3;

            PawnBitBoard pawnBlack = new PawnBitBoard(ChessPieceColors.Black);

            pawnBlack.Bits = BoardSquare.A7 | BoardSquare.B7 | BoardSquare.C7 | BoardSquare.D7 | BoardSquare.E7 | BoardSquare.F5 | BoardSquare.G7 | BoardSquare.H7;

            lolBoard.Update(pawnWhite);
            lolBoard.Update(pawnBlack);
            ColoredBitBoard bestMove = NegaMax.GetBestMove(lolBoard, 3, ChessPieceColors.White, MoveGen.GenerateLegalMoves, Eval.EvaluateState);
        }
Beispiel #8
0
        public void Test_super()
        {
            Winboard winboard = new Winboard();


            winboard.Handler("new");
            winboard.Handler("force");
            winboard.Handler("e2e4");
            winboard.Handler("e7e5");
            winboard.Handler("b1c3");
            winboard.Handler("g8f6");
            winboard.Handler("f2f3");
            winboard.Handler("c7c5");
            winboard.Handler("d2d3");
            winboard.engineColor = winboard.engineColor == ChessPieceColors.White ? ChessPieceColors.Black : ChessPieceColors.White;
            NegaMax.NegaMaxAlgorithm(winboard.chessBoard, 2, int.MinValue + 5, int.MaxValue - 4, ChessPieceColors.White, MoveGen.GenerateLegalMoves, Eval.EvaluateState);
            //winboard.Handler( "go" );

            Assert.True(true);
        }
Beispiel #9
0
        private static void sacrificeQueenDebugStuffSomethingTestMethod()
        {
            //Winboard winboard = new Winboard();
            ChessBoard lolBoard = new ChessBoard();

            lolBoard.InitializeGame();

            //White
            PawnBitBoard pawnWhite = new PawnBitBoard(ChessPieceColors.White);

            pawnWhite.Bits = BoardSquare.A4 | BoardSquare.C2 | BoardSquare.D3 | BoardSquare.E4 | BoardSquare.F2 | BoardSquare.G2;

            BishopBitBoard bishopWhite = new BishopBitBoard(ChessPieceColors.White);

            bishopWhite.Bits = BoardSquare.E2 | BoardSquare.H4;

            KingBitBoard kingWhite = new KingBitBoard(ChessPieceColors.White);

            kingWhite.Bits = BoardSquare.E1;

            RookBitBoard rookWhite = new RookBitBoard(ChessPieceColors.White);

            rookWhite.Bits = BoardSquare.B1 | BoardSquare.H1;

            KnightBitBoard knightWhite = new KnightBitBoard(ChessPieceColors.White);

            knightWhite.Bits = BoardSquare.D2;

            QueenBitBoard queenWhite = new QueenBitBoard(ChessPieceColors.White);

            queenWhite.Bits = BoardSquare.D1;

            //Black
            PawnBitBoard pawnBlack = new PawnBitBoard(ChessPieceColors.Black);

            pawnBlack.Bits = BoardSquare.A7 | BoardSquare.B7 | BoardSquare.C5 | BoardSquare.E5 | BoardSquare.H5;
            RookBitBoard rookBlack = new RookBitBoard(ChessPieceColors.Black);

            rookBlack.Bits = BoardSquare.A8 | BoardSquare.H7;

            BishopBitBoard bishopBlack = new BishopBitBoard(ChessPieceColors.Black);

            bishopBlack.Bits = BoardSquare.C8 | BoardSquare.F8;

            QueenBitBoard queenBlack = new QueenBitBoard(ChessPieceColors.Black);

            queenBlack.Bits = BoardSquare.B4;

            KingBitBoard kingBlack = new KingBitBoard(ChessPieceColors.Black);

            kingBlack.Bits = BoardSquare.F7;

            KnightBitBoard knightBlack = new KnightBitBoard(ChessPieceColors.Black);

            knightBlack.Bits = BoardSquare.B8;


            //RookBitBoard badMove = new RookBitBoard( ChessPieceColors.Black );
            //badMove.Bits = BoardSquare.B8;
            lolBoard.Update(pawnWhite);
            lolBoard.Update(knightWhite);
            lolBoard.Update(queenWhite);
            lolBoard.Update(rookWhite);
            lolBoard.Update(bishopWhite);
            lolBoard.Update(kingWhite);
            lolBoard.Update(pawnBlack);
            lolBoard.Update(rookBlack);
            lolBoard.Update(bishopBlack);
            lolBoard.Update(queenBlack);
            lolBoard.Update(kingBlack);
            lolBoard.Update(knightBlack);

            List <ColoredBitBoard> legalMoves = new List <ColoredBitBoard>();

            legalMoves = MoveGen.GenerateLegalMoves(lolBoard, ChessPieceColors.Black);
            ColoredBitBoard bestMove = NegaMax.GetBestMove(lolBoard, 3, ChessPieceColors.Black, MoveGen.GenerateLegalMoves, Eval.EvaluateState);

            Console.Write(legalMoves.ToString() + bestMove.ToString());
        }
Beispiel #10
0
        private static void blackqueensidecastle()
        {
            //Winboard winboard = new Winboard();
            ChessBoard lolBoard = new ChessBoard();

            lolBoard.InitializeGame();

            //White
            PawnBitBoard pawnWhite = new PawnBitBoard(ChessPieceColors.White);

            pawnWhite.Bits = BoardSquare.A2 | BoardSquare.B2 | BoardSquare.C2 | BoardSquare.D2 | BoardSquare.E4 | BoardSquare.H3;

            BishopBitBoard bishopWhite = new BishopBitBoard(ChessPieceColors.White);

            bishopWhite.Bits = BoardSquare.C1;

            KingBitBoard kingWhite = new KingBitBoard(ChessPieceColors.White);

            kingWhite.Bits = BoardSquare.D3;

            RookBitBoard rookWhite = new RookBitBoard(ChessPieceColors.White);

            rookWhite.Bits = BoardSquare.A1 | BoardSquare.H1;

            KnightBitBoard knightWhite = new KnightBitBoard(ChessPieceColors.White);

            knightWhite.Bits = BoardSquare.D2;

            QueenBitBoard queenWhite = new QueenBitBoard(ChessPieceColors.White);

            queenWhite.Bits = BoardSquare.D1;

            //Black
            PawnBitBoard pawnBlack = new PawnBitBoard(ChessPieceColors.Black);

            pawnBlack.Bits = BoardSquare.A7 | BoardSquare.B7 | BoardSquare.C7 | BoardSquare.C6 | BoardSquare.F7 | BoardSquare.G7 | BoardSquare.H7;

            RookBitBoard rookBlack = new RookBitBoard(ChessPieceColors.Black);

            rookBlack.Bits = BoardSquare.A8 | BoardSquare.H8;

            BishopBitBoard bishopBlack = new BishopBitBoard(ChessPieceColors.Black);

            bishopBlack.Bits = BoardSquare.F5 | BoardSquare.H4;

            QueenBitBoard queenBlack = new QueenBitBoard(ChessPieceColors.Black);

            queenBlack.Bits = BoardSquare.F2;

            KingBitBoard kingBlack = new KingBitBoard(ChessPieceColors.Black);

            kingBlack.Bits = BoardSquare.E8;

            KnightBitBoard knightBlack = new KnightBitBoard(ChessPieceColors.Black);

            knightBlack.Bits = BoardSquare.H6;


            //RookBitBoard badMove = new RookBitBoard( ChessPieceColors.Black );
            //badMove.Bits = BoardSquare.B8;
            lolBoard.Update(pawnWhite);
            lolBoard.Update(knightWhite);
            lolBoard.Update(queenWhite);
            lolBoard.Update(rookWhite);
            lolBoard.Update(bishopWhite);
            lolBoard.Update(kingWhite);
            lolBoard.Update(pawnBlack);
            lolBoard.Update(rookBlack);
            lolBoard.Update(bishopBlack);
            lolBoard.Update(queenBlack);
            lolBoard.Update(kingBlack);
            lolBoard.Update(knightBlack);
            KingBitBoard test = new KingBitBoard(ChessPieceColors.Black);

            test.Bits = BoardSquare.C8;
            lolBoard.Update(test);

            List <ColoredBitBoard> legalMoves = new List <ColoredBitBoard>();

            legalMoves = MoveGen.GenerateLegalMoves(lolBoard, ChessPieceColors.Black);
            ColoredBitBoard bestMove = NegaMax.GetBestMove(lolBoard, 3, ChessPieceColors.White, MoveGen.GenerateLegalMoves, Eval.EvaluateState);

            Console.Write(legalMoves.ToString() + bestMove.ToString());
        }
Beispiel #11
0
        /*  private static void WinBoardCastlingFAIL( ChessBoard chessBoard, ChessPieceColors winboardColor ) {
         *  _winboardConverter = new StringBitboardConverter( chessBoard, winboardColor );
         *  ColoredBitBoard bitBoardMoveRecived = _winboardConverter.ConvertStringMoveToBitBoard( "E8G8" );
         *  chessBoard.Update( bitBoardMoveRecived );
         * }*/
        private static void FAILFAILtest()
        {
            ChessBoard lolboard = new ChessBoard();

            lolboard.InitializeGame();

            PawnBitBoard pawnWhite = new PawnBitBoard(ChessPieceColors.White);

            pawnWhite.Bits = BoardSquare.E4 | BoardSquare.B2 | BoardSquare.C2 | BoardSquare.D2 | BoardSquare.H2 | BoardSquare.G2 | BoardSquare.F2 | BoardSquare.A2;
            lolboard.Update(pawnWhite);

            PawnBitBoard pawnBlack = new PawnBitBoard(ChessPieceColors.Black);

            pawnBlack.Bits = BoardSquare.A7 | BoardSquare.B7 | BoardSquare.C7 | BoardSquare.D7 | BoardSquare.E5 | BoardSquare.F7 | BoardSquare.G7 | BoardSquare.H7;
            lolboard.Update(pawnBlack);

            KnightBitBoard lilleKnejtWhite = new KnightBitBoard(ChessPieceColors.White);

            lilleKnejtWhite.Bits = BoardSquare.C3 | BoardSquare.G1;
            lolboard.Update(lilleKnejtWhite);

            KnightBitBoard lilleKnejtBlack = new KnightBitBoard(ChessPieceColors.Black);

            lilleKnejtBlack.Bits = BoardSquare.C6 | BoardSquare.G8;
            lolboard.Update(lilleKnejtBlack);

            KnightBitBoard lilleKnejtWhitenummer2 = new KnightBitBoard(ChessPieceColors.White);

            lilleKnejtWhitenummer2.Bits = BoardSquare.C3 | BoardSquare.F3;
            lolboard.Update(lilleKnejtWhitenummer2);

            PawnBitBoard pawnBlacknummerto = new PawnBitBoard(ChessPieceColors.Black);

            pawnBlacknummerto.Bits = BoardSquare.A7 | BoardSquare.B7 | BoardSquare.C7 | BoardSquare.D5 | BoardSquare.E5 | BoardSquare.F7 | BoardSquare.G7 | BoardSquare.H7;
            lolboard.Update(pawnBlacknummerto);
            //INGEN FEJL!
            PawnBitBoard pawnWhitenummerto = new PawnBitBoard(ChessPieceColors.White);

            pawnWhitenummerto.Bits = BoardSquare.A2 | BoardSquare.B2 | BoardSquare.C2 | BoardSquare.D2 | BoardSquare.D5 | BoardSquare.G2 | BoardSquare.F2 | BoardSquare.H2;
            lolboard.Update(pawnWhitenummerto);
            //Måske fejl?
            KnightBitBoard lilleKnejtBlacknummerto = new KnightBitBoard(ChessPieceColors.Black);

            lilleKnejtBlacknummerto.Bits = BoardSquare.B4 | BoardSquare.G8;
            lolboard.Update(lilleKnejtBlacknummerto);

            KnightBitBoard lilleKnejtWhitenummer3 = new KnightBitBoard(ChessPieceColors.White);

            lilleKnejtWhitenummer3.Bits = BoardSquare.C3 | BoardSquare.E5;
            lolboard.Update(lilleKnejtWhitenummer3);

            KnightBitBoard lilleKnejtBlacknummertre = new KnightBitBoard(ChessPieceColors.Black);

            lilleKnejtBlacknummertre.Bits = BoardSquare.B4 | BoardSquare.F6;
            lolboard.Update(lilleKnejtBlacknummertre);

            BishopBitBoard lillebishopruner = new BishopBitBoard(ChessPieceColors.White);

            lillebishopruner.Bits = BoardSquare.C1 | BoardSquare.B5;
            lolboard.Update(lillebishopruner);



            ColoredBitBoard bestMove = NegaMax.GetBestMove(lolboard, 2, ChessPieceColors.Black, MoveGen.GenerateLegalMoves, Eval.EvaluateState);
        }
Beispiel #12
0
        private static void anotherIllegalMoveFromMovegen()
        {
            //Winboard winboard = new Winboard();
            ChessBoard lolBoard = new ChessBoard();

            lolBoard.InitializeGame();

            //White
            PawnBitBoard pawnWhite = new PawnBitBoard(ChessPieceColors.White);

            pawnWhite.Bits = BoardSquare.A3 | BoardSquare.C3 | BoardSquare.C4 | BoardSquare.F4 | BoardSquare.G4 | BoardSquare.H3;

            BishopBitBoard bishopWhite = new BishopBitBoard(ChessPieceColors.White);

            bishopWhite.Bits = 0;

            KingBitBoard kingWhite = new KingBitBoard(ChessPieceColors.White);

            kingWhite.Bits = BoardSquare.C2;

            RookBitBoard rookWhite = new RookBitBoard(ChessPieceColors.White);

            rookWhite.Bits = BoardSquare.A1 | BoardSquare.E2;

            KnightBitBoard knightWhite = new KnightBitBoard(ChessPieceColors.White);

            knightWhite.Bits = BoardSquare.B1;

            QueenBitBoard queenWhite = new QueenBitBoard(ChessPieceColors.White);

            queenWhite.Bits = 0;

            //Black
            PawnBitBoard pawnBlack = new PawnBitBoard(ChessPieceColors.Black);

            pawnBlack.Bits = BoardSquare.A7 | BoardSquare.B7 | BoardSquare.C6 | BoardSquare.E7 | BoardSquare.F7 | BoardSquare.G7 | BoardSquare.H7;

            RookBitBoard rookBlack = new RookBitBoard(ChessPieceColors.Black);

            rookBlack.Bits = BoardSquare.D8 | BoardSquare.H8;

            BishopBitBoard bishopBlack = new BishopBitBoard(ChessPieceColors.Black);

            bishopBlack.Bits = BoardSquare.F8;

            QueenBitBoard queenBlack = new QueenBitBoard(ChessPieceColors.Black);

            queenBlack.Bits = BoardSquare.D1;

            KingBitBoard kingBlack = new KingBitBoard(ChessPieceColors.Black);

            kingBlack.Bits = BoardSquare.C8;

            KnightBitBoard knightBlack = new KnightBitBoard(ChessPieceColors.Black);

            knightBlack.Bits = 0;


            //RookBitBoard badMove = new RookBitBoard( ChessPieceColors.Black );
            //badMove.Bits = BoardSquare.B8;
            lolBoard.Update(pawnWhite);
            lolBoard.Update(knightWhite);
            lolBoard.Update(queenWhite);
            lolBoard.Update(rookWhite);
            lolBoard.Update(bishopWhite);
            lolBoard.Update(kingWhite);
            lolBoard.Update(pawnBlack);
            lolBoard.Update(rookBlack);
            lolBoard.Update(bishopBlack);
            lolBoard.Update(queenBlack);
            lolBoard.Update(kingBlack);
            lolBoard.Update(knightBlack);


            ColoredBitBoard bestMove = NegaMax.GetBestMove(lolBoard, 3, ChessPieceColors.White, MoveGen.GenerateLegalMoves, Eval.EvaluateState);
        }
Beispiel #13
0
        private static void f3d5failmove()
        {
            //Winboard winboard = new Winboard();
            ChessBoard lolBoard = new ChessBoard();

            lolBoard.InitializeGame();

            //White
            PawnBitBoard pawnWhite = new PawnBitBoard(ChessPieceColors.White);

            pawnWhite.Bits = BoardSquare.A3 | BoardSquare.B3 | BoardSquare.C3 | BoardSquare.D3 | BoardSquare.H4;

            BishopBitBoard bishopWhite = new BishopBitBoard(ChessPieceColors.White);

            bishopWhite.Bits = BoardSquare.C1;

            KingBitBoard kingWhite = new KingBitBoard(ChessPieceColors.White);

            kingWhite.Bits = BoardSquare.F2;

            RookBitBoard rookWhite = new RookBitBoard(ChessPieceColors.White);

            rookWhite.Bits = BoardSquare.A1 | BoardSquare.H1;

            KnightBitBoard knightWhite = new KnightBitBoard(ChessPieceColors.White);

            knightWhite.Bits = BoardSquare.B1 | BoardSquare.G1;

            QueenBitBoard queenWhite = new QueenBitBoard(ChessPieceColors.White);

            queenWhite.Bits = BoardSquare.F3;

            //Black
            PawnBitBoard pawnBlack = new PawnBitBoard(ChessPieceColors.Black);

            pawnBlack.Bits = BoardSquare.A7 | BoardSquare.B7 | BoardSquare.C5 | BoardSquare.D7 | BoardSquare.G7 | BoardSquare.G4 | BoardSquare.H7;

            RookBitBoard rookBlack = new RookBitBoard(ChessPieceColors.Black);

            rookBlack.Bits = BoardSquare.A8 | BoardSquare.F8;

            BishopBitBoard bishopBlack = new BishopBitBoard(ChessPieceColors.Black);

            bishopBlack.Bits = BoardSquare.C8 | BoardSquare.D6;

            QueenBitBoard queenBlack = new QueenBitBoard(ChessPieceColors.Black);

            queenBlack.Bits = BoardSquare.G6;

            KingBitBoard kingBlack = new KingBitBoard(ChessPieceColors.Black);

            kingBlack.Bits = BoardSquare.G8;

            KnightBitBoard knightBlack = new KnightBitBoard(ChessPieceColors.Black);

            knightBlack.Bits = BoardSquare.D5;


            //RookBitBoard badMove = new RookBitBoard( ChessPieceColors.Black );
            //badMove.Bits = BoardSquare.B8;
            lolBoard.Update(pawnWhite);
            lolBoard.Update(knightWhite);
            lolBoard.Update(queenWhite);
            lolBoard.Update(rookWhite);
            lolBoard.Update(bishopWhite);
            lolBoard.Update(kingWhite);
            lolBoard.Update(pawnBlack);
            lolBoard.Update(rookBlack);
            lolBoard.Update(bishopBlack);
            lolBoard.Update(queenBlack);
            lolBoard.Update(kingBlack);
            lolBoard.Update(knightBlack);


            ColoredBitBoard bestMove = NegaMax.GetBestMove(lolBoard, 3, ChessPieceColors.White, MoveGen.GenerateLegalMoves, Eval.EvaluateState);
        }
Beispiel #14
0
        private static void anotherBlackQueenSideCastleFail()
        {
            ChessBoard lolBoard = new ChessBoard();

            lolBoard.InitializeGame();

            //White
            PawnBitBoard pawnWhite = new PawnBitBoard(ChessPieceColors.White);

            pawnWhite.Bits = BoardSquare.A2 | BoardSquare.C3 | BoardSquare.E3 | BoardSquare.H3;

            BishopBitBoard bishopWhite = new BishopBitBoard(ChessPieceColors.White);

            bishopWhite.Bits = 0;

            RookBitBoard rookWhite = new RookBitBoard(ChessPieceColors.White);

            rookWhite.Bits = BoardSquare.A1;

            KnightBitBoard knightWhite = new KnightBitBoard(ChessPieceColors.White);

            knightWhite.Bits = BoardSquare.B1;

            QueenBitBoard queenWhite = new QueenBitBoard(ChessPieceColors.White);

            queenWhite.Bits = BoardSquare.E2;

            KingBitBoard kingWhite = new KingBitBoard(ChessPieceColors.White);

            kingWhite.Bits = BoardSquare.D2;

            //black
            PawnBitBoard pawnBlack = new PawnBitBoard(ChessPieceColors.Black);

            pawnBlack.Bits = BoardSquare.A7 | BoardSquare.B7 | BoardSquare.C5 | BoardSquare.F7 | BoardSquare.G7 | BoardSquare.H5;

            BishopBitBoard bishopBlack = new BishopBitBoard(ChessPieceColors.Black);

            bishopBlack.Bits = BoardSquare.E4 | BoardSquare.F8;

            RookBitBoard rookBlack = new RookBitBoard(ChessPieceColors.Black);

            rookBlack.Bits = BoardSquare.A8 | BoardSquare.H8;

            KnightBitBoard knightBlack = new KnightBitBoard(ChessPieceColors.Black);

            knightBlack.Bits = BoardSquare.F4;

            QueenBitBoard queenBlack = new QueenBitBoard(ChessPieceColors.Black);

            queenBlack.Bits = BoardSquare.H3;

            KingBitBoard kingBlack = new KingBitBoard(ChessPieceColors.Black);

            kingBlack.Bits = BoardSquare.C8;

            //Update

            lolBoard.Update(pawnWhite);
            lolBoard.Update(knightWhite);
            lolBoard.Update(queenWhite);
            lolBoard.Update(rookWhite);
            lolBoard.Update(bishopWhite);
            lolBoard.Update(kingWhite);
            lolBoard.Update(pawnBlack);
            lolBoard.Update(rookBlack);
            lolBoard.Update(bishopBlack);
            lolBoard.Update(queenBlack);
            lolBoard.Update(kingBlack);
            lolBoard.Update(knightBlack);

            ColoredBitBoard bestMove = NegaMax.GetBestMove(lolBoard, 3, ChessPieceColors.White, MoveGen.GenerateLegalMoves, Eval.EvaluateState);
        }
Beispiel #15
0
        private static void KingSideCastlingFAIL()
        {
            ChessBoard lolBoard = new ChessBoard();

            lolBoard.InitializeGame();

            //White
            PawnBitBoard pawnWhite = new PawnBitBoard(ChessPieceColors.White);

            pawnWhite.Bits = BoardSquare.A4 | BoardSquare.B4 | BoardSquare.C2 | BoardSquare.F4 | BoardSquare.H5;

            BishopBitBoard bishopWhite = new BishopBitBoard(ChessPieceColors.White);

            bishopWhite.Bits = BoardSquare.E3;

            RookBitBoard rookWhite = new RookBitBoard(ChessPieceColors.White);

            rookWhite.Bits = BoardSquare.C1 | BoardSquare.H1;

            KnightBitBoard knightWhite = new KnightBitBoard(ChessPieceColors.White);

            knightWhite.Bits = BoardSquare.G1;

            QueenBitBoard queenWhite = new QueenBitBoard(ChessPieceColors.White);

            queenWhite.Bits = 0;

            KingBitBoard kingWhite = new KingBitBoard(ChessPieceColors.White);

            kingWhite.Bits = BoardSquare.F2;

            //black
            PawnBitBoard pawnBlack = new PawnBitBoard(ChessPieceColors.Black);

            pawnBlack.Bits = BoardSquare.A7 | BoardSquare.B7 | BoardSquare.E7 | BoardSquare.E4 | BoardSquare.G4 | BoardSquare.G5 | BoardSquare.H7;

            BishopBitBoard bishopBlack = new BishopBitBoard(ChessPieceColors.Black);

            bishopBlack.Bits = BoardSquare.C3 | BoardSquare.C4;

            RookBitBoard rookBlack = new RookBitBoard(ChessPieceColors.Black);

            rookBlack.Bits = BoardSquare.A8 | BoardSquare.H8;

            KnightBitBoard knightBlack = new KnightBitBoard(ChessPieceColors.Black);

            knightBlack.Bits = BoardSquare.D4;

            QueenBitBoard queenBlack = new QueenBitBoard(ChessPieceColors.Black);

            queenBlack.Bits = 0;

            KingBitBoard kingBlack = new KingBitBoard(ChessPieceColors.Black);

            kingBlack.Bits = BoardSquare.G8;

            //Update

            lolBoard.Update(pawnWhite);
            lolBoard.Update(knightWhite);
            lolBoard.Update(queenWhite);
            lolBoard.Update(rookWhite);
            lolBoard.Update(bishopWhite);
            lolBoard.Update(kingWhite);
            lolBoard.Update(pawnBlack);
            lolBoard.Update(bishopBlack);
            lolBoard.Update(queenBlack);
            lolBoard.Update(knightBlack);
            lolBoard.Update(kingBlack);

            List <ColoredBitBoard> legalMoves = new List <ColoredBitBoard>();

            legalMoves = MoveGen.GenerateLegalMoves(lolBoard, ChessPieceColors.White);
            ColoredBitBoard bestMove = NegaMax.GetBestMove(lolBoard, 3, ChessPieceColors.White, MoveGen.GenerateLegalMoves, Eval.EvaluateState);
        }
Beispiel #16
0
        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}");
                }
            }
        }