예제 #1
0
        public void BlockTestHorizontal()
        {
            var state = new Player[7, 6];

              for (int i = 0; i < 7; i++)
              {
            for (int j = 0; j < 6; j++)
            {
              state[i, j] = Player.None;
            }
              }

              for (int i = 0; i < 3; i++)
              {
            state[i, Constants.Rows - 1] = Player.Human;
              }

              var board = new GameBoard(state);

              var game = new Game(board, Player.Human)
              {
            MoveGenerator = new LeftToRightMoveOrdering(),
            SearchStrategy = new AlphaBeta(),
            Input = new MockGameInput()
              };

              game.Start();

              Assert.IsTrue
              (
            game.Board[3, Constants.Rows - 1] == Player.AI,
            "AI had er voor moeten kiezen om de speler te blokkeren."
              );
        }
예제 #2
0
파일: Game.cs 프로젝트: JulianR/ConnectFour
 public Game(GameBoard board, Player currentPlayer)
 {
     this.RecursionDepth = 7;
       this.Board = board;
       board.Game = this;
       TerminalPositionsTable.Init();
       this.PlayerCombinations = new PlayerCombinations(board);
 }
예제 #3
0
        public GameState(State s, Board b, Player p, GameState parent, Cell c, Boolean mp)
        {
            maxPlayer = mp;
            state = s;
            cell = c;
            board = b;
            player = p;
            this.parent = parent;
            children = new List<GameState>();
            Region.findConnectedCells(b);
            b.UpdateCellObservers();

            if(MiniMaxTree.TerminalTest(cell) && state != GameState.State.initial)
            {
                state = GameState.State.terminal;

                if (maxPlayer)
                {
                    heuristicValue = MiniMaxTree.MIN_VALUE;
                }
                else
                    heuristicValue = MiniMaxTree.MAX_VALUE;
            }
        }
예제 #4
0
        //Get the cells on the board that belong to the player
        public List<Cell> getPlayerCells(Player player)
        {
            List<Cell> cells = new List<Cell>();

            for(int i = length - 1; i >= 0; i--)
            {
                for (int j = 0; j < width - 1; j++)
                {
                    if((int)board[i, j].getState() == player.getColor())
                    {
                        cells.Add(board[i, j]);
                    }
                }
            }
            return cells;
        }
예제 #5
0
파일: Game.cs 프로젝트: JulianR/ConnectFour
 public Game(Player player)
     : this(new GameBoard(), player)
 {
 }
예제 #6
0
파일: Game.cs 프로젝트: JulianR/ConnectFour
        private void TakeTurn(Player player)
        {
            if (!this.gameIsOver)
              {
            if (CurrentPlayer == Player.Human && !IsComputerVsComputer)
            {
              InputCommand command;

              do
              {
            command = Input.GetInput();
            switch (command)
            {
              case InputCommand.MoveLeft:
                SelectedColumnIndex = Math.Max(0, --SelectedColumnIndex);
                Invalidate();
                break;
              case InputCommand.MoveRight:
                SelectedColumnIndex = Math.Min(Constants.Columns - 1, ++SelectedColumnIndex);
                Invalidate();
                break;
              case InputCommand.Drop:
                Drop(this.SelectedColumnIndex);
                break;
              case InputCommand.Invalid:
                this.gameIsOver = true;
                return;
            }
              }
              while (command != InputCommand.Drop);

              SwitchTurns();
            }
            else if (CurrentPlayer == Player.Human)
            {
              MakeDecision(Player.Human);
              Thread.Sleep(500);
              SwitchTurns();
            }
            else
            {
              MakeDecision(Player.AI);
              if (IsComputerVsComputer)
              {
            Thread.Sleep(500);
              }
              SwitchTurns();
            }
              }
              Console.ReadLine();
        }
예제 #7
0
파일: Game.cs 프로젝트: JulianR/ConnectFour
        private void MakeDecision(Player maxPlayer)
        {
            Stopwatch sw = Stopwatch.StartNew();
              var column = this.SearchStrategy.FindBestColumnIndex(this, maxPlayer);
              sw.Stop();
              TimeTaken = sw.Elapsed;
              totalTimeTaken += sw.Elapsed;
              this.LastBestColumn = column;

              Drop(column);
              this.moveCount++;
        }
예제 #8
0
 public void setOpponent(Player player)
 {
     opponent = player;
 }