Fixing things.

This commit is contained in:
Alexander Huddleston 2015-10-27 21:48:04 -05:00
parent d13b1661ee
commit 80cd2abf98
4 changed files with 16 additions and 16 deletions

View file

@ -29,7 +29,8 @@ Board::Board(const Board& b) {
vector<Piece*> op = b.getOPieces(); vector<Piece*> op = b.getOPieces();
Piece* temp; Piece* temp;
//bool valid = false; //bool valid = false;
//char tempturn = b.getTurn(); char tempturn = b.getTurnPls();
turn = tempturn;
for (int i = 0; i < xp.size(); ++i) { for (int i = 0; i < xp.size(); ++i) {
temp = new Piece(xp[i]->getX(), xp[i]->getY(), 'X'); temp = new Piece(xp[i]->getX(), xp[i]->getY(), 'X');
@ -450,19 +451,19 @@ vector<moves> Board::viewPossibleMoves(){
c = opieces[i]->getY(); c = opieces[i]->getY();
if (isThisMovePossible(r, c, "FWD")) if (isThisMovePossible(r, c, "FWD"))
{ {
moves temp(8-r,intToCharColumn(c+1), "FWD"); moves temp(8-r,c, "FWD");
output.push_back(temp); output.push_back(temp);
} }
if (isThisMovePossible(r,c,"LEFT")) if (isThisMovePossible(r,c,"LEFT"))
{ {
moves temp(8-r,intToCharColumn(c+1), "LEFT"); moves temp(8-r,c, "LEFT");
output.push_back(temp); output.push_back(temp);
} }
if (isThisMovePossible(r,c,"RIGHT")) if (isThisMovePossible(r,c,"RIGHT"))
{ {
moves temp(8-r,intToCharColumn(c+1), "RIGHT"); moves temp(8-r,c, "RIGHT");
output.push_back(temp); output.push_back(temp);
} }
} }

View file

@ -36,6 +36,7 @@ public:
Piece* getPiece(int r, int c); Piece* getPiece(int r, int c);
vector<Piece*> getXPieces() const { return xpieces; } vector<Piece*> getXPieces() const { return xpieces; }
vector<Piece*> getOPieces() const { return opieces; } vector<Piece*> getOPieces() const { return opieces; }
char getTurnPls() const { return turn; }
moves parse(string input); moves parse(string input);
char getTurn() { return turn; } char getTurn() { return turn; }
bool isGameOver(); bool isGameOver();

View file

@ -92,7 +92,7 @@ void Engine::AI(){
minMax(b, listOfMoves[i]); minMax(b, listOfMoves[i]);
}*/ }*/
b->move(minMax(temp, listOfMoves[0], 0)); b->move(minMax(temp, listOfMoves[0], 0, 0));
b->changeTurns(); b->changeTurns();
//verification of correct turn //verification of correct turn
@ -105,12 +105,13 @@ void Engine::AI(){
cout << "----------------------END AI FUNCTION----------------------\n"; cout << "----------------------END AI FUNCTION----------------------\n";
} }
moves Engine::minMax(Board* temp, moves m, int c){ moves Engine::minMax(Board* temp, moves m, int c, int r){
//testing purposes only, c = finite depth //testing purposes only, c = finite depth
cout << "c: " << c << "\n\n"; cout << "c: " << c << "\n\n";
cout << "current turn: " << temp->getTurn() << "\n"; cout << "current turn: " << temp->getTurn() << "\n";
vector<moves> listOfMoves = temp->viewPossibleMoves(); vector<moves> listOfMoves = temp->viewPossibleMoves();
cout << "listOfMoves size: " << listOfMoves.size() << "\n\n";
if (c > 5){ if (c > 5){
return m; return m;
} }
@ -121,23 +122,20 @@ moves Engine::minMax(Board* temp, moves m, int c){
} }
else { else {
if(temp->isThisMovePossible(m.row, m.column, m.moveType) && temp->getPiece(m.row, m.column)->getType() == temp->getTurn()){ if(temp->getPiece(8 - m.row, m.column)->getType() == temp->getTurn() && temp->isThisMovePossible(8 - m.row, m.column, m.moveType)){
cout << "piece has been moved in minMax\n"; cout << "piece has been moved in minMax\n";
temp->move(m); temp->move(m);
temp->changeTurns(); temp->changeTurns();
temp->displayBoard(); //temp->displayBoard();
} }
else { else {
m = minMax(temp, listOfMoves[c+1], c+1); cout << m.row << " " << m.column << "\n\n";
} m = minMax(temp, listOfMoves[++r], c, r);
for (int i = 0; i < listOfMoves.size(); ++i){
//return minMax(b, listOfMoves[i]);
} }
temp->displayBoard(); temp->displayBoard();
//limited recursion vector<moves> listOfMoves = temp->viewPossibleMoves();
minMax(temp, listOfMoves[c], ++c); minMax(temp, listOfMoves[c], ++c, 0);
//testing //testing
return m; return m;

View file

@ -12,5 +12,5 @@ public:
void startGame(); void startGame();
void easyAI(); void easyAI();
void AI(); void AI();
moves minMax(Board* temp, moves m, int c); moves minMax(Board* temp, moves m, int c, int r);
}; };