<commit_before>#ifndef __COMPUTERPLAYER
#define __COMPUTERPLAYER

#include "player.h"

class ComputerPlayer : public Player
{
public:

  GameState getMove(const GameState & gameState)
  {
    GameState gameStateAfterMove = gameState;
    GameState theoreticalGameState;

    // If we can win, take win
    
    for (unsigned i = 0; i < BOARD_SIZE; i++)
    {
      for (unsigned j = 0; j < BOARD_SIZE; j++)
      {
        theoreticalGameState.board = gameState.board;
        if (theoreticalGameState.board.get(i, j) == BoardValue::Empty)
        {
          theoreticalGameState.board.set(i, j, this->getBoardValue());
          if (thisPlayerHasWon(theoreticalGameState))
          {
            gameStateAfterMove.board.set(i, j, this->getBoardValue());
            return gameStateAfterMove;
          }
        }

      }
    }

    // If they can win, prevent win
    
    for (unsigned i = 0; i < BOARD_SIZE; i++)
    {
      for (unsigned j = 0; j < BOARD_SIZE; j++)
      {
        theoreticalGameState.board = gameState.board;
        if (theoreticalGameState.board.get(i, j) == BoardValue::Empty)
        {
          theoreticalGameState.board.set(i, j, this->getOpponentBoardValue());
          if (otherPlayerHasWon(theoreticalGameState))
          {
            gameStateAfterMove.board.set(i, j, this->getBoardValue());
            return gameStateAfterMove;
          }
        }
      }
    }

    // If middle available, take middle
    
    if (gameStateAfterMove.board.get(1, 1) == BoardValue::Empty)
    {
      gameStateAfterMove.board.set(1, 1, this->getBoardValue());
      return gameStateAfterMove;
    }

    // Offensive Strategy
    
    if (gameStateAfterMove.board.get(1, 1) == this->getBoardValue() && gameState.board.numberOfAvailableMoves() == 7)
    {
      if (gameStateAfterMove.board.get(0, 1) == this->getOpponentBoardValue())
      {
        gameStateAfterMove.board.set(2, 2, this->getBoardValue());
        return gameStateAfterMove;
      }
      else if (gameStateAfterMove.board.get(1, 2) == this->getOpponentBoardValue())
      {
        gameStateAfterMove.board.set(2, 0, this->getBoardValue());
        return gameStateAfterMove;
      }
      else if (gameStateAfterMove.board.get(2, 1) == this->getOpponentBoardValue())
      {
        gameStateAfterMove.board.set(0, 0, this->getBoardValue());
        return gameStateAfterMove;
      }
      else if (gameStateAfterMove.board.get(1, 0) == this->getOpponentBoardValue())
      {
        gameStateAfterMove.board.set(2, 2, this->getBoardValue());
        return gameStateAfterMove;
      }
    }

    // Defensive Strategy
    
    if (gameStateAfterMove.board.get(1, 0) == this->getOpponentBoardValue() && gameStateAfterMove.board.get(2, 1) == this->getOpponentBoardValue() && gameStateAfterMove.board.get(2, 0) == BoardValue::Empty)
    {
      gameStateAfterMove.board.set(2, 0, this->getBoardValue());
      return gameStateAfterMove;
    }
    else if (gameStateAfterMove.board.get(1, 0) == this->getOpponentBoardValue() && gameStateAfterMove.board.get(0, 1) == this->getOpponentBoardValue() && gameStateAfterMove.board.get(0, 0) == BoardValue::Empty)
    {
      gameStateAfterMove.board.set(0, 0, this->getBoardValue());
      return gameStateAfterMove;
    }
    else if (gameStateAfterMove.board.get(0, 1) == this->getOpponentBoardValue() && gameStateAfterMove.board.get(1, 2) == this->getOpponentBoardValue() && gameStateAfterMove.board.get(0, 2) == BoardValue::Empty)
    {
      gameStateAfterMove.board.set(0, 2, this->getBoardValue());
      return gameStateAfterMove;
    }
    else if (gameStateAfterMove.board.get(2, 1) == this->getOpponentBoardValue() && gameStateAfterMove.board.get(1, 2) == this->getOpponentBoardValue() && gameStateAfterMove.board.get(2, 2) == BoardValue::Empty)
    {
      gameStateAfterMove.board.set(2, 2, this->getBoardValue());
      return gameStateAfterMove;
    }

    // If corner available, take corner
    
    if (gameStateAfterMove.board.get(0, 0) == BoardValue::Empty)
    {
      gameStateAfterMove.board.set(0, 0, this->getBoardValue());
      return gameStateAfterMove;
    }
    else if (gameStateAfterMove.board.get(0, 2) == BoardValue::Empty)
    {
      gameStateAfterMove.board.set(0, 2, this->getBoardValue());
      return gameStateAfterMove;
    }
    else if (gameStateAfterMove.board.get(2, 0) == BoardValue::Empty)
    {
      gameStateAfterMove.board.set(2, 0, this->getBoardValue());
      return gameStateAfterMove;
    }
    else if (gameStateAfterMove.board.get(2, 2) == BoardValue::Empty)
    {
      gameStateAfterMove.board.set(2, 2, this->getBoardValue());
      return gameStateAfterMove;
    }

    // Default to random move
    
    return TicTacToe::makeRandomMove(gameState, this->getBoardValue());
  }
  
private:

  bool thisPlayerHasWon(const GameState & gameState)
  {
    if (this->getBoardValue() == BoardValue::PlayerOne) return TicTacToe::playerOneHasWon(gameState);
    else return TicTacToe::playerTwoHasWon(gameState);
  }

