Untitled

mail@pastecode.io avatar
unknown
c_cpp
a year ago
2.2 kB
2
Indexable
Never
int State::evaluate(){
  // [TODO] design your own evaluation function
  auto first_board = this->board.board[0];
  auto second_board = this->board.board[1];
  int now_value = 0, oppn_value = 0;
  int now_piece, oppn_piece;
  for(int i = 0; i < BOARD_H; i++){
    for(int j = 0; j < BOARD_W; j++){
      if((now_piece = first_board[i][j])){
        switch (now_piece){
          case 1: //pawn
            if(i == 4){
              now_value += 4;
            }
            now_value += 1;
            break;
          case 2: //rook
            now_value += 5;
            break;
          case 3: //knight
            now_value += 3;
            break;
          case 4: //bishop
            now_value += 3;
            break;
          case 5: //queen
            now_value += 9;
            break;
          case 6: //king
            now_value += 15;
            break;
          default:
            break;
        }
        if(i == 0 || i == BOARD_H - 1 || j == 0 || j == BOARD_W - 1)
          now_value -= 2;
        if(i == 1 || i == BOARD_W - 2 || j == 1 || j == BOARD_W - 1)
          now_value -= 1;
      }
    }
  }
  for(int i = 0; i < BOARD_H; i++){
    for(int j = 0; j < BOARD_W; j++){
      if((oppn_piece = second_board[i][j])){
        // std::cout << this->player << "," << now_piece << ' ';
        switch (oppn_piece){
          case 1: //pawn
            if(i == 1){
              now_value -= 4;
            }
            oppn_value -= 1;
            break;
          case 2: //rook
            oppn_value -= 5;
            break;
          case 3: //knight
            oppn_value -= 3;
            break;
          case 4: //bishop
            oppn_value -= 3;
            break;
          case 5: //queen 
            oppn_value -= 9;
            break;
          case 6: //king
            oppn_value -= 15;
            break;
        }
        if(i == 0 || i == BOARD_H - 1 || j == 0 || j == BOARD_W - 1)
          oppn_value += 2;
        if(i == 1 || i == BOARD_W - 2 || j == 1 || j == BOARD_W - 1)
          oppn_value += 1;
      }
    }
  }
  return now_value - oppn_value;
}