Beispiel #1
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();
        }