Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int distanceRBQtoKing(const Scene *const s, const PlayerColor me)
- {
- const PlayerColor opponent = opponentColor(me);
- const ChessPiece * const myObjects = s -> getPieces(me);
- const ChessPiece *const oppKing = s -> getKing(opponent);
- int kx = oppKing->getX();
- int ky = oppKing->getY();
- int score = 0;
- for(int i=0; i<16; i++) {
- if (!myObjects[i].getAlive())
- continue;
- const ChessPieceType cpt = myObjects[i].getType();
- const int x = myObjects[i].getX();
- const int y = myObjects[i].getY();
- if (cpt == ROOK || cpt == QUEEN) {
- int dx = abs(x - kx);
- int dy = abs(y - ky);
- if ((dy == 0 && dx <= 2) || (dx == 0 && dy <=2 ))
- score += 5;
- }
- if (cpt == BISHOP || cpt == QUEEN) {
- int dx = abs(x - kx);
- int dy = abs(y - ky);
- if (dx <= 2 && dy <= 2 && dx == dy)
- score += 5;
- }
- }
- return score;
- }
Advertisement
Add Comment
Please, Sign In to add comment