cleaning things up. Testing AI.
This commit is contained in:
parent
e8208380a7
commit
4e402357b1
2 changed files with 20 additions and 17 deletions
13
Board.cpp
13
Board.cpp
|
@ -261,7 +261,7 @@ void Board::move(moves m){
|
|||
int row = 8 - (m.row);
|
||||
int column = m.column;
|
||||
|
||||
cout << "INSIDE MOVE: " << row << " " << column << "\n\n";
|
||||
cout << "INSIDE MOVE: " << row << " " << column << " " << m.moveType << "\n\n";
|
||||
|
||||
if (row > 8 || row < 0 || column > 8 || column < 0) {
|
||||
cout<<"ERROR: index out of bound."<<endl;
|
||||
|
@ -328,9 +328,9 @@ void Board::move(moves m){
|
|||
}
|
||||
}
|
||||
else {
|
||||
cout << piece->getX() << " " << piece->getY() << "\n\n";
|
||||
//cout << piece->getX() << " " << piece->getY() << "\n\n";
|
||||
piece->moveRight();
|
||||
cout << piece->getX() << " " << piece->getY() << "\n\n";
|
||||
//cout << piece->getX() << " " << piece->getY() << "\n\n";
|
||||
}
|
||||
}
|
||||
setValidTrue();
|
||||
|
@ -379,7 +379,7 @@ bool Board::isThisMovePossible(int r, int c, string moveType){
|
|||
else if(temp->getType() != piece->getType()) {
|
||||
char a = temp->getType();
|
||||
char b = piece->getType();
|
||||
cout << a << " " << b << "\n\n";
|
||||
//cout << a << " " << b << "\n\n";
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
|
@ -401,7 +401,7 @@ bool Board::isThisMovePossible(int r, int c, string moveType){
|
|||
else if(temp->getType() != piece->getType()) {
|
||||
char a = temp->getType();
|
||||
char b = piece->getType();
|
||||
cout << a << " " << b << "\n\n";
|
||||
//cout << a << " " << b << "\n\n";
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
|
@ -445,7 +445,8 @@ vector<moves> Board::viewPossibleMoves(){
|
|||
}
|
||||
}
|
||||
|
||||
else if (turn == '0') {
|
||||
else if (turn == 'O') {
|
||||
//cout << "\nTESTING\n\n";
|
||||
for (int i = 0; i < opieces.size(); ++i){
|
||||
r = opieces[i]->getX();
|
||||
c = opieces[i]->getY();
|
||||
|
|
24
Engine.cpp
24
Engine.cpp
|
@ -43,11 +43,11 @@ void Engine::startGame(){
|
|||
}
|
||||
}
|
||||
|
||||
if(b->isValid()) cout << b->getTurn();
|
||||
//if(b->isValid()) cout << b->getTurn();
|
||||
|
||||
while(b->getTurn() == 'X' )
|
||||
{
|
||||
easyAI();
|
||||
AI();
|
||||
}
|
||||
|
||||
gameOver = b->isGameOver();
|
||||
|
@ -107,14 +107,15 @@ void Engine::AI(){
|
|||
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";
|
||||
//cout << "c: " << c << "\n\n";
|
||||
//cout << "current turn: " << temp->getTurn() << "\n";
|
||||
vector<moves> listOfMoves = temp->viewPossibleMoves();
|
||||
cout << "listOfMoves size: " << listOfMoves.size() << "\n\n";
|
||||
//cout << "listOfMoves size: " << listOfMoves.size() << "\n\n";
|
||||
/*
|
||||
if (c > 5){
|
||||
return m;
|
||||
}
|
||||
|
||||
*/
|
||||
if (temp->isGameOver() == true){
|
||||
cout << "END OF PATH REACHED\n";
|
||||
return m;
|
||||
|
@ -122,19 +123,20 @@ moves Engine::minMax(Board* temp, moves m, int c, int r){
|
|||
|
||||
else {
|
||||
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->changeTurns();
|
||||
//temp->displayBoard();
|
||||
temp->displayBoard();
|
||||
}
|
||||
else {
|
||||
cout << m.row << " " << m.column << "\n\n";
|
||||
//cout << m.row << " " << m.column << "\n\n";
|
||||
m = minMax(temp, listOfMoves[++r], c, r);
|
||||
}
|
||||
|
||||
temp->displayBoard();
|
||||
//temp->displayBoard();
|
||||
vector<moves> listOfMoves = temp->viewPossibleMoves();
|
||||
minMax(temp, listOfMoves[c], ++c, 0);
|
||||
//cout << "listOfMoves size: " << listOfMoves.size() << "\n\n";
|
||||
minMax(temp, listOfMoves[0], 0, 0);
|
||||
|
||||
//testing
|
||||
return m;
|
||||
|
|
Reference in a new issue