jdb
Forum Guru
Arimaa player #214
Gender:
Posts: 682
|
|
Evaluation of Goal Threats
« on: Nov 26th, 2011, 12:50pm » |
Quote Modify
|
There was some talk in the chatroom archives about evaluating goal threats. Clueless analyzes each of the goal squares on the board. It estimates the number of steps required to goal on that square. It counts the number of steps required to clear the goal square (ie c8 ) and the gmt square (ie c7 ). It also counts the number of steps to the nearest rabbit. Code: /** * Creates a lower bound estimate for the number of steps required to goal * on a certain goal square. This lower bound is exact. It is impossible to goal * in fewer steps, but of course it may require more steps. * @param gs * @param goal_index * @return */ public int get_estimate(GameState gs, int goal_index) { assert (goal_index >= 0 && goal_index <= 63); assert (goal_index <= 7 || goal_index >= 56); int player = (goal_index < 8) ? 1 : 0; int enemy = player ^ 0x01; long enemy_bb = gs.colour_bb[enemy]; // all enemy pieces long player_bb = gs.colour_bb[player]; // all player pieces long empty_bb = gs.empty_bb; long goal_bb = TestForGoal.goal_pattern_bb[goal_index][0]; long touch_goal_bb = TestForGoal.goal_pattern_bb[goal_index][2]; long player_rabbit_bb = gs.piece_bb[player]; long gmt_bb = TestForGoal.goal_pattern_bb[goal_index][4]; long player_nr_bb = player_bb & ~player_rabbit_bb; long touch_gmt_bb = TestForGoal.goal_pattern_bb[goal_index][5]; long three_step_bb = TestForGoal.goal_pattern_bb[goal_index][8]; long goal_and_gmt_bb = TestForGoal.goal_pattern_bb[goal_index][9]; int steps_required = 0; // Holds estimate of steps required to goal long stronger_player_bb = player_bb; // Strong enough to clear goal and gmt square // Analyze goal square if ( goal_bb != 0 ) { if ( (goal_bb & player_nr_bb) != 0 ) { steps_required++; } if ( (goal_bb & enemy_bb) != 0 ) { steps_required+=2; // Only keep stronger player pieces int pt = gs.getPieceType(goal_bb,enemy); stronger_player_bb &= gs.stronger_enemy_bb[pt]; } } // Analyze gmt square if ( gmt_bb != 0 ) { if ( (gmt_bb & player_nr_bb) != 0 ) { steps_required++; } if ( (gmt_bb & enemy_bb) != 0 ) { steps_required+=2; // Only keep stronger player pieces int pt = gs.getPieceType(gmt_bb,enemy); stronger_player_bb &= gs.stronger_enemy_bb[pt]; } } // Locate closest piece strong enough to clear goal and gmt square if ( stronger_player_bb == 0 ) { return 9999; } long reach_bb = stronger_player_bb; long target_bb = goal_and_gmt_bb & enemy_bb; int piece_steps = 0; if ( target_bb != 0 ) { while (piece_steps < 10) { reach_bb |= touching_bb(reach_bb); if ( (reach_bb & target_bb) != 0) { break; } piece_steps++; } } steps_required += piece_steps; // Locate closest rabbit reach_bb = player_rabbit_bb; int rabbit_steps = 1; while ( rabbit_steps<10 ) { reach_bb |= touching_bb(reach_bb); if ( (reach_bb & goal_bb) != 0 ) { break; } rabbit_steps++; } steps_required+=rabbit_steps; return steps_required; } |
|
|