src/rook.cpp
/**
 * @brief Given board state, mark all squares that the piece is capable of moving to.
 * @param board Square*[][] Array of Square class pointers representing board state.
 * @see Piece::markDanger
 * @see Board::p_squares
 *
 * Iterates over the board upwards, downwards, leftwards, and rightwards until another piece or the edge of the board is
 * encountered. Every Square object iterated over is marked. If an enemy piece is encountered, the enemy piece's
 * location is marked. If a friendly piece is encountered, the friendly piece's location is not marked. Either case
 * results in a break.
 *
 */
@brief Given board state, mark all squares that the piece is capable of moving to.
@param board Square*[][] Array of Square class pointers representing board state.
@see Piece::markDanger
@see Board::p_squares

Iterates over the board upwards, downwards, leftwards, and rightwards until another piece or the edge of the board is
encountered. Every Square object iterated over is marked. If an enemy piece is encountered, the enemy piece's
location is marked. If a friendly piece is encountered, the friendly piece's location is not marked. Either case
results in a break.
@brief Given board state mark all squares that the piece is capable of moving to . @param board Square * [] [] Array of Square class pointers representing board state . @see Piece :: markDanger @see Board :: p_squares Iterates over the board upwards downwards leftwards and rightwards until another piece or the edge of the board is encountered . Every Square object iterated over is marked . If an enemy piece is encountered the enemy piece ' s location is marked . If a friendly piece is encountered the friendly piece ' s location is not marked . Either case results in a break .
void Rook::markDanger(Square* board[BOARD_SIZE][BOARD_SIZE]) {
    int tmpX = posX; 
    int tmpY = posY;
    Square* cur = board[posY][posX]; 
    Square* tmp; 
    while (tmpY < BOARD_SIZE - 1) { 
        tmpY++;
        tmp = board[tmpY][tmpX];
        if (tmp->hasPiece()) { 
            if (tmp->getPiece()->isWhite != isWhite) {
                tmp->inDangerFrom.insert(cur); 
                break;
            } else { 
                break;
            }
        } else { 
            tmp->inDangerFrom.insert(cur);
        }
    }
    tmpY = posY; 
    while (tmpX > 0) { 
        tmpX--;
        tmp = board[tmpY][tmpX];
        if (tmp->hasPiece()) {
            if (tmp->getPiece()->isWhite != isWhite) {
                tmp->inDangerFrom.insert(cur);
                break;
            } else {
                break;
            }
        } else {
            tmp->inDangerFrom.insert(cur);
        }
    }
    tmpX = posX;
    while (tmpY > 0) { 
        tmpY--;
        tmp = board[tmpY][tmpX];
        if (tmp->hasPiece()) { 
            if (tmp->getPiece()->isWhite != isWhite) {
                tmp->inDangerFrom.insert(cur); 
            }
            break; 
        } else { 
            tmp->inDangerFrom.insert(cur);
        }
    }
    tmpY = posY;
    while (tmpX < BOARD_SIZE - 1) { 
        tmpX++;
        tmp = board[tmpY][tmpX];
        if (tmp->hasPiece()) { 
            if (tmp->getPiece()->isWhite != isWhite) {
                tmp->inDangerFrom.insert(cur); 
                break;
            } else { 
                break;
            }
        } else { 
            tmp->inDangerFrom.insert(cur);
        }
    }
}
void Rook :: markDanger ( Square * board [ BOARD_SIZE ] [ BOARD_SIZE ] ) { int tmpX = posX ; int tmpY = posY ; Square * cur = board [ posY ] [ posX ] ; Square * tmp ; while ( tmpY < BOARD_SIZE - 1 ) { tmpY ++ ; tmp = board [ tmpY ] [ tmpX ] ; if ( tmp -> hasPiece ( ) ) { if ( tmp -> getPiece ( ) -> isWhite != isWhite ) { tmp -> inDangerFrom . insert ( cur ) ; break ; } else { break ; } } else { tmp -> inDangerFrom . insert ( cur ) ; } } tmpY = posY ; while ( tmpX > 0 ) { tmpX -- ; tmp = board [ tmpY ] [ tmpX ] ; if ( tmp -> hasPiece ( ) ) { if ( tmp -> getPiece ( ) -> isWhite != isWhite ) { tmp -> inDangerFrom . insert ( cur ) ; break ; } else { break ; } } else { tmp -> inDangerFrom . insert ( cur ) ; } } tmpX = posX ; while ( tmpY > 0 ) { tmpY -- ; tmp = board [ tmpY ] [ tmpX ] ; if ( tmp -> hasPiece ( ) ) { if ( tmp -> getPiece ( ) -> isWhite != isWhite ) { tmp -> inDangerFrom . insert ( cur ) ; } break ; } else { tmp -> inDangerFrom . insert ( cur ) ; } } tmpY = posY ; while ( tmpX < BOARD_SIZE - 1 ) { tmpX ++ ; tmp = board [ tmpY ] [ tmpX ] ; if ( tmp -> hasPiece ( ) ) { if ( tmp -> getPiece ( ) -> isWhite != isWhite ) { tmp -> inDangerFrom . insert ( cur ) ; break ; } else { break ; } } else { tmp -> inDangerFrom . insert ( cur ) ; } } }
@brief Given board state, mark all squares that the piece is capable of moving to.
@brief Given board state mark all squares that the piece is capable of moving to .
// Used to store position of Square being iterated over // Square piece is on // Square under inspection // Iterates upwards // If piece encountered // If enemy piece, mark Square as in danger and break // Mark square as in danger from cur // If not enemy piece, break // If no piece encountered, mark square as in danger from cur and continue. // Reset tmpY // Iterate leftwards // Iterate downwards // If piece encountered // If enemy piece, mark square as in danger // Mark square as in danger from cur // Stop iteration // If no piece encountered, mark square as in danger from cur and continue. // Iterate rightwards // If piece encountered // If enemy piece, mark Square as in danger and break // Mark square as in danger from cur // If not enemy piece, break // If no piece encountered, mark square as in danger from cur and continue.