tictactoe_solver.cpp
// This function makes a choice for placing a token on the board using the idea
// of the minimax algorithm. It generates moves up the specified move depth or
// until the game has been completed. After generating moves the minimax
// algorithm will make a choice on where is the best place to place a token
// 
// If a game score is positive that means that 'X' is winning, if the game
// score is negative then 'O' is winning, and if the score is zero then it is
// currently a tie.
//
// Alpha beta pruning is also implemented to increase the speed of the function
// To learn more about minimax and alpha beta pruning check out the wikipedia
// article
// - https://en.wikipedia.org/wiki/Minimax
// - https://en.wikipedia.org/wiki/Alpha%E2%80%93beta_pruning
// 
// @param board current tic-tac-toe board
// @param move_depth the amount of moves to look ahead
// @param player which players turn it is, true for 'X' false for 'O'

This function makes a choice for placing a token on the board using the idea
of the minimax algorithm. It generates moves up the specified move depth or
until the game has been completed. After generating moves the minimax
algorithm will make a choice on where is the best place to place a token

If a game score is positive that means that 'X' is winning, if the game
score is negative then 'O' is winning, and if the score is zero then it is
currently a tie.


This function makes a choice for placing a token on the board using the idea of the minimax algorithm . It generates moves up the specified move depth or until the game has been completed . After generating moves the minimax algorithm will make a choice on where is the best place to place a token If a game score is positive that means that ' X ' is winning if the game score is negative then ' O ' is winning and if the score is zero then it is currently a tie .
std::pair<unsigned int, unsigned int> tictactoeai::MakePlacementChoice(
    const tictactoe::TicTacToe &board,
    unsigned int move_depth,
    bool player)
{
  tictactoe::TicTacToe *game = new tictactoe::TicTacToe(board);
  Node* root = new Node(game, {100,100});
  if (player)
    CalcMaxChild(root, true, move_depth, INT32_MIN, INT32_MAX);
  else
    CalcMinChild(root, true, move_depth, INT32_MIN, INT32_MAX);
  std::pair<unsigned int, unsigned int> placement =
   root->children_[root->best_child_]->placement_;
  if (root->children_)
    {
      for (unsigned int i = 0; i < root->child_arr_length_; ++i)
      {
        delete root->children_[i];
      }
      delete [] root->children_;
    }
  delete root;
  return placement;
}
std :: pair < unsigned int , unsigned int > tictactoeai :: MakePlacementChoice ( const tictactoe :: TicTacToe & board , unsigned int move_depth , bool player ) { tictactoe :: TicTacToe * game = new tictactoe :: TicTacToe ( board ) ; Node * root = new Node ( game , { 100 , 100 } ) ; if ( player ) CalcMaxChild ( root , true , move_depth , INT32_MIN , INT32_MAX ) ; else CalcMinChild ( root , true , move_depth , INT32_MIN , INT32_MAX ) ; std :: pair < unsigned int , unsigned int > placement = root -> children_ [ root -> best_child_ ] -> placement_ ; if ( root -> children_ ) { for ( unsigned int i = 0 ; i < root -> child_arr_length_ ; ++ i ) { delete root -> children_ [ i ] ; } delete [ ] root -> children_ ; } delete root ; return placement ; }
This function makes a choice for placing a token on the board using the idea
of the minimax algorithm.
This function makes a choice for placing a token on the board using the idea of the minimax algorithm .