Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Tic-Tac-Toe/AI.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
79 lines (68 sloc)
1.49 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "AI.h" | |
AI::AI() | |
{ | |
// Constructor | |
void AI::setTargetGrid(Grid *grid) | |
{ | |
gridPtr = grid; | |
} | |
void AI::aiTurn() | |
{ | |
// Calls the correct AI move for the selected difficulty | |
if(difficulty == Impossible) | |
{ | |
impossibleAITurn(); | |
} | |
else | |
{ | |
normalAITurn(); | |
} | |
} | |
void AI::normalAITurn() | |
{ | |
// AI logic for normal difficulty | |
} | |
void AI::impossibleAITurn() | |
{ | |
// AI logic for impossible difficulty | |
} | |
char AI::getSymbol() | |
{ | |
// Returns the symbol the AI player is using | |
return this->symbol; | |
} | |
void AI::setSymbol(char playerSymbol) | |
{ | |
// Sets the AI symbol to the opposite of the player's | |
if(playerSymbol == 'O') | |
{ | |
symbol = 'X'; | |
} | |
else | |
{ | |
symbol = 'O'; | |
} | |
} | |
void AI::setDifficulty() | |
{ | |
// ALlows the player to choose the difficulty and sets values accordingly | |
int choice = 0; | |
std::cout << "There are two difficulties to choose from, which would you like?" << std::endl; | |
std::cout << " 1 - Normal\n 2 - Impossible\n" << std::endl; | |
std::cin >> choice; | |
switch(choice) | |
{ | |
case 1: | |
difficulty = Normal; | |
std::cout << "\nNormal difficulty has been selected" << std::endl; | |
break; | |
case 2: | |
difficulty = Impossible; | |
std::cout << "\nImpossible difficulty has been selected" << std::endl; | |
break; | |
default: | |
difficulty = Normal; | |
std::cout << "\nInvalid option, defaulting to Normal difficulty" << std::endl; | |
break; | |
} | |
} |