final AI
This commit is contained in:
parent
f5ba309a6e
commit
39c2da093a
3 changed files with 16 additions and 5 deletions
|
@ -475,20 +475,20 @@ int Board::evaluate(char max, char min){
|
||||||
|
|
||||||
//check for taken conditions
|
//check for taken conditions
|
||||||
if (checkTaken(min)){
|
if (checkTaken(min)){
|
||||||
val += 10;
|
val = val + 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checkTaken(max)){
|
if (checkTaken(max)){
|
||||||
val -= 10;
|
val = val - 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
//ultimate condition!
|
//ultimate condition!
|
||||||
if (isGameOver()){
|
if (isGameOver()){
|
||||||
if (whoWon() == max)
|
if (whoWon() == max)
|
||||||
val = INT_MAX / 2;
|
val = val + 10;
|
||||||
|
|
||||||
else
|
else
|
||||||
val = INT_MIN / 2;
|
val = val - 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
//cout << "val: " << val << "\n";
|
//cout << "val: " << val << "\n";
|
||||||
|
|
10
Engine.cpp
10
Engine.cpp
|
@ -65,6 +65,7 @@ void Engine::userGame(int difficulty){
|
||||||
b->resetTaken();
|
b->resetTaken();
|
||||||
b->setValidFalse();
|
b->setValidFalse();
|
||||||
}
|
}
|
||||||
|
b->displayBoard();
|
||||||
}
|
}
|
||||||
|
|
||||||
while(b->getTurn() == 'X' ){
|
while(b->getTurn() == 'X' ){
|
||||||
|
@ -110,9 +111,13 @@ void Engine::AIGame(int difficulty){
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::AI(int depth){
|
void Engine::AI(int depth){
|
||||||
|
if (depth == -1)
|
||||||
|
depth = INT_MAX;
|
||||||
|
|
||||||
Board* state = new Board(*b);
|
Board* state = new Board(*b);
|
||||||
moves m;
|
moves m;
|
||||||
MNode* root = new MNode(*state, m, 0);
|
MNode* root = new MNode(*state, m, 0);
|
||||||
|
this->resetAB();
|
||||||
createMMTree(root, depth, 1);
|
createMMTree(root, depth, 1);
|
||||||
m = evaluateMMTree(root);
|
m = evaluateMMTree(root);
|
||||||
|
|
||||||
|
@ -228,3 +233,8 @@ int Engine::evaluateMMBranch(MNode* node, int max, int min){
|
||||||
|
|
||||||
return max;
|
return max;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Engine::resetAB(){
|
||||||
|
alpha = INT_MIN;
|
||||||
|
beta = INT_MAX;
|
||||||
|
}
|
1
Engine.h
1
Engine.h
|
@ -20,4 +20,5 @@ public:
|
||||||
void createMMTree(MNode* node, int depth, int alt);
|
void createMMTree(MNode* node, int depth, int alt);
|
||||||
moves evaluateMMTree(MNode* node);
|
moves evaluateMMTree(MNode* node);
|
||||||
int evaluateMMBranch(MNode* node, int max, int min);
|
int evaluateMMBranch(MNode* node, int max, int min);
|
||||||
|
void resetAB();
|
||||||
};
|
};
|
||||||
|
|
Reference in a new issue