Exemple #1
0
        static void PrintBoardAfterMove(IPlayerMove move, string playerName, SimpleBoard board)
        {
            var piece = board.Get(move.Move.StartPosition.ToTuple());

            if (move.Move.PromotionResult != PromotionPieceType.NoPromotion)
            {
                if (piece.Contains("w"))
                {
                    piece = "wQ ";
                }
                else
                {
                    piece = "bQ ";
                }
            }

            // Clear previous move
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    if (board.Get((i, j)) == SimpleBoard.PreviousTileValue)
                    {
                        board.Set((i, j), "   ");
                        break;
                    }
                }
            }

            board.Set(move.Move.StartPosition.ToTuple(), SimpleBoard.PreviousTileValue);
            board.Set(move.Move.EndPosition.ToTuple(), piece);

            board.Print();
        }
Exemple #2
0
        static void StartLocalGame(int minDelayInMs, int?overrideOpponentMaxDepth, Board overrideBoard = null)
        {
            Log(Environment.NewLine);
            // TODO async
            var moveHistory = new List <IPlayerMove>();
            var info1       = new StartInformationImplementation()
            {
                WhitePlayer = true
            };

            var player1 = new Logic(info1, false, null, overrideBoard);
            var board   = new SimpleBoard(player1.Board);

            var firstMove = player1.CreateMove();

            moveHistory.Add(firstMove);
            PrintMove(firstMove, "white");
            PrintBoardAfterMove(firstMove, "", board);

            var info2 = new StartInformationImplementation()
            {
                WhitePlayer = false, OpponentMove = firstMove.Move
            };
            var player2 = new Logic(info2, false, overrideOpponentMaxDepth, overrideBoard);

            try
            {
                while (true)
                {
                    var move = player2.CreateMove();
                    moveHistory.Add(move);
                    PrintMove(move, "black");
                    PrintBoardAfterMove(move, "", board);
                    if (move.Move.CheckMate)
                    {
                        Log("Checkmate");
                        break;
                    }
                    if (MoveHistory.IsDraw(moveHistory))
                    {
                        Log("Draw");
                        break;
                    }
                    player1.ReceiveMove(move.Move);
                    Thread.Sleep(minDelayInMs);

                    move = player1.CreateMove();
                    moveHistory.Add(move);
                    PrintMove(move, "white");
                    PrintBoardAfterMove(move, "", board);
                    if (move.Move.CheckMate)
                    {
                        Log("Checkmate");
                        break;
                    }
                    if (MoveHistory.IsDraw(moveHistory))
                    {
                        Log("Draw");
                        break;
                    }
                    player2.ReceiveMove(move.Move);
                    Thread.Sleep(minDelayInMs);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.Read();
        }