示例#1
0
unsigned short int reverse::next_action ( wall &maze_memorizer, route &route_memorizer,
                                          unsigned short int position[], unsigned short int direction, wall &virtual_walls ) {
  unsigned short int succeeded_virtual_foolish_solution;
  if ( route_memorizer.signed_crossroad( position ) ) {
    virtual_walls.update( position, direction, DOWN, UNSAFE );
    if ( maze_memorizer.safe_to_go( position, direction, LEFT ) && virtual_walls.safe_to_go( position, direction, LEFT ) ) {
      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.need_to_scan( virtual_position ) ) {
        succeeded_virtual_foolish_solution =
          route_memorizer.virtual_foolish_solution( maze_memorizer, virtual_position, virtual_direction, position );
        route_memorizer.update_status( virtual_position, virtual_direction, TURN_L_90 );
        if ( virtual_direction == direction && succeeded_virtual_foolish_solution ) {
          virtual_walls.update( virtual_position, virtual_direction, LEFT, UNSAFE );
        }
        else {
          is_done = 1;
          return GO_LEFTWARD;
        }
      }
      else {
        route_memorizer.update_visited_places( virtual_position );
        route_memorizer.update_for_virtual_walls( virtual_position, virtual_direction, maze_memorizer, virtual_walls );
        virtual_walls.update( position, direction, LEFT, UNSAFE );
      }
    }
    if ( route_memorizer.signed_crossroad( position ) &&
         maze_memorizer.safe_to_go( position, direction, UP ) && virtual_walls.safe_to_go( position, direction, UP ) ) {
      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_FORWARD );
      if ( maze_memorizer.need_to_scan( virtual_position ) ) {
        succeeded_virtual_foolish_solution =
          route_memorizer.virtual_foolish_solution( maze_memorizer, virtual_position, virtual_direction, position );
        route_memorizer.update_status( virtual_position, virtual_direction, TURN );
        if ( virtual_direction == direction && succeeded_virtual_foolish_solution ) {
          virtual_walls.update( virtual_position, virtual_direction, UP, UNSAFE );
        }
        else {
          is_done = 1;
          return GO_FORWARD;
        }
      }
      else {
        route_memorizer.update_visited_places( virtual_position );
        route_memorizer.update_for_virtual_walls( virtual_position, virtual_direction, maze_memorizer, virtual_walls );
        virtual_walls.update( position, direction, UP, UNSAFE );
      }
    }
    if ( route_memorizer.signed_crossroad( position ) &&
         maze_memorizer.safe_to_go( position, direction, RIGHT ) && virtual_walls.safe_to_go( position, direction, RIGHT ) ) {
      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_RIGHTWARD );
      if ( maze_memorizer.need_to_scan( virtual_position ) ) {
        succeeded_virtual_foolish_solution =
          route_memorizer.virtual_foolish_solution( maze_memorizer, virtual_position, virtual_direction, position );
        route_memorizer.update_status( virtual_position, virtual_direction, TURN_R_90 );
        if ( virtual_direction == direction && succeeded_virtual_foolish_solution ) {
          virtual_walls.update( virtual_position, virtual_direction, RIGHT, UNSAFE );
        }
        else {
          is_done = 1;
          return GO_RIGHTWARD;
        }
      }
      else {
        route_memorizer.update_visited_places( virtual_position );
        route_memorizer.update_for_virtual_walls( virtual_position, virtual_direction, maze_memorizer, virtual_walls );
        virtual_walls.update( position, direction, RIGHT, UNSAFE );
      }
    }
  }
  if ( maze_memorizer.safe_to_go( position, direction, LEFT ) && virtual_walls.safe_to_go( position, direction, LEFT ) ) {
    return GO_LEFTWARD;
  }
  else if ( maze_memorizer.safe_to_go( position, direction, UP ) && virtual_walls.safe_to_go( position, direction, UP ) ) {
    return GO_FORWARD;
  }
  else if ( maze_memorizer.safe_to_go( position, direction, RIGHT ) && virtual_walls.safe_to_go( position, direction, RIGHT ) ) {
    return GO_RIGHTWARD;
  }
  return DUMMY;
}
示例#2
0
unsigned short int normal::next_action ( wall &maze_memorizer, route &route_memorizer,
                                         unsigned short int position[], unsigned short int direction, wall &virtual_walls ) {
  unsigned short int the_count_of_safe_to_go_blocks;
  unsigned short int succeeded_virtual_foolish_solution;
  if ( maze_memorizer.need_to_scan( position ) ) {
    return SCAN;
  }
  else {
    route_memorizer.update_for_virtual_walls( position, direction, maze_memorizer, virtual_walls );
    the_count_of_safe_to_go_blocks =
      maze_memorizer.the_count_of_safe_to_go_blocks(position,direction) - virtual_walls.the_count_of_unsafe_to_go_blocks(position,direction);
    if ( the_count_of_safe_to_go_blocks ) {
      if ( maze_memorizer.safe_to_go( position, direction, LEFT ) && virtual_walls.safe_to_go( position, direction, LEFT ) ) {
        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.need_to_scan( virtual_position ) ) {
          if ( the_count_of_safe_to_go_blocks > 1 ) {
            succeeded_virtual_foolish_solution =
              route_memorizer.virtual_foolish_solution( maze_memorizer, virtual_position, virtual_direction, position );
            route_memorizer.update_status( virtual_position, virtual_direction, TURN_L_90 );
            if ( virtual_direction == direction && succeeded_virtual_foolish_solution ) {
              the_count_of_safe_to_go_blocks--;
              virtual_walls.update( virtual_position, virtual_direction, LEFT, UNSAFE );
            }
            else {
              route_memorizer.set_the_count_of_facing_unvisited_blocks( position, the_count_of_safe_to_go_blocks - 1 );
              return GO_LEFTWARD;
            }
          }
          else {
            route_memorizer.set_the_count_of_facing_unvisited_blocks( position, the_count_of_safe_to_go_blocks - 1 );
            return GO_LEFTWARD;
          }
        }
        else {
          the_count_of_safe_to_go_blocks--;
          route_memorizer.update_visited_places( virtual_position );
          route_memorizer.update_for_virtual_walls( position, direction, maze_memorizer, virtual_walls );
          virtual_walls.update( position, direction, LEFT, UNSAFE );
        }
      }
      if ( maze_memorizer.safe_to_go( position, direction, UP ) && virtual_walls.safe_to_go( position, direction, UP ) ) {
        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.need_to_scan( virtual_position ) ) {
          if ( the_count_of_safe_to_go_blocks > 1 ) {
            succeeded_virtual_foolish_solution =
              route_memorizer.virtual_foolish_solution( maze_memorizer, virtual_position, virtual_direction, position );
            route_memorizer.update_status( virtual_position, virtual_direction, TURN );
            if ( virtual_direction == direction && succeeded_virtual_foolish_solution ) {
              the_count_of_safe_to_go_blocks--;
              virtual_walls.update( virtual_position, virtual_direction, UP, UNSAFE );
            }
            else {
              route_memorizer.set_the_count_of_facing_unvisited_blocks( position, the_count_of_safe_to_go_blocks - 1 );
              return GO_FORWARD;
            }
          }
          else {
            route_memorizer.set_the_count_of_facing_unvisited_blocks( position, the_count_of_safe_to_go_blocks - 1 );
            return GO_FORWARD;
          }
        }
        else {
          the_count_of_safe_to_go_blocks--;
          route_memorizer.update_visited_places( virtual_position );
          route_memorizer.update_for_virtual_walls( position, direction, maze_memorizer, virtual_walls );
          virtual_walls.update( position, direction, UP, UNSAFE );
        }
      }
      if ( maze_memorizer.safe_to_go( position, direction, RIGHT ) && virtual_walls.safe_to_go( position, direction, RIGHT ) ) {
        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.need_to_scan( virtual_position ) ) {
          if ( the_count_of_safe_to_go_blocks > 1 ) {
            succeeded_virtual_foolish_solution =
              route_memorizer.virtual_foolish_solution( maze_memorizer, virtual_position, virtual_direction, position );
            route_memorizer.update_status( virtual_position, virtual_direction, TURN_R_90 );
            if ( virtual_direction == direction && succeeded_virtual_foolish_solution ) {
              the_count_of_safe_to_go_blocks--;
              virtual_walls.update( virtual_position, virtual_direction, RIGHT, UNSAFE );
            }
            else {
              route_memorizer.set_the_count_of_facing_unvisited_blocks( position, the_count_of_safe_to_go_blocks - 1 );
              return GO_RIGHTWARD;
            }
          }
          else {
            route_memorizer.set_the_count_of_facing_unvisited_blocks( position, the_count_of_safe_to_go_blocks - 1 );
            return GO_RIGHTWARD;
          }
        }
        else {
          the_count_of_safe_to_go_blocks--;
          route_memorizer.update_visited_places( virtual_position );
          route_memorizer.update_for_virtual_walls( position, direction, maze_memorizer, virtual_walls );
          virtual_walls.update( position, direction, RIGHT, UNSAFE );
        }
      }
    }
    is_done = 1;
    return DUMMY;
  }
}