コード例 #1
0
ファイル: Reverse.cpp プロジェクト: harubot/micromouse
void reverse::map_potentials( wall &maze_memorizer, route &route_memorizer,
                              unsigned short int position[], unsigned short int &direction,
                              unsigned short int starting_position[], unsigned short int starting_direction,
                              unsigned short int aimed_position[], unsigned short int aimed_direction ) {
  unsigned short int next_action = DUMMY;
  unsigned short int potential_to_set = 0;
  if ( position[0] == starting_position[0] && position[1] == starting_position[1] ) {
    if ( direction == starting_direction ) {
      route_memorizer.has_potential_map = 1;
      route_memorizer.solve_the_maze( maze_memorizer, starting_position, starting_direction, aimed_position, aimed_direction );
      route_memorizer.reset();
      is_done = 1;
    }
    else {
      if ( maze_memorizer.safe_to_go( position, direction, LEFT ) ) {
        next_action = GO_LEFTWARD;
      }
      else if ( maze_memorizer.safe_to_go( position, direction, UP ) ) {
        next_action = GO_FORWARD;
      }
      else if ( maze_memorizer.safe_to_go( position, direction, RIGHT ) ) {
        next_action = GO_RIGHTWARD;
      }
      route_memorizer.update_status( position, direction, next_action );
      if ( direction == starting_direction ) {
        potential_to_set = route_memorizer.s;
      }
      else {
        potential_to_set = route_memorizer.t;
      }
      route_memorizer.put_a_sign_to_reverse( position, direction );
      route_memorizer.set_potential( position, potential_to_set );
      route_memorizer.update_visited_places( position );
      is_done = 1;      
    }
  }
  else {
    if ( route_memorizer.signed_crossroad( position ) ) {
      route_memorizer.decrement_the_count_of_facing_unvisited_blocks( position );
      virtual_position[0] = position[0];
      virtual_position[1] = position[1];
      virtual_direction = direction;
      route_memorizer.update_status( virtual_position, virtual_direction, GO_LEFTWARD );
      if ( maze_memorizer.safe_to_go( position, direction, LEFT ) &&
           !(virtual_position[0] == starting_position[0] && virtual_position[1] == starting_position[1]) ) {
        if ( route_memorizer.signed_crossroad( position ) ) {
          next_action = GO_LEFTWARD;
          potential_to_set = route_memorizer.get_potential( position ) + route_memorizer.s;
        }
        else if ( route_memorizer.visited( position, direction, LEFT ) ) {
          if ( route_memorizer.get_potential( position, direction, LEFT ) > route_memorizer.get_potential( position ) + route_memorizer.s ) {
            next_action = GO_LEFTWARD;
            if ( maze_memorizer.safe_to_go( position, direction, RIGHT ) ) {
              if ( route_memorizer.get_potential( position ) > route_memorizer.get_potential( position, direction, RIGHT ) ) {
                potential_to_set = route_memorizer.get_potential( position ) + route_memorizer.s;
              }
              else {
                potential_to_set = route_memorizer.get_potential( position ) + route_memorizer.t;
              }
            }
            else {
              potential_to_set = route_memorizer.get_potential( position ) + route_memorizer.t;
            }
          }
        }
        else {
          next_action = GO_LEFTWARD;
          if ( maze_memorizer.safe_to_go( position, direction, RIGHT ) ) {
            if ( route_memorizer.get_potential( position ) > route_memorizer.get_potential( position, direction, RIGHT ) ) {
              potential_to_set = route_memorizer.get_potential( position ) + route_memorizer.s;
            }
            else {
              potential_to_set = route_memorizer.get_potential( position ) + route_memorizer.t;
            }
          }
          else {
            potential_to_set = route_memorizer.get_potential( position ) + route_memorizer.t;
          }
        }
      }
      if ( next_action == DUMMY ) {
        next_action = GO_FORWARD;
        potential_to_set = route_memorizer.get_potential( position ) + route_memorizer.t;
      }
      route_memorizer.update_status( position, direction, next_action );
      route_memorizer.put_a_sign_to_reverse( position, direction );
      route_memorizer.set_potential( position, potential_to_set );
      route_memorizer.update_visited_places( position );
      is_done = 1;
    }
    else {
      next_action = route_memorizer.get_the_direction_to_reverse( position, direction );
      route_memorizer.remove_a_sign_to_reverse( position );
      route_memorizer.update_status( position, direction, next_action );
    }
  }
}
コード例 #2
0
ファイル: Normal.cpp プロジェクト: harubot/micromouse
void normal::map_potentials( wall &maze_memorizer, route &route_memorizer,
                             unsigned short int position[], unsigned short int &direction,
                             unsigned short int starting_position[], unsigned short int starting_direction,
                             unsigned short int aimed_position[], unsigned short int aimed_direction ) {
  unsigned short int next_action = DUMMY;
  unsigned short int the_count_of_facing_unvisited_blocks = 0; //precisely wrong name
  unsigned short int potential_to_set = 0;
  virtual_position[0] = position[0];
  virtual_position[1] = position[1];
  virtual_direction = direction;
  route_memorizer.update_status( virtual_position, virtual_direction, GO_LEFTWARD );
  if ( maze_memorizer.safe_to_go( position, direction, LEFT ) &&
       !(virtual_position[0] == starting_position[0] && virtual_position[1] == starting_position[1]) ) {
    if ( route_memorizer.visited( position, direction, LEFT ) ) {
      if ( route_memorizer.get_potential( position, direction, LEFT ) > route_memorizer.get_potential( position ) + route_memorizer.t ) {
        the_count_of_facing_unvisited_blocks++;
        next_action = GO_LEFTWARD;
        potential_to_set = route_memorizer.get_potential( position ) + route_memorizer.t;
      }
    }
    else {
      the_count_of_facing_unvisited_blocks++;
      next_action = GO_LEFTWARD;
      potential_to_set = route_memorizer.get_potential( position ) + route_memorizer.t;
    }
  }
  virtual_position[0] = position[0];
  virtual_position[1] = position[1];
  virtual_direction = direction;
  route_memorizer.update_status( virtual_position, virtual_direction, GO_FORWARD );
  if ( maze_memorizer.safe_to_go( position, direction, UP ) &&
       !(virtual_position[0] == starting_position[0] && virtual_position[1] == starting_position[1]) ) {
    if ( route_memorizer.visited( position, direction, UP ) ) {
      if ( route_memorizer.get_potential( position, direction, UP ) > route_memorizer.get_potential( position ) + route_memorizer.s ) {
        the_count_of_facing_unvisited_blocks++;
        if ( next_action == DUMMY ) {
          next_action = GO_FORWARD;
          potential_to_set = route_memorizer.get_potential( position ) + route_memorizer.s;
        }
      }
    }
    else {
      the_count_of_facing_unvisited_blocks++;
      if ( next_action == DUMMY ) {
        next_action = GO_FORWARD;
        potential_to_set = route_memorizer.get_potential( position ) + route_memorizer.s;
      }
    }
  }
  virtual_position[0] = position[0];
  virtual_position[1] = position[1];
  virtual_direction = direction;
  route_memorizer.update_status( virtual_position, virtual_direction, GO_RIGHTWARD );
  if ( maze_memorizer.safe_to_go( position, direction, RIGHT ) &&
       !(virtual_position[0] == starting_position[0] && virtual_position[1] == starting_position[1]) ) {
    if ( route_memorizer.visited( position, direction, RIGHT ) ) {
      if ( route_memorizer.get_potential( position, direction, RIGHT ) > route_memorizer.get_potential( position ) + route_memorizer.t ) {
        the_count_of_facing_unvisited_blocks++;
        if ( next_action == DUMMY ) {
          next_action = GO_RIGHTWARD;
          potential_to_set = route_memorizer.get_potential( position ) + route_memorizer.t;
        }
      }
    }
    else {
      the_count_of_facing_unvisited_blocks++;
      if ( next_action == DUMMY ) {
        next_action = GO_RIGHTWARD;
        potential_to_set = route_memorizer.get_potential( position ) + route_memorizer.t;
      }
    }
  }
  if ( next_action != DUMMY ) {
    route_memorizer.set_the_count_of_facing_unvisited_blocks( position, the_count_of_facing_unvisited_blocks - 1 );
    route_memorizer.update_status( position, direction, next_action );
    route_memorizer.put_a_sign_to_reverse( position, direction );
    route_memorizer.update_visited_places( position );
    route_memorizer.set_potential( position, potential_to_set );
  }
  else {
    if ( position[0] == starting_position[0] && position[1] == starting_position[1] ) {
      route_memorizer.update_status( position, direction, GO_BACKWARD );
      route_memorizer.put_a_sign_to_reverse( position, direction );
      route_memorizer.update_visited_places( position );
      route_memorizer.set_potential( position, route_memorizer.t );
    }
    else {
      route_memorizer.remove_a_sign_to_reverse( position );
      route_memorizer.update_status( position, direction, GO_BACKWARD );
      is_done = 1;
    }
  }
}