Welcome, Guest. Please Login or Register.
Nov 26th, 2024, 4:19pm

Home Home Help Help Search Search Members Members Login Login Register Register
Arimaa Forum « Evaluation of Goal Threats »


   Arimaa Forum
   Arimaa
   Bot Development
(Moderator: supersamu)
   Evaluation of Goal Threats
« Previous topic | Next topic »
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print
   Author  Topic: Evaluation of Goal Threats  (Read 1038 times)
jdb
Forum Guru
*****



Arimaa player #214

   


Gender: male
Posts: 682
Evaluation of Goal Threats
« on: Nov 26th, 2011, 12:50pm »
Quote Quote Modify 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;
  }
 
IP Logged
Swynndla
Forum Guru
*****



Arimaa player #1821

   


Posts: 235
Re: Evaluation of Goal Threats
« Reply #1 on: Nov 26th, 2011, 3:13pm »
Quote Quote Modify Modify

Nice - thank you for sharing!  Cheesy
IP Logged
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print

« Previous topic | Next topic »

Arimaa Forum » Powered by YaBB 1 Gold - SP 1.3.1!
YaBB © 2000-2003. All Rights Reserved.