Exemplo n.º 1
0
 /**
  * instantiate a strategy from a config property. requires conf to have already been set (as well
  * as anything the provider might need to read).
  */
 RegionGroupingStrategy getStrategy(
     final Configuration conf, final String key, final String defaultValue) throws IOException {
   Class<? extends RegionGroupingStrategy> clazz;
   try {
     clazz = Strategies.valueOf(conf.get(key, defaultValue)).clazz;
   } catch (IllegalArgumentException exception) {
     // Fall back to them specifying a class name
     // Note that the passed default class shouldn't actually be used, since the above only fails
     // when there is a config value present.
     clazz = conf.getClass(key, IdentityGroupingStrategy.class, RegionGroupingStrategy.class);
   }
   LOG.info("Instantiating RegionGroupingStrategy of type " + clazz);
   try {
     final RegionGroupingStrategy result = clazz.newInstance();
     result.init(conf);
     return result;
   } catch (InstantiationException exception) {
     LOG.error(
         "couldn't set up region grouping strategy, check config key " + REGION_GROUPING_STRATEGY);
     LOG.debug("Exception details for failure to load region grouping strategy.", exception);
     throw new IOException("couldn't set up region grouping strategy", exception);
   } catch (IllegalAccessException exception) {
     LOG.error(
         "couldn't set up region grouping strategy, check config key " + REGION_GROUPING_STRATEGY);
     LOG.debug("Exception details for failure to load region grouping strategy.", exception);
     throw new IOException("couldn't set up region grouping strategy", exception);
   }
 }
Exemplo n.º 2
0
  public static void main(String[] args) {
    if (args.length != 1) {
      System.out.println(
          "Usage: java FoosBasic GAMEID"
              + "\n\tGAMEID = 0    creates a new game"
              + "\n\tGAMEID = WXYZ connect to a specific game");
      return;
    }

    // Connect to a FoosGame with id from the command line
    FoosGame game = new FoosGame(args[0]);

    // Initial roster: select the better ones with high probability
    // TODO: might be more aggressive about this
    myType = Strategies.chooseInitType(GAME_TYPE_RESULT);
    if (v) {
      System.out.println("the type is:" + myType);
      System.out.println("the row assignment is:" + Arrays.toString(Strategies.INIT_TYPES[myType]));
    }
    int[] roster = helper.rowNumToRoster(Strategies.INIT_TYPES[myType]);

    if (v) {
      System.out.println("my roaster: " + Arrays.toString(roster));
    }

    System.out.println("{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{");
    int[] game_state;
    while (true) {
      // Send the roster and get the game state
      game_state = game.make_move(roster);
      if (game_state[2] == 4 * ITER_PER_QUARTER) break;

      // keep track of performance
      if (game_state[0] > teamScore) {
        GAME_TYPE_RESULT[myType] += 1;
      }

      // Use the game state to determine the next move
      if (game_state[2] % ITER_PER_QUARTER == 0)
        roster = helper.rowNumToRoster(Strategies.INIT_TYPES[myType]);
      else roster = new_move(game_state);
    }

    System.out.println("Final Score: " + game_state[0] + " - " + game_state[1]);
    if (game_state[0] > game_state[1]) System.out.println("WIN!");
    if (game_state[0] == game_state[1]) System.out.println("Tie Game");
  }
Exemplo n.º 3
0
 /**
  * Determine a roster for the next round from the current game state. Input: game_state[0]: team
  * score game_state[1]: opponent team score game_state[2]: game round number game_state[3]: row
  * number of the ball game_state[4 ]-[ 29]: team foosplayer row positions game_state[30]-[ 55]:
  * team foosplayer fatigues game_state[56]-[ 81]: opponent foosplayer row positions
  * game_state[81]-[107]: opponent foosplayer fatigues Output: roster[0]-[NUM_FOOSPLAYERS-1]: team
  * foosplayer row positions for next round
  */
 public static int[] new_move(int[] game_state) {
   // Trivial strategy, null move
   return Strategies.movePlayerTowardBall(game_state);
 }