示例#1
0
        private void StartGame(bool isFirstPlayerHuman, bool isSecondPlayerHuman)
        {
            Board = new MillBoard();

            if (isFirstPlayerHuman)
            {
                FirstPlayer = new HumanPlayer(true);
            }
            else
            {
                FirstPlayer = new MinimaxAI(true, 5);
            }

            if (isSecondPlayerHuman)
            {
                SecondPlayer = new HumanPlayer(false);
            }
            else
            {
                SecondPlayer = new MinimaxAlphaBetaAI(false, 5);
                //SecondPlayer = new MinimaxAI(false, 5);
            }

            FirstPlayer.Enemy  = SecondPlayer;
            SecondPlayer.Enemy = FirstPlayer;

            CurrentPlayer = FirstPlayer;

            while (!IsGameOver(CurrentPlayer))
            {
                Board.Print();
                Console.WriteLine("It's " + (CurrentPlayer.IsWhite ? "WHITE's" : "BLACK's") + " turn!");
                Console.WriteLine(GetNameOfStage(CurrentPlayer.State));
                Console.WriteLine("Pawns in hands: " + CurrentPlayer.PawnsInHandNum);
                Console.WriteLine("Pawns on board: " + CurrentPlayer.PawnsOnBoardNum);
                Console.WriteLine("Enemy's pawns in hands: " + CurrentPlayer.Enemy.PawnsInHandNum);
                Console.WriteLine("Enemy's pawns on board: " + CurrentPlayer.Enemy.PawnsOnBoardNum);
                CurrentPlayer.Move();

                CurrentPlayer = CurrentPlayer == FirstPlayer ? SecondPlayer : FirstPlayer;
            }

            Board.Print();
            if (!IsDraw())
            {
                Console.WriteLine("Game over! Winner: " + (CurrentPlayer.Enemy.IsWhite ? "WHITE!" : "BLACK!"));
            }
            else
            {
                Console.WriteLine("Draw!");
            }
        }
示例#2
0
 protected void PrintWithSkip(string message)
 {
     if (!skip && !skip50)
     {
         MillBoard.Print();
         Console.WriteLine(message);
         string command = Console.ReadLine();
         if (command == "s")
         {
             skip = true;
         }
         else if (command == "d")
         {
             skip50      = true;
             skipCounter = 0;
         }
     }
     else if (skip50)
     {
         skipCounter++;
         if (skipCounter > SKIP_NUM)
         {
             skip50 = false;
         }
     }
 }
示例#3
0
        private void OnePositionMove(string command, bool printBoard, Func <int, bool> IsMoveValidCondition, Action <int> OnValid)
        {
            if (printBoard)
            {
                MillBoard.Print();
            }

            while (AS_LONG_AS_PLAYER_MAKES_INVALID_MOVES)
            {
                Console.Write(command);
                int pos = int.Parse(Console.ReadLine());
                if (IsMoveValidCondition(pos))
                {
                    OnValid(pos);
                    return;
                }
                else
                {
                    OutputAboutWrongMove();
                }
            }
        }