public override void TestAI(SearchContext <object, TicTacToeState, TicTacToeMove, object, TicTacToeMove> context) { // Test if the technique can find the winning move. var source = new TicTacToeState("X-O-XO---"); context.Reset(); context.Source = source.Copy(); var result = PlayGame(context); Assert.IsTrue(result.PlayerWon == 0); // Test if the technique can avoid a loss. source = new TicTacToeState("--X-OX---"); source.EndTurn(); context.Reset(); context.Source = source.Copy(); result = PlayGame(context); Assert.IsTrue(result.PlayerWon == -1); // On an empty board the game should be a draw. // (first player should play corner/middle position and second player should force the draw by playing the other) source = new TicTacToeState(); context.Reset(); context.Source = source.Copy(); result = PlayGame(context); Assert.IsTrue(result.PlayerWon == -1); // If the first player plays the middle position, the game is a draw. // (second player should play a corner position) source = new TicTacToeState("----X----"); source.EndTurn(); context.Reset(); context.Source = source.Copy(); result = PlayGame(context); Assert.IsTrue(result.PlayerWon == -1); // If the first player plays an edge position, the game is a draw. // (second player should play the middle position) source = new TicTacToeState("---X-----"); source.EndTurn(); context.Reset(); context.Source = source.Copy(); result = PlayGame(context); Assert.IsTrue(result.PlayerWon == -1); }
public TicTacToeMove Sample(TicTacToeState state, OddmentTable <int> sideInformation) { // Get all available positions in this state var emptyPositions = TicTacToeMoveGenerator.AllEmptyPositions(state); var positionSelected = false; var selectedPosition = -1; while (!positionSelected) { // Sample a position from the OddmentTable selectedPosition = sideInformation.Next(); // Check if this position can be played, otherwise generate a new one positionSelected = emptyPositions.Contains(selectedPosition); } return(new TicTacToeMove(selectedPosition, state.ActivePlayerID)); }
public static List <int> AllEmptyPositions(TicTacToeState state) { var positions = new List <int>(); var board = state.State.ToCharArray(); var index = 0; while (index < board.Length) { if (board[index] == TicTacToeState.OPEN_SPACE) { positions.Add(index); } index++; } return(positions); }
public TicTacToeMove Sample(TicTacToeState state) { return(null); }
public bool Equals(TicTacToeState otherState) { return(HashMethod() == otherState.HashMethod()); }
public TicTacToeMoveGenerator(TicTacToeState state) { // Initialise the position to the first open position on the board. Board = state.State; PlayerID = state.ActivePlayerID; }