From 5b9fc9393be7443e37ad08122d2354f34de5ca88 Mon Sep 17 00:00:00 2001 From: Rebecca Schofield Date: Thu, 29 Oct 2015 13:06:15 -0500 Subject: [PATCH 1/4] structure done- unstable --- Engine.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++------ Engine.h | 3 ++- MNode.cpp | 8 ++++---- MNode.h | 6 +++--- test.cpp | 27 +++++++++++++++++++++++++-- 5 files changed, 82 insertions(+), 16 deletions(-) diff --git a/Engine.cpp b/Engine.cpp index 17079f0..947b583 100644 --- a/Engine.cpp +++ b/Engine.cpp @@ -43,8 +43,8 @@ void Engine::startGame(){ } while(b->getTurn() == 'X' ){ - easyAI(); - //AI(3); + //easyAI(); + AI(3); } gameOver = b->isGameOver(); @@ -68,6 +68,8 @@ void Engine::AI(int depth){ Board* temp = new Board(*b); moves empty; MNode* root = new MNode(*temp, empty, 0); + root = createMMTree(root, depth); + //printTree(0, root); CURRENTLY PRODUCES SEG FAULT //only doing 1 branch right now because testing /*for (int i = 0; i < listOfMoves.size(); ++i){ @@ -75,15 +77,29 @@ void Engine::AI(int depth){ }*/ //remove this soon - //b->move(minMax(temp, listOfMoves[0], 0, 0)); - - b->changeTurns(); + //b->move(minMax(temp, listOfMoves[0], 0, 0; + + vector listOfMoves = b->viewPossibleMoves(); + b->move(listOfMoves[0]); + + b->changeTurns(); b->displayBoard(); } -moves Engine::minMax(MNode* node, int depth){ +MNode* Engine::createMMTree(MNode* node, int depth){ Board current = node->getState(); vector listOfMoves = current.viewPossibleMoves(); + vector children = node->getChildren(); + + if (depth >= 0){ + for (int i = 0; i < children.size(); ++i){ + cout << "i: " << i << "\n"; + node->addChild(createMMTree(children[i], --depth)); + } + } + + else return node; + /* if (current.isGameOver() == true){ cout << "END OF PATH REACHED\n\n"; @@ -106,3 +122,29 @@ moves Engine::minMax(MNode* node, int depth){ } */ } + +moves Engine::evaluateMMTree(MNode* node){ + //returns the move from children that maximizes evaluate() + moves m; + vector children = node->getChildren(); + + for (auto &c : children){ + cout << "c: " << c->getMMVal(); + } + + return m; +} +/* +//return sum of eval values +//pass in each child of root and 0 +int Engine::evaluateMMBranch(Node* node, int sum){ + sum += node->getMMVal(); + vector children = node->getChildren(); + + for (auto &c : children){ + sum += evaluateMMBranch(c, sum); + } + + return sum; +} +*/ \ No newline at end of file diff --git a/Engine.h b/Engine.h index 89f3327..104284b 100644 --- a/Engine.h +++ b/Engine.h @@ -14,5 +14,6 @@ public: void startGame(); void easyAI(); void AI(int depth); - moves minMax(MNode* node, int depth); + MNode* createMMTree(MNode* node, int depth); + moves evaluateMMTree(MNode* node); }; diff --git a/MNode.cpp b/MNode.cpp index 8f4c410..ca4c548 100755 --- a/MNode.cpp +++ b/MNode.cpp @@ -31,13 +31,13 @@ bool MNode::hasChildren(){ return false; } -void printTree(int depth, const MNode& n){ +void printTree(int depth, MNode* n){ vector children; - cout << "depth " << depth << " :" << n.getMMVal() << " "; - children = n.getChildren(); + cout << "depth " << depth << " : " << n->getMMVal() << " | "; + children = n->getChildren(); //print out root for (int i = 0; i < children.size(); ++i){ - printTree(++depth, *children[i]); + printTree(++depth, children[i]); } } \ No newline at end of file diff --git a/MNode.h b/MNode.h index 1afe963..a35de3d 100755 --- a/MNode.h +++ b/MNode.h @@ -20,11 +20,11 @@ public: void addChild(MNode* n) { children.push_back(n); } int getMMVal() const { return minimax_val; } void setMMVal(int mmval); - Board getState() { return state; } + Board getState() const { return state; } void setState(Board s) { state = s; } - moves getMove() { return mvs; } + moves getMove() const { return mvs; } void setMove(moves m) { mvs = m; } bool hasChildren(); }; -void printTree(int depth, const MNode& n); \ No newline at end of file +void printTree(int depth, MNode* n); \ No newline at end of file diff --git a/test.cpp b/test.cpp index c26c406..ec8eb3e 100644 --- a/test.cpp +++ b/test.cpp @@ -4,7 +4,30 @@ using namespace std; int main() { + MNode* a = new MNode(); + MNode* b = new MNode(); + MNode* c = new MNode(); + MNode* d = new MNode(); + + a->setMMVal(1); + b->setMMVal(3); + c->setMMVal(87); + d->setMMVal(-1); + + a->addChild(b); + a->addChild(c); + b->addChild(d); + + printTree(0, a); + cout << "\n"; + printTree(0, b); + cout << "\n"; + printTree(0, c); + cout << "\n"; + printTree(0, d); + cout << "\n"; + //Board b; - Engine e; - e.startGame(); + //Engine e; + //e.startGame(); } From 5f4c6c25391ff269f7d79ea9d7f0a3e93b973d22 Mon Sep 17 00:00:00 2001 From: Rebecca Schofield Date: Thu, 29 Oct 2015 13:54:16 -0500 Subject: [PATCH 2/4] compiles, but not correct --- Board.cpp | 17 +++++++---- Board.h | 2 +- Engine.cpp | 88 +++++++++++++++++++++++++----------------------------- Engine.h | 3 +- test.cpp | 28 ++--------------- 5 files changed, 58 insertions(+), 80 deletions(-) diff --git a/Board.cpp b/Board.cpp index 6750ab2..072fc95 100644 --- a/Board.cpp +++ b/Board.cpp @@ -1,3 +1,5 @@ +#include +#include #include #include #include "Board.h" @@ -536,19 +538,24 @@ void Board::snapshot(vector& inputVec, Board inputBoard){ inputVec.push_back(inputBoard); } -int Board::evaluate(char max, char min){ - //right now just evaluating number of pieces +int Board::evaluate(char max){ + int val = 0; + + srand(time(NULL)); + val = rand() % 100 + 1; + /* if (max == 'X'){ - return (xpieces.size() - opieces.size()); + val += (xpieces.size() - opieces.size()); } else if (max == 'O'){ - return (opieces.size() - xpieces.size()); + val += (opieces.size() - xpieces.size()); } else { cout << "Error in evaluate: unidentified max, must be either 'X' or 'O'.\n"; - return 0; } + */ + return val; } diff --git a/Board.h b/Board.h index 7af5bcf..cc01a6a 100644 --- a/Board.h +++ b/Board.h @@ -60,5 +60,5 @@ public: void undo(Board& tablero); void interpret(string input, Board& tablero); void snapshot(vector& inputVec, Board inputBoard); - int evaluate(char max, char min); + int evaluate(char max); }; diff --git a/Engine.cpp b/Engine.cpp index 947b583..5430dbb 100644 --- a/Engine.cpp +++ b/Engine.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include "Engine.h" Engine::Engine(){ @@ -65,19 +66,16 @@ void Engine::easyAI(){ } void Engine::AI(int depth){ - Board* temp = new Board(*b); - moves empty; - MNode* root = new MNode(*temp, empty, 0); - root = createMMTree(root, depth); - //printTree(0, root); CURRENTLY PRODUCES SEG FAULT - - //only doing 1 branch right now because testing - /*for (int i = 0; i < listOfMoves.size(); ++i){ - minMax(b, listOfMoves[i]); - }*/ - - //remove this soon - //b->move(minMax(temp, listOfMoves[0], 0, 0; + Board* state = new Board(*b); + moves m; + MNode* root = new MNode(*state, m, 0); + createMMTree(root, depth); + m = evaluateMMTree(root); + cout << "\n"; + /* + printTree(0, root); + cout << "\n"; + */ vector listOfMoves = b->viewPossibleMoves(); b->move(listOfMoves[0]); @@ -86,58 +84,53 @@ void Engine::AI(int depth){ b->displayBoard(); } -MNode* Engine::createMMTree(MNode* node, int depth){ +void Engine::createMMTree(MNode* node, int depth){ + MNode* temp; Board current = node->getState(); vector listOfMoves = current.viewPossibleMoves(); - vector children = node->getChildren(); - + if (depth >= 0){ - for (int i = 0; i < children.size(); ++i){ - cout << "i: " << i << "\n"; - node->addChild(createMMTree(children[i], --depth)); + for (int i = 0; i < listOfMoves.size(); ++i){ + if(current.getPiece(8 - listOfMoves[i].row, listOfMoves[i].column)->getType() == + current.getTurn() && current.isThisMovePossible(8 - listOfMoves[i].row, + listOfMoves[i].column, + listOfMoves[i].moveType)){ + current = current.move(listOfMoves[i]); + current.changeTurns(); + temp = new MNode(current, listOfMoves[i], current.evaluate('X')); + node->addChild(temp); + createMMTree(temp, --depth); + current.changeTurns(); + } } } - else return node; - - /* - if (current.isGameOver() == true){ - cout << "END OF PATH REACHED\n\n"; - return m; - } - - else { - if(current.getPiece(8 - m.row, m.column)->getType() == current.getTurn() && current.isThisMovePossible(8 - m.row, m.column, m.moveType)){ - temp->move(m); - temp->evaluate('X', 'O'); - temp->changeTurns(); - } - else { - m = minMax(temp, listOfMoves[++r], c, r); - } - - vector listOfMoves = temp->viewPossibleMoves(); - minMax(temp, listOfMoves[0], 0, 0); - return m; - } - */ + return; } moves Engine::evaluateMMTree(MNode* node){ //returns the move from children that maximizes evaluate() + MNode* temp; moves m; + int max = INT_MIN; + int val; vector children = node->getChildren(); for (auto &c : children){ - cout << "c: " << c->getMMVal(); + val = evaluateMMBranch(c, 0); + + if(val > max){ + temp = c; + max = val; + } } - return m; + return temp->getMove(); } -/* + //return sum of eval values //pass in each child of root and 0 -int Engine::evaluateMMBranch(Node* node, int sum){ +int Engine::evaluateMMBranch(MNode* node, int sum){ sum += node->getMMVal(); vector children = node->getChildren(); @@ -146,5 +139,4 @@ int Engine::evaluateMMBranch(Node* node, int sum){ } return sum; -} -*/ \ No newline at end of file +} \ No newline at end of file diff --git a/Engine.h b/Engine.h index 104284b..b915383 100644 --- a/Engine.h +++ b/Engine.h @@ -14,6 +14,7 @@ public: void startGame(); void easyAI(); void AI(int depth); - MNode* createMMTree(MNode* node, int depth); + void createMMTree(MNode* node, int depth); moves evaluateMMTree(MNode* node); + int evaluateMMBranch(MNode* node, int sum); }; diff --git a/test.cpp b/test.cpp index ec8eb3e..302979c 100644 --- a/test.cpp +++ b/test.cpp @@ -4,30 +4,8 @@ using namespace std; int main() { - MNode* a = new MNode(); - MNode* b = new MNode(); - MNode* c = new MNode(); - MNode* d = new MNode(); + Engine e; + e.startGame(); - a->setMMVal(1); - b->setMMVal(3); - c->setMMVal(87); - d->setMMVal(-1); - - a->addChild(b); - a->addChild(c); - b->addChild(d); - - printTree(0, a); - cout << "\n"; - printTree(0, b); - cout << "\n"; - printTree(0, c); - cout << "\n"; - printTree(0, d); - cout << "\n"; - - //Board b; - //Engine e; - //e.startGame(); + //COMPILES BUT EVERYTHING IS PRINTING FIRST MOVE } From 01b8e2c06baa41a445409760982d1a5cbd6a0aaa Mon Sep 17 00:00:00 2001 From: Rebecca Schofield Date: Fri, 30 Oct 2015 11:56:44 -0500 Subject: [PATCH 3/4] tree DONE, no ab pruning --- Board.cpp | 5 +---- Engine.cpp | 8 +++----- test.cpp | 2 -- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/Board.cpp b/Board.cpp index 072fc95..92f0e08 100644 --- a/Board.cpp +++ b/Board.cpp @@ -541,9 +541,6 @@ void Board::snapshot(vector& inputVec, Board inputBoard){ int Board::evaluate(char max){ int val = 0; - srand(time(NULL)); - val = rand() % 100 + 1; - /* if (max == 'X'){ val += (xpieces.size() - opieces.size()); } @@ -555,7 +552,7 @@ int Board::evaluate(char max){ else { cout << "Error in evaluate: unidentified max, must be either 'X' or 'O'.\n"; } - */ + return val; } diff --git a/Engine.cpp b/Engine.cpp index 5430dbb..83bf785 100644 --- a/Engine.cpp +++ b/Engine.cpp @@ -71,15 +71,14 @@ void Engine::AI(int depth){ MNode* root = new MNode(*state, m, 0); createMMTree(root, depth); m = evaluateMMTree(root); - cout << "\n"; + /* printTree(0, root); cout << "\n"; + cout << "AI move: (" << m.row << ", " << m.column << "): " << m.moveType << "\n"; */ - vector listOfMoves = b->viewPossibleMoves(); - b->move(listOfMoves[0]); - + b->move(m); b->changeTurns(); b->displayBoard(); } @@ -118,7 +117,6 @@ moves Engine::evaluateMMTree(MNode* node){ for (auto &c : children){ val = evaluateMMBranch(c, 0); - if(val > max){ temp = c; max = val; diff --git a/test.cpp b/test.cpp index 302979c..8b1eb77 100644 --- a/test.cpp +++ b/test.cpp @@ -6,6 +6,4 @@ int main() { Engine e; e.startGame(); - - //COMPILES BUT EVERYTHING IS PRINTING FIRST MOVE } From 1de453bce57526f394a80dae8ebe58fdcf5a012e Mon Sep 17 00:00:00 2001 From: Rebecca Schofield Date: Mon, 2 Nov 2015 16:19:42 -0600 Subject: [PATCH 4/4] master AI commit, stable w/o alpha beta --- Board.cpp | 102 ++++++++++++++++++++++++++++++++++++++++------------- Board.h | 15 ++++---- Engine.cpp | 96 +++++++++++++++++++++++++++++++++++-------------- Engine.h | 5 +-- MNode.cpp | 2 +- MNode.h | 3 ++ Piece.cpp | 4 --- Piece.h | 3 +- 8 files changed, 162 insertions(+), 68 deletions(-) diff --git a/Board.cpp b/Board.cpp index 92f0e08..6f30d40 100644 --- a/Board.cpp +++ b/Board.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include "Board.h" @@ -8,7 +9,7 @@ using namespace std; Board::Board() { Piece* temp; - bool valid = false; + for (int i = 0; i < 2; ++i) { for (int j = 0; j < 8; ++j) { temp = new Piece(i, j, 'X'); @@ -24,14 +25,15 @@ Board::Board() { pieces.push_back(temp); } } + + valid, xtaken, otaken = false; } Board::Board(const Board& b) { - vector xp = b.getXPieces(); - vector op = b.getOPieces(); + vector xp = b.getTypePieces('X'); + vector op = b.getTypePieces('O'); Piece* temp; - //bool valid = false; - char tempturn = b.getTurnPls(); + char tempturn = b.getTurn(); turn = tempturn; for (int i = 0; i < xp.size(); ++i) { @@ -45,6 +47,8 @@ Board::Board(const Board& b) { opieces.push_back(temp); pieces.push_back(temp); } + + valid, xtaken, otaken = false; } //make this efficient! @@ -76,6 +80,8 @@ void Board::isTaken(int r, int c) { for(int x = 0; x < opieces.size(); ++x) { if (opieces[x]->getX() == r && opieces[x]->getY() == c) { opieces.erase(opieces.begin() + x); + cout << "otaken set to TRUE\n"; + otaken = true; } } } @@ -83,6 +89,8 @@ void Board::isTaken(int r, int c) { for(int x = 0; x < xpieces.size(); ++x) { if (xpieces[x]->getX() == r && xpieces[x]->getY() == c) { xpieces.erase(xpieces.begin() + x); + cout << "xtaken set to TRUE\n"; + xtaken = true; } } } @@ -92,6 +100,30 @@ void Board::isTaken(int r, int c) { } } +bool Board::checkTaken(char c){ + if (c == 'X'){ + return xtaken; + } + + else if (c == 'O'){ + return otaken; + } + + else + return false; +} + +vector Board::getTypePieces(char type) const{ + if (type == 'X') + return xpieces; + else if (type == 'O') + return opieces; + else{ + cout << "Invalid type!\n"; + return pieces; + } +} + moves Board::parse(string input){ input = myToUpper(input); @@ -138,20 +170,21 @@ bool Board::isGameOver(){ return false; } -string Board::whoWon(){ +char Board::whoWon(){ for (int i = 0; i < xpieces.size(); ++i){ if (xpieces[i]->getX() == 7){ - return "Player X wins!"; + return 'X'; } } for (int i = 0; i < opieces.size(); ++i){ if (opieces[i]->getX() == 0){ - return "Player O wins!"; + return 'O'; } } - return "ERROR: function whoWon() called incorrectly."; + cout << "ERROR: function whoWon() called incorrectly. Game is not over. \n"; + return 'a'; } void Board::changeTurns(){ @@ -159,6 +192,11 @@ void Board::changeTurns(){ else turn = 'O'; } +void Board::resetTaken(){ + xtaken = false; + otaken = false; +} + void Board::displayBoard(){ cout << "; A B C D E F G H"<& inputVec, Board inputBoard){ inputVec.push_back(inputBoard); } -int Board::evaluate(char max){ - int val = 0; - - if (max == 'X'){ - val += (xpieces.size() - opieces.size()); - } - - else if (max == 'O'){ - val += (opieces.size() - xpieces.size()); - } - - else { - cout << "Error in evaluate: unidentified max, must be either 'X' or 'O'.\n"; +int Board::evaluate(char max, char min){ + vector maxPieces = getTypePieces(max); + vector minPieces = getTypePieces(min); + int reflector, val, x, y = 0; + Piece* temp; + + val += 2 * (maxPieces.size() - minPieces.size()); + + cout << (checkTaken(max)) << "\n"; + cout << (checkTaken(min)) << "\n"; + //check for taken conditions + if (checkTaken(min)){ + cout << "adding 10 to val\n"; + val += 10; } + if (checkTaken(max)){ + cout << "subtracting 10 from val\n"; + val -= 10; + } + + //ultimate condition! + if (isGameOver()){ + if (whoWon() == max) + val = INT_MAX / 2; + + else + val = INT_MIN / 2; + } + + cout << "val: " << val << "\n"; return val; } diff --git a/Board.h b/Board.h index cc01a6a..13a820c 100644 --- a/Board.h +++ b/Board.h @@ -28,8 +28,8 @@ class Board { vector xpieces; vector opieces; vector pieces; + bool valid, xtaken, otaken; char turn = 'O'; - bool valid = false; public: Board(); @@ -40,14 +40,15 @@ public: bool isPiece(int r, int c); Piece* getPiece(int r, int c); void isTaken(int r, int c); - vector getXPieces() const { return xpieces; } - vector getOPieces() const { return opieces; } - char getTurnPls() const { return turn; } + bool checkTaken(char c); + vector getPieces() const { return pieces; } + vector getTypePieces(char type) const; + char getTurn() const { return turn; } moves parse(string input); - char getTurn() { return turn; } bool isGameOver(); - string whoWon(); + char whoWon(); void changeTurns(); + void resetTaken(); void displayBoard(); string boardToString(); int charToIntColumn(char input); @@ -60,5 +61,5 @@ public: void undo(Board& tablero); void interpret(string input, Board& tablero); void snapshot(vector& inputVec, Board inputBoard); - int evaluate(char max); + int evaluate(char max, char min); }; diff --git a/Engine.cpp b/Engine.cpp index 83bf785..bb3efe5 100644 --- a/Engine.cpp +++ b/Engine.cpp @@ -3,6 +3,8 @@ #include #include #include +#include +#include #include "Engine.h" Engine::Engine(){ @@ -14,13 +16,24 @@ void Engine::startGame(){ cout<<"WELCOME\n"; cout<<"1. Play against AI?\n"; - cout<<"2. Play against a human?\n"; + cout<<"2. Watch AI vs AI?\n"; cout<<"Enter choice: \n"; int choice = -1; cin >> choice; cout << "OK" << endl; + if (choice == 1) + userGame(); + else if (choice == 2) + AIGame(); + else { + cout << "Please enter a valid choice.\n"; + startGame(); + } +} + +void Engine::userGame(){ string move; bool gameOver = false; @@ -39,6 +52,7 @@ void Engine::startGame(){ if(b->isValid()){ b->changeTurns(); + b->resetTaken(); b->setValidFalse(); } } @@ -55,36 +69,44 @@ void Engine::startGame(){ } } -void Engine::easyAI(){ - vector listOfMoves = b->viewPossibleMoves(); - - srand(time(NULL)); - int randomChoice = rand() % (listOfMoves.size()-1) - 0; - - b->move(listOfMoves[randomChoice]); - b->changeTurns(); +void Engine::AIGame(){ + bool gameOver = false; + + while (gameOver != true){ + gameOver = b->isGameOver(); + + while(b->getTurn() == 'O'){ + AI(3); + } + + b->displayBoard(); + sleep(1); + + while(b->getTurn() == 'X' ){ + AI(3); + } + + gameOver = b->isGameOver(); + } } void Engine::AI(int depth){ Board* state = new Board(*b); moves m; MNode* root = new MNode(*state, m, 0); - createMMTree(root, depth); + createMMTree(root, depth, 1); m = evaluateMMTree(root); - - /* + printTree(0, root); - cout << "\n"; - cout << "AI move: (" << m.row << ", " << m.column << "): " << m.moveType << "\n"; - */ b->move(m); b->changeTurns(); - b->displayBoard(); + b->resetTaken(); } -void Engine::createMMTree(MNode* node, int depth){ +void Engine::createMMTree(MNode* node, int depth, int alt){ MNode* temp; + char max, min; Board current = node->getState(); vector listOfMoves = current.viewPossibleMoves(); @@ -94,11 +116,29 @@ void Engine::createMMTree(MNode* node, int depth){ current.getTurn() && current.isThisMovePossible(8 - listOfMoves[i].row, listOfMoves[i].column, listOfMoves[i].moveType)){ + current.resetTaken(); current = current.move(listOfMoves[i]); + max = current.getTurn(); current.changeTurns(); - temp = new MNode(current, listOfMoves[i], current.evaluate('X')); + min = current.getTurn(); + + if (current.checkTaken('X')) + cout << "xtaken true\n"; + if (current.checkTaken('O')) + cout << "otaken true\n"; + + temp = new MNode(current, listOfMoves[i], current.evaluate(max, min)); + + if (alt == 1) + temp->setType("max"); + else if (alt == 1) + temp->setType("min"); + + current.resetTaken(); node->addChild(temp); - createMMTree(temp, --depth); + + createMMTree(temp, --depth, alt * -1); + current.changeTurns(); } } @@ -116,25 +156,27 @@ moves Engine::evaluateMMTree(MNode* node){ vector children = node->getChildren(); for (auto &c : children){ - val = evaluateMMBranch(c, 0); + val = evaluateMMBranch(c, INT_MIN); if(val > max){ temp = c; max = val; } } - + return temp->getMove(); } -//return sum of eval values -//pass in each child of root and 0 -int Engine::evaluateMMBranch(MNode* node, int sum){ - sum += node->getMMVal(); +int Engine::evaluateMMBranch(MNode* node, int max){ + if (node->getMMVal() > max) + max = node->getMMVal(); + vector children = node->getChildren(); for (auto &c : children){ - sum += evaluateMMBranch(c, sum); + evaluateMMBranch(c, max); } + + //cout << "max: " << max << "\n"; - return sum; + return max; } \ No newline at end of file diff --git a/Engine.h b/Engine.h index b915383..fbcb212 100644 --- a/Engine.h +++ b/Engine.h @@ -12,9 +12,10 @@ public: Engine(); Board* getBoard() { return b; } void startGame(); - void easyAI(); + void userGame(); + void AIGame(); void AI(int depth); - void createMMTree(MNode* node, int depth); + void createMMTree(MNode* node, int depth, int alt); moves evaluateMMTree(MNode* node); int evaluateMMBranch(MNode* node, int sum); }; diff --git a/MNode.cpp b/MNode.cpp index ca4c548..8865b29 100755 --- a/MNode.cpp +++ b/MNode.cpp @@ -33,7 +33,7 @@ bool MNode::hasChildren(){ void printTree(int depth, MNode* n){ vector children; - cout << "depth " << depth << " : " << n->getMMVal() << " | "; + cout << "depth " << depth << " : " << n->getMMVal() << "\n"; children = n->getChildren(); //print out root diff --git a/MNode.h b/MNode.h index a35de3d..1db411e 100755 --- a/MNode.h +++ b/MNode.h @@ -11,6 +11,7 @@ class MNode { Board state; moves mvs; int minimax_val; + string type; //min or max public: MNode(); @@ -24,6 +25,8 @@ public: void setState(Board s) { state = s; } moves getMove() const { return mvs; } void setMove(moves m) { mvs = m; } + string getType() { return type; } + void setType(string t) { type = t; } bool hasChildren(); }; diff --git a/Piece.cpp b/Piece.cpp index a438327..bd78a31 100644 --- a/Piece.cpp +++ b/Piece.cpp @@ -63,7 +63,3 @@ void Piece::moveRight(){ else cout << "Error: trying to move an empty piece left."; } - -void Piece::isTaken(){ - cout << getX() << " " << getY() << "\n\n"; -} diff --git a/Piece.h b/Piece.h index 82f6bed..4da1f83 100644 --- a/Piece.h +++ b/Piece.h @@ -20,5 +20,4 @@ public: void setY(int c){ y = c; } char getType(){ return type; } void makeEmpty(){ type = '_'; } - void isTaken(); -}; +};