Search in sources :

Example 1 with Move

use of ww.sim.Move in project cg by nmahoude.

the class Player method think.

public static Move think(Simulation sim) {
    Move bestMove = new Move(null);
    double bestScore = Double.NEGATIVE_INFINITY;
    for (int i = 0; i < 2; i++) {
        Agent agent = state.agents[i];
        Move move = new Move(agent);
        for (Dir dir1 : Dir.getValues()) {
            for (Dir dir2 : Dir.getValues()) {
                move.dir1 = dir1;
                move.dir2 = dir2;
                sim.simulate(0, move);
                if (move.isValid()) {
                    double score = AgentEvaluator.score(state);
                    System.err.println("" + move.toPlayerOutput() + " = " + score);
                    if (score > bestScore) {
                        bestScore = score;
                        move.copyTo(state, bestMove);
                    }
                    sim.undo(0, move);
                }
            }
        }
    }
    return bestMove;
}
Also used : Move(ww.sim.Move)

Example 2 with Move

use of ww.sim.Move in project cg by nmahoude.

the class EvalTest method dontBlockOurself.

/**
 * why ? agent 1 choose to go NE and trapped itself for 1 point
 */
@Test
public void dontBlockOurself() {
    state.size = 7;
    TU.setAgent(state, 0, 5, 3);
    TU.setAgent(state, 1, 2, 1);
    TU.setAgent(state, 2, -1, -1);
    TU.setAgent(state, 3, -1, -1);
    TU.setHeights(state, "...3...", "..344..", ".24444.", "0004434", ".00344.", "..013..", "...2...");
    Move moveShouldBeBetter = TU.getMove(1, Dir.SW, Dir.NE);
    simulation.simulate(moveShouldBeBetter, state);
    assertThat(moveShouldBeBetter.isValid(), is(true));
    double score1 = eval.calculateScore(state, moveShouldBeBetter);
    eval.debug("Go back a lvl, but don't trapp");
    state.restore();
    Move initialMove = TU.getMove(1, Dir.NE, Dir.SW);
    simulation.simulate(initialMove, state);
    assertThat(initialMove.isValid(), is(true));
    double score2 = eval.calculateScore(state, initialMove);
    eval.debug("it's a trap");
    assertThat(score1 > score2, is(true));
}
Also used : Move(ww.sim.Move) Test(org.junit.Test)

Example 3 with Move

use of ww.sim.Move in project cg by nmahoude.

the class EvalTest method gettingOurselfIsBadBad.

@Test
@Ignore
public void gettingOurselfIsBadBad() {
    state.size = 5;
    TU.setAgent(state, 0, 4, 3);
    TU.setAgent(state, 1, 4, 1);
    TU.setAgent(state, 2, -1, -1);
    TU.setAgent(state, 3, -1, -1);
    TU.setHeights(state, "00044", "00143", "11243", "03343", "00101");
    Move move = TU.getMove(0, Dir.N, Dir.S);
    simulation.simulate(move, state);
    assertThat(move.isValid(), is(true));
    double score = eval.calculateScore(state, move);
    assertThat(score < 1000, is(true));
}
Also used : Move(ww.sim.Move) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with Move

use of ww.sim.Move in project cg by nmahoude.

the class NodeV2Test method dontGoNearAnEnemyAndACliff.

@Test
public void dontGoNearAnEnemyAndACliff() {
    state.size = 5;
    TU.setAgent(state, 0, 3, 3);
    TU.setAgent(state, 1, 2, 2);
    TU.setAgent(state, 2, 3, 1);
    TU.setAgent(state, 3, -1, -1);
    TU.setHeights(state, "00133", "01333", "01343", "00300", "00000");
    Move move = TU.getMove(1, Dir.N, Dir.SW);
    simulation.simulate(move, state);
    Eval eval = new Eval();
    Agent toCheck = state.agents[1];
    Dir oppWall = Dir.NW;
    int tx = toCheck.x + oppWall.dx;
    int ty = toCheck.y + oppWall.dy;
    int x = toCheck.x;
    int y = toCheck.y;
    int currentHeight = state.getHeight(x, y);
    toCheck.x = tx;
    toCheck.y = ty;
    state.setHeight(x, y, currentHeight + 1);
    double score = eval.calculateScore(state, move);
}
Also used : Move(ww.sim.Move) Test(org.junit.Test)

Example 5 with Move

use of ww.sim.Move in project cg by nmahoude.

the class NodeV2Test method dontGoInADangerousPosition.

@Test
public void dontGoInADangerousPosition() {
    state.size = 6;
    TU.setAgent(state, 0, 5, 3);
    TU.setAgent(state, 1, 1, 3);
    TU.setAgent(state, 2, -1, -1);
    TU.setAgent(state, 3, 5, 2);
    TU.setHeights(state, "033344", "334444", "333343", "334440", "413334", "403334");
    Move move = TU.getMove(1, Dir.SE, Dir.W);
    Simulation simulation = new Simulation();
    simulation.simulate(move, state);
    NodeV2 node = new NodeV2();
    node.state = state;
    int potentialBlocked = node.checkAgentPotentiallyBlocked();
    assertThat(potentialBlocked, is(2));
}
Also used : Simulation(ww.sim.Simulation) Move(ww.sim.Move) Test(org.junit.Test)

Aggregations

Move (ww.sim.Move)40 Test (org.junit.Test)27 GameState (ww.GameState)10 Scanner (java.util.Scanner)8 Dir (ww.Dir)4 Ignore (org.junit.Ignore)3 Simulation (ww.sim.Simulation)3 NodePOC (ww.think.NodePOC)3 ArrayList (java.util.ArrayList)2 Think (ww.think.Think)2 HashSet (java.util.HashSet)1 Cell (ww.Cell)1 Point (ww.Point)1 Oracle (ww.prediction.Oracle)1