Fixing moves.
This commit is contained in:
parent
e969058b96
commit
aa50abcaff
1 changed files with 12 additions and 11 deletions
23
Board.cpp
23
Board.cpp
|
@ -198,7 +198,7 @@ void Board::move(moves jugada){
|
|||
int row = 8 - (jugada.row);
|
||||
int column = charToIntColumn(jugada.column);
|
||||
|
||||
cout << row << " " << column << "\n\n";
|
||||
//cout << row << " " << column << "\n\n";
|
||||
|
||||
if (row > 8 || row < 0 || column > 8 || column < 0) {
|
||||
cout<<"ERROR: index out of bound."<<endl;
|
||||
|
@ -206,6 +206,7 @@ void Board::move(moves jugada){
|
|||
}
|
||||
|
||||
Piece* piece;
|
||||
//cout << "TEST" << row << " " << column << "\n\n";
|
||||
if (isPiece(row, column))
|
||||
piece = getPiece(row, column);
|
||||
|
||||
|
@ -213,22 +214,22 @@ void Board::move(moves jugada){
|
|||
cout<<"ERROR: attempting to move an invalid piece.\n";
|
||||
return;
|
||||
}
|
||||
|
||||
//cout << piece->getX() << piece->getY() << "\n\n";
|
||||
if (piece->getType() != turn) {
|
||||
cout<<"ERROR: attempting to move the wrong side's piece.\n";
|
||||
}
|
||||
|
||||
else {
|
||||
if (jugada.moveType == "FWD") {
|
||||
if(isPiece(row--, column)) {
|
||||
if(getPiece(row--, column)->getType() != piece->getType()) {
|
||||
getPiece(row--, column)->isTaken();
|
||||
piece->moveFwd();
|
||||
}
|
||||
else {
|
||||
cout << "Invalid move, there is a piece there.\n";
|
||||
return;
|
||||
}
|
||||
if(piece->getType() == 'O') {
|
||||
row--;
|
||||
}
|
||||
else {
|
||||
row++;
|
||||
}
|
||||
if(isPiece(row, column)) {
|
||||
cout << "Invalid move, there is a piece there.\n";
|
||||
return;
|
||||
}
|
||||
else {
|
||||
piece->moveFwd();
|
||||
|
|
Reference in a new issue