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." ); }
public Game(GameBoard board, Player currentPlayer) { this.RecursionDepth = 7; this.Board = board; board.Game = this; TerminalPositionsTable.Init(); this.PlayerCombinations = new PlayerCombinations(board); }
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; } }
//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; }
public Game(Player player) : this(new GameBoard(), player) { }
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(); }
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++; }
public void setOpponent(Player player) { opponent = player; }