Stable AI w/o error printing
This commit is contained in:
parent
63c2b52b5a
commit
c3cf43fc00
4 changed files with 12 additions and 10 deletions
14
Board.cpp
14
Board.cpp
|
@ -80,7 +80,7 @@ void Board::isTaken(int r, int c) {
|
||||||
for(int x = 0; x < opieces.size(); ++x) {
|
for(int x = 0; x < opieces.size(); ++x) {
|
||||||
if (opieces[x]->getX() == r && opieces[x]->getY() == c) {
|
if (opieces[x]->getX() == r && opieces[x]->getY() == c) {
|
||||||
opieces.erase(opieces.begin() + x);
|
opieces.erase(opieces.begin() + x);
|
||||||
cout << "otaken set to TRUE\n";
|
//cout << "otaken set to TRUE\n";
|
||||||
otaken = true;
|
otaken = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ void Board::isTaken(int r, int c) {
|
||||||
for(int x = 0; x < xpieces.size(); ++x) {
|
for(int x = 0; x < xpieces.size(); ++x) {
|
||||||
if (xpieces[x]->getX() == r && xpieces[x]->getY() == c) {
|
if (xpieces[x]->getX() == r && xpieces[x]->getY() == c) {
|
||||||
xpieces.erase(xpieces.begin() + x);
|
xpieces.erase(xpieces.begin() + x);
|
||||||
cout << "xtaken set to TRUE\n";
|
//cout << "xtaken set to TRUE\n";
|
||||||
xtaken = true;
|
xtaken = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -582,16 +582,16 @@ int Board::evaluate(char max, char min){
|
||||||
|
|
||||||
val += 2 * (maxPieces.size() - minPieces.size());
|
val += 2 * (maxPieces.size() - minPieces.size());
|
||||||
|
|
||||||
cout << (checkTaken(max)) << "\n";
|
//cout << (checkTaken(max)) << "\n";
|
||||||
cout << (checkTaken(min)) << "\n";
|
//cout << (checkTaken(min)) << "\n";
|
||||||
//check for taken conditions
|
//check for taken conditions
|
||||||
if (checkTaken(min)){
|
if (checkTaken(min)){
|
||||||
cout << "adding 10 to val\n";
|
//cout << "adding 10 to val\n";
|
||||||
val += 10;
|
val += 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checkTaken(max)){
|
if (checkTaken(max)){
|
||||||
cout << "subtracting 10 from val\n";
|
//cout << "subtracting 10 from val\n";
|
||||||
val -= 10;
|
val -= 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -604,7 +604,7 @@ int Board::evaluate(char max, char min){
|
||||||
val = INT_MIN / 2;
|
val = INT_MIN / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << "val: " << val << "\n";
|
//cout << "val: " << val << "\n";
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,7 @@ void Engine::AI(int depth){
|
||||||
createMMTree(root, depth, 1);
|
createMMTree(root, depth, 1);
|
||||||
m = evaluateMMTree(root);
|
m = evaluateMMTree(root);
|
||||||
|
|
||||||
printTree(0, root);
|
//printTree(0, root);
|
||||||
|
|
||||||
b->move(m);
|
b->move(m);
|
||||||
b->changeTurns();
|
b->changeTurns();
|
||||||
|
@ -125,12 +125,12 @@ void Engine::createMMTree(MNode* node, int depth, int alt){
|
||||||
max = current.getTurn();
|
max = current.getTurn();
|
||||||
current.changeTurns();
|
current.changeTurns();
|
||||||
min = current.getTurn();
|
min = current.getTurn();
|
||||||
|
/*
|
||||||
if (current.checkTaken('X'))
|
if (current.checkTaken('X'))
|
||||||
cout << "xtaken true\n";
|
cout << "xtaken true\n";
|
||||||
if (current.checkTaken('O'))
|
if (current.checkTaken('O'))
|
||||||
cout << "otaken true\n";
|
cout << "otaken true\n";
|
||||||
|
*/
|
||||||
temp = new MNode(current, listOfMoves[i], current.evaluate(max, min));
|
temp = new MNode(current, listOfMoves[i], current.evaluate(max, min));
|
||||||
|
|
||||||
if (alt == 1)
|
if (alt == 1)
|
||||||
|
|
1
Engine.h
1
Engine.h
|
@ -8,6 +8,7 @@ using namespace std;
|
||||||
class Engine {
|
class Engine {
|
||||||
Board* b;
|
Board* b;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Engine();
|
Engine();
|
||||||
Board* getBoard() { return b; }
|
Board* getBoard() { return b; }
|
||||||
|
|
1
test.cpp
1
test.cpp
|
@ -4,6 +4,7 @@ using namespace std;
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
Board b;
|
||||||
Engine e;
|
Engine e;
|
||||||
e.startGame();
|
e.startGame();
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue