コード例 #1
0
  public GameMove getMove(GameState state, String lastMove) {
    DomineeringState board = (DomineeringState) state;
    homeSym = board.homeSym;
    awaySym = board.awaySym;
    emptySym = board.emptySym;
    isHome = state.who == GameState.Who.HOME; // HOME: true, AWAY: false

    if (isHome) {
      MAX_DEPTH = 6;
      if (board.numMoves >= 6) MAX_DEPTH = 8;
      if (board.numMoves >= 12) MAX_DEPTH = 10;
      if (board.numMoves >= 14) MAX_DEPTH = 12;
    } else {
      MAX_DEPTH = 7;
      if (board.numMoves >= 6) MAX_DEPTH = 9;
      if (board.numMoves >= 12) MAX_DEPTH = 11;
      if (board.numMoves >= 14) MAX_DEPTH = 13;
    }

    Move[] stack = new Move[MAX_DEPTH + 1];
    init(stack);

    if (isHome == true) {
      if (board.numMoves == 0) {
        Move[] temp = new Move[4];
        temp[0] = new Move(1, 2, 1, 3);
        temp[1] = new Move(1, 4, 1, 5);
        temp[2] = new Move(6, 2, 6, 3);
        temp[3] = new Move(6, 4, 6, 5);
        Random rnd = new Random();
        return temp[rnd.nextInt(4)];
      } else if (board.numMoves == 2) {
        Map map = new HashMap();
        Scanner sc;
        try {
          sc = new Scanner(new File("home3.txt"));
          while (sc.hasNextLine()) {
            String s = sc.nextLine();
            String[] sp = s.split("\\s+");
            long key = Long.parseLong(sp[0]);
            Move value =
                new Move(
                    Integer.parseInt(sp[1]),
                    Integer.parseInt(sp[2]),
                    Integer.parseInt(sp[3]),
                    Integer.parseInt(sp[4]));
            map.put(key, value);
          }
          long hash = new Board(board.board, isHome, "alphabetatt").getHashKey();
          Move rtn = (Move) map.get(hash);
          if (rtn != null) return rtn;
        } catch (FileNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    } else {
      if (board.numMoves == 1) {
        Map map = new HashMap();
        Scanner sc;
        try {
          sc = new Scanner(new File("away2.txt"));
          while (sc.hasNextLine()) {
            String s = sc.nextLine();
            String[] sp = s.split("\\s+");
            long key = Long.parseLong(sp[0]);
            Move value =
                new Move(
                    Integer.parseInt(sp[1]),
                    Integer.parseInt(sp[2]),
                    Integer.parseInt(sp[3]),
                    Integer.parseInt(sp[4]));
            map.put(key, value);
          }
          long hash = new Board(board.board, isHome, "alphabetatt").getHashKey();
          Move rtn = (Move) map.get(hash);
          if (rtn != null) return rtn;
        } catch (FileNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    }

    long start = System.currentTimeMillis();
    alphabetaTT(board.board, 0, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, isHome, stack);
    long end = System.currentTimeMillis();

    total += (end - start);
    System.out.printf(
        "%s %3d Time: %-4d Total:%d\n", stack[0], (int) stack[0].score, (end - start), total);
    tt.print();

    System.out.println("Move: " + board.numMoves);

    return stack[0];
  }