TorusPredPreyGame { public void advance(int[][] predMoves, int[][] preyMoves) { moveAll(predMoves, preds); moveAll(preyMoves, preys); eat(preds, preys); time++; gameOver = ArrayUtil.countOccurrences(null, preys) == preys.length || time >= timeLimit; } TorusPredPreyGame(int xDim, int yDim, int numPred, int numPrey); TorusWorld getWorld(); TorusAgent[][] getAgents(); TorusAgent[] getPredators(); TorusAgent[] getPrey(); void advance(int[][] predMoves, int[][] preyMoves); int getTime(); int getTimeLimit(); int getDeathTime(int prey); int getPreyCatchesForThisPred(int pred); static final int AGENT_TYPE_PRED; static final int AGENT_TYPE_PREY; }
@Test public void testAdvance() { game1 = new TorusPredPreyGame(100, 100, 3, 2); TorusWorld world = new TorusWorld(100, 100); TorusAgent pred1 = new TorusAgent(world, 0, 0, 0); TorusAgent pred2 = new TorusAgent(world, 0, 0, 0); TorusAgent pred3 = new TorusAgent(world, 0, 0, 0); TorusAgent prey1 = new TorusAgent(world, 0, 0, 1); TorusAgent prey2 = new TorusAgent(world, 0, 0, 1); game1.preds[0] = pred1; game1.preds[1] = pred2; game1.preds[2] = pred3; game1.preys[0] = prey1; game1.preys[1] = prey2; int[] pred1Move = new int[] { 0, 0 }; int[] pred2Move = new int[] { 1, 0 }; int[] pred3Move = new int[] { 1, 1 }; int[] prey1Move = new int[] { 1, 1 }; int[] prey2Move = new int[] { 0, 1 }; int[][] predMoves = new int[][] { pred1Move, pred2Move, pred3Move }; int[][] preyMoves = new int[][] { prey1Move, prey2Move }; assertNotNull(prey1); assertEquals(pred1.getPosition(), new Tuple2D(0, 0)); assertEquals(pred2.getPosition(), new Tuple2D(0, 0)); assertEquals(pred3.getPosition(), new Tuple2D(0, 0)); assertEquals(prey1.getPosition(), new Tuple2D(0, 0)); assertEquals(prey2.getPosition(), new Tuple2D(0, 0)); Tuple2D pred1Pos = pred1.getPosition(); Tuple2D pred2Pos = pred2.getPosition(); Tuple2D pred3Pos = pred3.getPosition(); Tuple2D prey2Pos = prey2.getPosition(); assertEquals(game1.getTime(), 0); game1.advance(predMoves, preyMoves); assertEquals(game1.getTime(), 1); assertEquals(game1.preds[0].getPosition(), pred1Pos.add(new Tuple2D(pred1Move[0], pred1Move[1]))); assertEquals(game1.preds[1].getPosition(), pred2Pos.add(new Tuple2D(pred2Move[0], pred2Move[1]))); assertEquals(game1.preds[2].getPosition(), pred3Pos.add(new Tuple2D(pred3Move[0], pred3Move[1]))); assertNull(game1.preys[0]); assertEquals(game1.preys[1].getPosition(), prey2Pos.add(new Tuple2D(prey2Move[0], prey2Move[1]))); }