Fixing moves.

This commit is contained in:
Alexander Huddleston 2015-10-27 14:49:03 -05:00
parent e969058b96
commit aa50abcaff

View file

@ -198,7 +198,7 @@ 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"; //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;
@ -206,6 +206,7 @@ void Board::move(moves jugada){
} }
Piece* piece; Piece* piece;
//cout << "TEST" << row << " " << column << "\n\n";
if (isPiece(row, column)) if (isPiece(row, column))
piece = getPiece(row, column); piece = getPiece(row, column);
@ -213,22 +214,22 @@ void Board::move(moves jugada){
cout<<"ERROR: attempting to move an invalid piece.\n"; cout<<"ERROR: attempting to move an invalid piece.\n";
return; return;
} }
//cout << piece->getX() << piece->getY() << "\n\n";
if (piece->getType() != turn) { if (piece->getType() != turn) {
cout<<"ERROR: attempting to move the wrong side's piece.\n"; cout<<"ERROR: attempting to move the wrong side's piece.\n";
} }
else { else {
if (jugada.moveType == "FWD") { if (jugada.moveType == "FWD") {
if(isPiece(row--, column)) { if(piece->getType() == 'O') {
if(getPiece(row--, column)->getType() != piece->getType()) { row--;
getPiece(row--, column)->isTaken(); }
piece->moveFwd(); else {
} row++;
else { }
cout << "Invalid move, there is a piece there.\n"; if(isPiece(row, column)) {
return; cout << "Invalid move, there is a piece there.\n";
} return;
} }
else { else {
piece->moveFwd(); piece->moveFwd();