public void ConvertStringMoveToBitBoard_IsNullReturned_Equal()
        {
            ChessBoard chessBoard               = new ChessBoard();
            StringBitboardConverter converter   = new StringBitboardConverter(chessBoard, ChessPieceColors.White);
            string          stringMove          = "e4e5";
            ColoredBitBoard correctMoveBitBoard = converter.ConvertStringMoveToBitBoard(stringMove);

            Assert.Equal(null, correctMoveBitBoard);
        }
        public void ConvertStringMoveToBitBoard_IsCorrectBitBoardReturned_Equals()
        {
            ChessBoard chessBoard = new ChessBoard();

            chessBoard.BlackKnight.Bits = BoardSquare.B8 | BoardSquare.G8;
            string stringMove = "b8c6";

            StringBitboardConverter converter = new StringBitboardConverter(chessBoard, ChessPieceColors.Black);

            ColoredBitBoard currentMoveBitBoard = converter.ConvertStringMoveToBitBoard(stringMove);

            ColoredBitBoard correctMoveBitBoard = new KnightBitBoard(ChessPieceColors.Black);

            correctMoveBitBoard.Bits = BoardSquare.C6 | BoardSquare.G8;

            Assert.Equal(currentMoveBitBoard.GetType(), correctMoveBitBoard.GetType());
            Assert.Equal(currentMoveBitBoard.Bits, correctMoveBitBoard.Bits);
        }
        public void ConvertStringMoveToBitBoard_IsCorrectPromotionKnigtBitBoardReturned_Equal()
        {
            ChessBoard chessBoard = new ChessBoard();

            chessBoard.WhitePawn.Bits = BoardSquare.A2 | BoardSquare.B2 | BoardSquare.C2 | BoardSquare.D2 | BoardSquare.E7 | BoardSquare.F2 | BoardSquare.G2 | BoardSquare.H2;
            string stringMove = "e7e8n";

            StringBitboardConverter converter = new StringBitboardConverter(chessBoard, ChessPieceColors.White);

            PawnBitBoard currentMoveBitBoard = (PawnBitBoard)converter.ConvertStringMoveToBitBoard(stringMove);

            PawnBitBoard correctMoveBitBoard = new PawnBitBoard(ChessPieceColors.White);

            correctMoveBitBoard.Bits = BoardSquare.A2 | BoardSquare.B2 | BoardSquare.C2 | BoardSquare.D2 | BoardSquare.E8 | BoardSquare.F2 | BoardSquare.G2 | BoardSquare.H2;
            correctMoveBitBoard.Promote(PawnBitBoard.PromotionPiece.Knight);

            Assert.Equal(correctMoveBitBoard.GetType(), currentMoveBitBoard.GetType());
            Assert.Equal(correctMoveBitBoard.Bits, currentMoveBitBoard.Bits);
            Assert.Equal(correctMoveBitBoard.Promotion, currentMoveBitBoard.Promotion);
        }
Ejemplo n.º 4
0
        public void Handler(string inputString)
        {
            Trace.WriteLine("Handler() input: " + inputString);
            string[] input = inputString.Split(' ');
            switch (input[0])
            {
            case "protover":
                protover = Convert.ToInt32(input[1]);
                if (protover == 2)
                {
                    Console.WriteLine("feature colors=0 done=1");
                }
                break;

            case "new":
                chessBoard.InitializeGame();
                Bayes.HandleEvalConfig(out depth, Path.GetFullPath("config.txt"));
                if (Bayes.TuneEvalValues)
                {
                    Bayes.ModifyValues(Bayes.RandomizeEvalConfiguration(Bayes.CreateOutputString(chessBoard)), chessBoard);
                }
                else
                {
                    Bayes.ModifyValues(Bayes.FindBestEvalConfiguration(Path.GetFullPath("log.txt")), chessBoard);
                }
                isFirstGo = true;
                break;

            case "level":
                movesPerMinutes = Convert.ToInt32(input[1]);
                minutes         = Convert.ToInt32(input[2]);
                break;

            case "accepted":
                switch (input[1])
                {
                case "colors":
                    isAcceptedColors = true;
                    break;

                case "time":
                    isAcceptedTime = true;
                    break;
                }
                break;

            case "quit":
                System.Environment.Exit(0);
                break;

            case "force":
                force = true;
                break;

            case "rejected":
                throw new Exception("Feature '" + input[1] + "' was not accepted.");

            case "result":

                if (Bayes.TuneEvalValues)
                {
                    Bayes.RepetetionPerEvalConfiguration--;
                    if (Bayes.RepetetionPerEvalConfiguration == 0)
                    {
                        Bayes.Seed++;
                        Bayes.RepetetionPerEvalConfiguration = 10;
                    }
                }

                Bayes.WriteToEvalConfig(Path.GetFullPath("config.txt"), depth);

                switch (input[1])
                {
                case "1-0":
                    chessBoard.State = ChessBoardGameState.WhiteMate;
                    Bayes.WriteLineToTxtFile(Path.GetFullPath("log.txt"), Bayes.CreateEvalConfigurationStringLogFormat(true, Bayes.CreateOutputString(chessBoard)));
                    break;

                case "0-1":
                    chessBoard.State = ChessBoardGameState.BlackMate;
                    Bayes.WriteLineToTxtFile(Path.GetFullPath("log.txt"), Bayes.CreateEvalConfigurationStringLogFormat(false, Bayes.CreateOutputString(chessBoard)));
                    break;

                case "1/2-1/2":
                    chessBoard.State = ChessBoardGameState.Draw;
                    Bayes.WriteLineToTxtFile(Path.GetFullPath("log.txt"), Bayes.CreateEvalConfigurationStringLogFormat(false, Bayes.CreateOutputString(chessBoard)));
                    break;

                case "*":
                    Console.WriteLine("Error (unknown command): " + input[0]);
                    break;
                }
                break;

            case "go":
                if (isFirstGo == true)
                {
                    force = false;
                    DoMove();
                    isFirstGo = false;
                }
                else
                {
                    Console.WriteLine("Error (Not handled): go");
                }
                break;

            default:
                if (STRINGMOVE_FORMAT.IsMatch(input[0]))
                {
                    Logger.OutputMove(input[0]);
                    ColoredBitBoard bitBoardMoveRecived = _winboardConverter.ConvertStringMoveToBitBoard(input[0]);
                    chessBoard.Update(bitBoardMoveRecived);
                    whiteTurn = !whiteTurn;
                    if (force == false)
                    {
                        DoMove();
                    }
                }
                else
                {
                    Console.WriteLine("Error (unknown command): " + input[0]);
                }
                break;
            }
        }