Fixing board errors.

This commit is contained in:
Alexander Huddleston 2015-10-27 13:48:45 -05:00
parent 6a867cd780
commit e969058b96
3 changed files with 57 additions and 6 deletions

View file

@ -94,6 +94,15 @@ void Board::changeTurns(){
} }
void Board::displayBoard(){ void Board::displayBoard(){
/*
cout << "Debugging:\n";
for (int i = 0; i < pieces.size(); ++i){
if(i%8 == 0)
cout << "\n";
cout << pieces[i]->getX() << " " << pieces[i]->getY() << " " << pieces[i]->getType() << "\t";
}
cout << "Debugging:\n\n";
*/
cout << "; A B C D E F G H"<<endl; cout << "; A B C D E F G H"<<endl;
for (int i = 0; i < 8; ++i) { for (int i = 0; i < 8; ++i) {
int label = 8 - i; int label = 8 - i;
@ -118,10 +127,11 @@ void Board::displayBoard(){
string Board::boardToString(){ string Board::boardToString(){
string output = ""; string output = "";
output += "; A B C D E F G H\n"; output += "; A B C D E F G H\n";
int label;
for (int i = 0; i < 8; ++i) { for (int i = 0; i < 8; ++i) {
int label = 8 - i; label = 8 - i;
output += "; "; output += "; ";
output += label; output += '0' + label;
output += " "; output += " ";
for (int j = 0; j < 8; ++j){ for (int j = 0; j < 8; ++j){
if (isPiece(i, j)) if (isPiece(i, j))
@ -188,8 +198,11 @@ void Board::move(moves jugada){
int row = 8 - (jugada.row); int row = 8 - (jugada.row);
int column = charToIntColumn(jugada.column); int column = charToIntColumn(jugada.column);
cout << row << " " << column << "\n\n";
if (row > 8 || row < 0 || column > 8 || column < 0) { if (row > 8 || row < 0 || column > 8 || column < 0) {
cout<<"ERROR: index out of bound."<<endl; cout<<"ERROR: index out of bound."<<endl;
return;
} }
Piece* piece; Piece* piece;
@ -207,18 +220,54 @@ void Board::move(moves jugada){
else { else {
if (jugada.moveType == "FWD") { if (jugada.moveType == "FWD") {
if(isPiece(row--, column)) {
if(getPiece(row--, column)->getType() != piece->getType()) {
getPiece(row--, column)->isTaken();
piece->moveFwd(); piece->moveFwd();
} }
else {
cout << "Invalid move, there is a piece there.\n";
return;
}
}
else {
piece->moveFwd();
}
}
else if (jugada.moveType == "LEFT") { else if (jugada.moveType == "LEFT") {
//add error checking //add error checking
if(isPiece(row--, column--)) {
if(getPiece(row--, column--)->getType() != piece->getType()) {
getPiece(row--, column--)->isTaken();
piece->moveLeft(); piece->moveLeft();
} }
else {
cout << "Invalid move, there is a piece there.\n";
return;
}
}
else {
piece->moveLeft();
}
}
else if (jugada.moveType == "RIGHT") { else if (jugada.moveType == "RIGHT") {
//add error checking //add error checking
if(isPiece(row--, column++)) {
if(getPiece(row--, column++)->getType() != piece->getType()) {
getPiece(row--, column++)->isTaken();
piece->moveRight(); piece->moveRight();
} }
else {
cout << "Invalid move, there is a piece there.\n";
return;
}
}
else {
piece->moveRight();
}
}
} }
} }

View file

@ -41,6 +41,8 @@ void Engine::startGame(){
b->changeTurns(); b->changeTurns();
} }
cout << "TEST\n\n";
while(b->getTurn() == 'X' ) while(b->getTurn() == 'X' )
{ {
easyAI(); easyAI();

View file

@ -65,5 +65,5 @@ void Piece::moveRight(){
} }
void Piece::isTaken(){ void Piece::isTaken(){
// cout << getX() << " " << getY() << "\n\n";
} }