Fixing things.
This commit is contained in:
parent
d13b1661ee
commit
80cd2abf98
4 changed files with 16 additions and 16 deletions
|
@ -29,7 +29,8 @@ Board::Board(const Board& b) {
|
|||
vector<Piece*> 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<moves> 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);
|
||||
}
|
||||
}
|
||||
|
|
1
Board.h
1
Board.h
|
@ -36,6 +36,7 @@ public:
|
|||
Piece* getPiece(int r, int c);
|
||||
vector<Piece*> getXPieces() const { return xpieces; }
|
||||
vector<Piece*> getOPieces() const { return opieces; }
|
||||
char getTurnPls() const { return turn; }
|
||||
moves parse(string input);
|
||||
char getTurn() { return turn; }
|
||||
bool isGameOver();
|
||||
|
|
20
Engine.cpp
20
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<moves> 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<moves> listOfMoves = temp->viewPossibleMoves();
|
||||
minMax(temp, listOfMoves[c], ++c, 0);
|
||||
|
||||
//testing
|
||||
return m;
|
||||
|
|
2
Engine.h
2
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);
|
||||
};
|
Reference in a new issue