public int GetMove(IPlayerBoardAdapter playerBoardAdapter) { int move; do { Console.Write("Enter your move (0-8): "); ConsoleKeyInfo cki = Console.ReadKey(false); Console.WriteLine(); if (Char.IsDigit(cki.KeyChar)) { move = int.Parse(cki.KeyChar.ToString(CultureInfo.InvariantCulture)); if (move <0 || move>8) { continue; } if (playerBoardAdapter.GetField(move) == 0) { break; } } Console.WriteLine("Move is incorrect!"); } while (true); return move; }
public Game([Named("playerOne")] IPlayerAgent playerOne, [Named("playerTwo")] IPlayerAgent playerTwo) { _playerOne = playerOne; _playerTwo = playerTwo; _gameBoard = new GameBoard(); _playerOneAdapter = new PlayerBoardAdapter(_gameBoard, BoardField.One); _playerTwoAdapter = new PlayerBoardAdapter(_gameBoard, BoardField.Two); }
public int GetMove(IPlayerBoardAdapter playerBoardAdapter) { var emptySpots = new List<int>(); for (int i = 0; i < 9; i++) { if (playerBoardAdapter.GetField(i) == 0) { emptySpots.Add(i); } } return emptySpots[random.Next(0, emptySpots.Count)]; }