  bool otherPlayerHasWon(const GameState & gameState)
  {
    if (this->getOpponentBoardValue() == BoardValue::PlayerOne) return TicTacToe::playerOneHasWon(gameState);
    else return TicTacToe::playerTwoHasWon(gameState);
  }
};

#endif<commit_msg>Added game state class (part 2)<commit_after>#ifndef __COMPUTERPLAYER
#define __COMPUTERPLAYER

#include "player.h"

class ComputerPlayer : public Player
{
public:

  GameState getMove(const GameState & gameState)
  {
    GameState move = gameState;
    GameState theoreticalGameState;

    // If we can win, take win
    
    for (unsigned i = 0; i < BOARD_SIZE; i++)
    {
      for (unsigned j = 0; j < BOARD_SIZE; j++)
      {
        theoreticalGameState.board = gameState.board;
        if (theoreticalGameState.board.get(i, j) == BoardValue::Empty)
        {
          theoreticalGameState.board.set(i, j, this->getBoardValue());
          if (thisPlayerHasWon(theoreticalGameState))
          {
            move.board.set(i, j, this->getBoardValue());
            return move;
          }
        }

      }
    }

    // If they can win, prevent win
    
    for (unsigned i = 0; i < BOARD_SIZE; i++)
    {
      for (unsigned j = 0; j < BOARD_SIZE; j++)
      {
        theoreticalGameState.board = gameState.board;
        if (theoreticalGameState.board.get(i, j) == BoardValue::Empty)
        {
          theoreticalGameState.board.set(i, j, this->getOpponentBoardValue());
          if (otherPlayerHasWon(theoreticalGameState))
          {
            move.board.set(i, j, this->getBoardValue());
            return move;
          }
        }
      }
    }

    // If middle available, take middle
    
    if (move.board.get(1, 1) == BoardValue::Empty)
    {
      move.board.set(1, 1, this->getBoardValue());
      return move;
    }

    // Offensive Strategy
    
    if (move.board.get(1, 1) == this->getBoardValue() && gameState.board.numberOfAvailableMoves() == 7)
    {
      if (move.board.get(0, 1) == this->getOpponentBoardValue())
      {
        move.board.set(2, 2, this->getBoardValue());
        return move;
      }
      else if (move.board.get(1, 2) == this->getOpponentBoardValue())
      {
        move.board.set(2, 0, this->getBoardValue());
        return move;
      }
      else if (move.board.get(2, 1) == this->getOpponentBoardValue())
      {
        move.board.set(0, 0, this->getBoardValue());
        return move;
      }
      else if (move.board.get(1, 0) == this->getOpponentBoardValue())
      {
        move.board.set(2, 2, this->getBoardValue());
        return move;
      }
    }

    // Defensive Strategy
    
    if (move.board.get(1, 0) == this->getOpponentBoardValue() && move.board.get(2, 1) == this->getOpponentBoardValue() && move.board.get(2, 0) == BoardValue::Empty)
    {
      move.board.set(2, 0, this->getBoardValue());
      return move;
    }
    else if (move.board.get(1, 0) == this->getOpponentBoardValue() && move.board.get(0, 1) == this->getOpponentBoardValue() && move.board.get(0, 0) == BoardValue::Empty)
    {
      move.board.set(0, 0, this->getBoardValue());
      return move;
    }
    else if (move.board.get(0, 1) == this->getOpponentBoardValue() && move.board.get(1, 2) == this->getOpponentBoardValue() && move.board.get(0, 2) == BoardValue::Empty)
    {
      move.board.set(0, 2, this->getBoardValue());
      return move;
    }
    else if (move.board.get(2, 1) == this->getOpponentBoardValue() && move.board.get(1, 2) == this->getOpponentBoardValue() && move.board.get(2, 2) == BoardValue::Empty)
    {
      move.board.set(2, 2, this->getBoardValue());
      return move;
    }

    // If corner available, take corner
    
    if (move.board.get(0, 0) == BoardValue::Empty)
    {
      move.board.set(0, 0, this->getBoardValue());
      return move;
    }
    else if (move.board.get(0, 2) == BoardValue::Empty)
    {
      move.board.set(0, 2, this->getBoardValue());
      return move;
    }
    else if (move.board.get(2, 0) == BoardValue::Empty)
    {
      move.board.set(2, 0, this->getBoardValue());
      return move;
    }
    else if (move.board.get(2, 2) == BoardValue::Empty)
    {
      move.board.set(2, 2, this->getBoardValue());
      return move;
    }

    // Default to random move
    
    return TicTacToe::makeRandomMove(gameState, this->getBoardValue());
  }
  
private:

  bool thisPlayerHasWon(const GameState & gameState)
  {
    if (this->getBoardValue() == BoardValue::PlayerOne) return TicTacToe::playerOneHasWon(gameState);
    else return TicTacToe::playerTwoHasWon(gameState);
  }

  bool otherPlayerHasWon(const GameState & gameState)
  {
    if (this->getOpponentBoardValue() == BoardValue::PlayerOne) return TicTacToe::playerOneHasWon(gameState);
    else return TicTacToe::playerTwoHasWon(gameState);
  }
};

#endif
{'fraction_non_alphanumeric': 0.141721044045677, 'fraction_numerical': 0.015395595432300162, 'mean_word_length': 2.816731517509728, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3669543', 'n_tokens_mistral': 3364, 'n_tokens_neox': 3199, 'n_words': 594}