ai structure done
This commit is contained in:
parent
0b5b8be258
commit
e2be536254
2 changed files with 18 additions and 10 deletions
24
Engine.cpp
24
Engine.cpp
|
@ -23,19 +23,23 @@ void Engine::startGame(){
|
||||||
|
|
||||||
int choice = -1;
|
int choice = -1;
|
||||||
cin >> choice;
|
cin >> choice;
|
||||||
|
cout<<"Enter AI difficulty: \n";
|
||||||
|
int difficulty;
|
||||||
|
cin >> difficulty;
|
||||||
|
|
||||||
cout << "OK" << endl;
|
cout << "OK" << endl;
|
||||||
|
|
||||||
if (choice == 1)
|
if (choice == 1)
|
||||||
userGame();
|
userGame(difficulty);
|
||||||
else if (choice == 2)
|
else if (choice == 2)
|
||||||
AIGame();
|
AIGame(difficulty);
|
||||||
else {
|
else {
|
||||||
cout << "Please enter a valid choice.\n";
|
cout << "Please enter a valid choice.\n";
|
||||||
startGame();
|
startGame();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::userGame(){
|
void Engine::userGame(int difficulty){
|
||||||
string move;
|
string move;
|
||||||
|
|
||||||
bool gameOver = false;
|
bool gameOver = false;
|
||||||
|
@ -60,39 +64,43 @@ void Engine::userGame(){
|
||||||
}
|
}
|
||||||
|
|
||||||
while(b->getTurn() == 'X' ){
|
while(b->getTurn() == 'X' ){
|
||||||
//easyAI();
|
AI(difficulty);
|
||||||
AI(3);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gameOver = b->isGameOver();
|
gameOver = b->isGameOver();
|
||||||
b->setValidFalse();
|
b->setValidFalse();
|
||||||
b->snapshot(record, *b);
|
b->snapshot(record, *b);
|
||||||
}
|
}
|
||||||
|
|
||||||
b->displayBoard();
|
b->displayBoard();
|
||||||
string s = "";
|
string s = "";
|
||||||
s += b->getTurn();
|
s += b->getTurn();
|
||||||
cout << "Game over. " + s + " wins!\n\n";
|
cout << "Game over. " + s + " wins!\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::AIGame(){
|
void Engine::AIGame(int difficulty){
|
||||||
bool gameOver = false;
|
bool gameOver = false;
|
||||||
|
|
||||||
while (gameOver != true){
|
while (gameOver != true){
|
||||||
gameOver = b->isGameOver();
|
gameOver = b->isGameOver();
|
||||||
|
|
||||||
while(b->getTurn() == 'O'){
|
while(b->getTurn() == 'O'){
|
||||||
AI(3);
|
AI(difficulty);
|
||||||
}
|
}
|
||||||
|
|
||||||
b->displayBoard();
|
b->displayBoard();
|
||||||
sleep(1);
|
sleep(1);
|
||||||
|
|
||||||
while(b->getTurn() == 'X' ){
|
while(b->getTurn() == 'X' ){
|
||||||
AI(3);
|
AI(difficulty);
|
||||||
}
|
}
|
||||||
|
|
||||||
gameOver = b->isGameOver();
|
gameOver = b->isGameOver();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string s = "";
|
||||||
|
s += b->getTurn();
|
||||||
|
cout << "Game over. " + s + " wins!\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::AI(int depth){
|
void Engine::AI(int depth){
|
||||||
|
|
4
Engine.h
4
Engine.h
|
@ -13,8 +13,8 @@ public:
|
||||||
Engine();
|
Engine();
|
||||||
Board* getBoard() { return b; }
|
Board* getBoard() { return b; }
|
||||||
void startGame();
|
void startGame();
|
||||||
void userGame();
|
void userGame(int difficulty);
|
||||||
void AIGame();
|
void AIGame(int difficulty);
|
||||||
void AI(int depth);
|
void AI(int depth);
|
||||||
void createMMTree(MNode* node, int depth, int alt);
|
void createMMTree(MNode* node, int depth, int alt);
|
||||||
moves evaluateMMTree(MNode* node);
|
moves evaluateMMTree(MNode* node);
|
||||||
|
|
Reference in a new issue