From 80cd2abf98995c6f1ec2ada92baec1cbaa0d4a2a Mon Sep 17 00:00:00 2001 From: Alexander Huddleston Date: Tue, 27 Oct 2015 21:48:04 -0500 Subject: [PATCH] Fixing things. --- Board.cpp | 9 +++++---- Board.h | 1 + Engine.cpp | 20 +++++++++----------- Engine.h | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Board.cpp b/Board.cpp index 72fb1ea..d428ac5 100755 --- a/Board.cpp +++ b/Board.cpp @@ -29,7 +29,8 @@ Board::Board(const Board& b) { vector op = b.getOPieces(); Piece* temp; //bool valid = false; - //char tempturn = b.getTurn(); + char tempturn = b.getTurnPls(); + turn = tempturn; for (int i = 0; i < xp.size(); ++i) { temp = new Piece(xp[i]->getX(), xp[i]->getY(), 'X'); @@ -450,19 +451,19 @@ vector Board::viewPossibleMoves(){ c = opieces[i]->getY(); if (isThisMovePossible(r, c, "FWD")) { - moves temp(8-r,intToCharColumn(c+1), "FWD"); + moves temp(8-r,c, "FWD"); output.push_back(temp); } if (isThisMovePossible(r,c,"LEFT")) { - moves temp(8-r,intToCharColumn(c+1), "LEFT"); + moves temp(8-r,c, "LEFT"); output.push_back(temp); } if (isThisMovePossible(r,c,"RIGHT")) { - moves temp(8-r,intToCharColumn(c+1), "RIGHT"); + moves temp(8-r,c, "RIGHT"); output.push_back(temp); } } diff --git a/Board.h b/Board.h index 9b68242..7a9a170 100755 --- a/Board.h +++ b/Board.h @@ -36,6 +36,7 @@ public: Piece* getPiece(int r, int c); vector getXPieces() const { return xpieces; } vector getOPieces() const { return opieces; } + char getTurnPls() const { return turn; } moves parse(string input); char getTurn() { return turn; } bool isGameOver(); diff --git a/Engine.cpp b/Engine.cpp index d2d9d02..80d2940 100755 --- a/Engine.cpp +++ b/Engine.cpp @@ -92,7 +92,7 @@ void Engine::AI(){ minMax(b, listOfMoves[i]); }*/ - b->move(minMax(temp, listOfMoves[0], 0)); + b->move(minMax(temp, listOfMoves[0], 0, 0)); b->changeTurns(); //verification of correct turn @@ -105,12 +105,13 @@ void Engine::AI(){ 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 cout << "c: " << c << "\n\n"; cout << "current turn: " << temp->getTurn() << "\n"; vector listOfMoves = temp->viewPossibleMoves(); + cout << "listOfMoves size: " << listOfMoves.size() << "\n\n"; if (c > 5){ return m; } @@ -121,23 +122,20 @@ moves Engine::minMax(Board* temp, moves m, int c){ } 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"; temp->move(m); temp->changeTurns(); - temp->displayBoard(); + //temp->displayBoard(); } else { - m = minMax(temp, listOfMoves[c+1], c+1); - } - - for (int i = 0; i < listOfMoves.size(); ++i){ - //return minMax(b, listOfMoves[i]); + cout << m.row << " " << m.column << "\n\n"; + m = minMax(temp, listOfMoves[++r], c, r); } temp->displayBoard(); - //limited recursion - minMax(temp, listOfMoves[c], ++c); + vector listOfMoves = temp->viewPossibleMoves(); + minMax(temp, listOfMoves[c], ++c, 0); //testing return m; diff --git a/Engine.h b/Engine.h index 97efbf8..b6df5f5 100755 --- a/Engine.h +++ b/Engine.h @@ -12,5 +12,5 @@ public: void startGame(); void easyAI(); void AI(); - moves minMax(Board* temp, moves m, int c); + moves minMax(Board* temp, moves m, int c, int r); }; \ No newline at end of file