Search in sources :

Example 1 with Think

use of ww.think.Think in project cg by nmahoude.

the class Perf method perf.

@Test
public void perf() {
    state.size = 6;
    state.readInit(new Scanner("" + state.size + " 2"));
    TU.setHeights(state, "344444", "333434", "..34..", ".3..3.", ".0101.", "000002");
    TU.setAgent(state, 0, 1, 3);
    TU.setAgent(state, 1, 1, 1);
    TU.setAgent(state, 2, -1, -1);
    TU.setAgent(state, 3, -1, -1);
    Player.state = state;
    GameState.startTime = System.currentTimeMillis() + 1_000_000;
    state.legalActionDepth0NodeCache.clear();
    for (int i = 0; i < 2; i++) {
        for (Dir dir1 : Dir.getValues()) {
            for (Dir dir2 : Dir.getValues()) {
                Move move = new Move(state.agents[i]);
                move.dir1 = dir1;
                move.dir2 = dir2;
                NodePOC node = new NodePOC(1);
                node.move = move;
                state.legalActionDepth0NodeCache.add(node);
            }
        }
    }
    for (int i = 0; i < 500; i++) {
        new Think(state).think(3);
    }
}
Also used : Scanner(java.util.Scanner) NodePOC(ww.think.NodePOC) Think(ww.think.Think) Move(ww.sim.Move) Dir(ww.Dir) Test(org.junit.Test)

Example 2 with Think

use of ww.think.Think in project cg by nmahoude.

the class Player method main.

public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    state.readInit(in);
    int round = 0;
    // game loop
    while (true) {
        round++;
        state.readRound(in);
        if (round > 1) {
            oracle.guessFrom(state);
            // oracle.debug(state);
            oracle.apply(state);
        } else {
            // init the oracle
            oracle = new Oracle(state);
        // oracle.setDebug(true);
        }
        // think(sim);
        Move bestMove = new Move(null);
        // deepening
        // odd deepening only
        int deepening = 1;
        Move move = null;
        int maxDeepening = 1;
        int enemyInSight = state.getEnemyInSight();
        switch(enemyInSight) {
            case 0:
                maxDeepening = 10;
                break;
            case 1:
                maxDeepening = 10;
                break;
            case 2:
                maxDeepening = 10;
                break;
        }
        do {
            move = new Think(state).think(deepening);
            if (move != null && move.agent != null) {
                move.copyTo(state, bestMove);
                System.err.println("AB @ " + deepening + " found bestMove :" + bestMove);
            } else {
                System.err.println("AB curoff at " + deepening);
            }
            if (deepening == 1) {
                // order moves
                state.legalActionDepth0NodeCache.sort(new Comparator<NodePOC>() {

                    @Override
                    public int compare(NodePOC o1, NodePOC o2) {
                        return Double.compare(o2.score, o1.score);
                    }
                });
            // for (Node node : state.legalActionDepth0NodeCache) {
            // System.err.println(""+node.move+" -> "+node.score);
            // }
            }
            deepening += 2;
        } while (move.agent != null && deepening < maxDeepening);
        long endTime = System.currentTimeMillis();
        int depth = deepening / 2;
        if (bestMove != null && bestMove.agent != null) {
            // just before the output, we replay our best move for the divination
            oracle.updatePreviousState(state);
            sim.simulate(0, bestMove);
            // System.err.println("State after last simulation for prediction for move "+bestMove);
            // state.toTDD();
            oracle.updateSimulated(state, bestMove);
            if (DEBUG_SCORING) {
                System.err.println("Evaluation for move : " + bestMove);
                AgentEvaluator.score(state);
            }
            // +" "+depth+" in "+(endTime-GameState.startTime));
            System.out.println(bestMove.toPlayerOutput());
        } else {
            System.out.println("ACCEPT-DEFEAT GOOD FIGHT, GG");
        }
    }
}
Also used : Scanner(java.util.Scanner) Think(ww.think.Think) NodePOC(ww.think.NodePOC) Move(ww.sim.Move) Oracle(ww.prediction.Oracle)

Aggregations

Scanner (java.util.Scanner)2 Move (ww.sim.Move)2 NodePOC (ww.think.NodePOC)2 Think (ww.think.Think)2 Test (org.junit.Test)1 Dir (ww.Dir)1 Oracle (ww.prediction.Oracle)1