flok99

Untitled

May 31st, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. int distanceRBQtoKing(const Scene *const s, const PlayerColor me)
  2. {
  3.         const PlayerColor opponent = opponentColor(me);
  4.         const ChessPiece * const myObjects = s -> getPieces(me);
  5.         const ChessPiece *const oppKing = s -> getKing(opponent);
  6.         int kx = oppKing->getX();
  7.         int ky = oppKing->getY();
  8.  
  9.         int score = 0;
  10.  
  11.         for(int i=0; i<16; i++) {
  12.                 if (!myObjects[i].getAlive())
  13.                         continue;
  14.  
  15.                 const ChessPieceType cpt = myObjects[i].getType();
  16.                 const int x = myObjects[i].getX();
  17.                 const int y = myObjects[i].getY();
  18.  
  19.                 if (cpt == ROOK || cpt == QUEEN) {
  20.                         int dx = abs(x - kx);
  21.                         int dy = abs(y - ky);
  22.  
  23.                         if ((dy == 0 && dx <= 2) || (dx == 0 && dy <=2 ))
  24.                                 score += 5;
  25.                 }
  26.  
  27.                 if (cpt == BISHOP || cpt == QUEEN) {
  28.                         int dx = abs(x - kx);
  29.                         int dy = abs(y - ky);
  30.  
  31.                         if (dx <= 2 && dy <= 2 && dx == dy)
  32.                                 score += 5;
  33.                 }
  34.         }
  35.  
  36.         return score;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment