public City getCityAt(Position p) {
    if (p.getRow() == 1 && p.getColumn() == 1) {
      return new City() {
        public Player getOwner() {
          return Player.RED;
        }

        public int getSize() {
          return 1;
        }

        public String getProduction() {
          return null;
        }

        public String getWorkforceFocus() {
          return null;
        }

        public int getProductionCount() {
          return 0;
        }
      };
    }
    return null;
  }
예제 #2
0
  public City getCityAt(Position p) {
    if (p.getRow() == 1 && p.getColumn() == 1) {
      return new City() {
        public Player getOwner() {
          return Player.RED;
        }

        public int getSize() {
          return 1;
        }

        public String getProduction() {
          return null;
        }

        public String getWorkforceFocus() {
          return null;
        }

        @Override
        public int getTreasure() {
          // TODO Auto-generated method stub
          return 0;
        }
      };
    }
    return null;
  }
예제 #3
0
 public Tile getTileAt(Position p) {
   if (p.getRow() == 0 && p.getColumn() == 0) {
     return new StubTile(GameConstants.FOREST, 0, 0);
   }
   if (p.getRow() == 1 && p.getColumn() == 0) {
     return new StubTile(GameConstants.HILLS, 1, 0);
   }
   return new StubTile(GameConstants.PLAINS, 0, 1);
 }
예제 #4
0
  @Test
  public void testMoveStep() {
    robot = new Robot(new Energy(2400, unitOfPower.Ws), Orientation.RIGHT);
    robot.setPosition(Position.newPosition(3, 4, board));

    Program moveProgram = new Program(move, robot);
    robot.setProgram(moveProgram);

    assertEquals(1, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(5, 4, board).getElements().size());
    assertEquals(Orientation.RIGHT, robot.getOrientation());
    assertEquals(2400, robot.getAmountOfEnergy(), epsilon);

    moveProgram.step();

    assertEquals(0, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(1, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(5, 4, board).getElements().size());
    assertEquals(Orientation.RIGHT, robot.getOrientation());
    assertEquals(1900, robot.getAmountOfEnergy(), epsilon);

    moveProgram.step();
    moveProgram.step();
    moveProgram.step();
    moveProgram.step();
    moveProgram.step();
    moveProgram.step();
    moveProgram.step();
    moveProgram.step();
    moveProgram.step();
    moveProgram.step();

    assertEquals(0, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(1, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(5, 4, board).getElements().size());
    assertEquals(Orientation.RIGHT, robot.getOrientation());
    assertEquals(1900, robot.getAmountOfEnergy(), epsilon);
  }
  /** Test of insert method, of class TranspositionTable. */
  @Test
  public void testInsert() throws ChessParseError {
    System.out.println("insert");
    TranspositionTable tt = new TranspositionTable(16);
    Position pos = TextIO.readFEN(TextIO.startPosFEN);
    String[] moves = {
      "e4", "e5", "Nf3", "Nc6", "Bb5", "a6", "Ba4", "b5", "Bb3", "Nf6", "O-O", "Be7", "Re1"
    };
    UndoInfo ui = new UndoInfo();
    for (int i = 0; i < moves.length; i++) {
      Move m = TextIO.stringToMove(pos, moves[i]);
      pos.makeMove(m, ui);
      int score = i * 17 + 3;
      m.score = score;
      int type = TranspositionTable.TTEntry.T_EXACT;
      int ply = i + 1;
      int depth = i * 2 + 5;
      tt.insert(pos.historyHash(), m, type, ply, depth, score * 2 + 3);
    }

    pos = TextIO.readFEN(TextIO.startPosFEN);
    for (int i = 0; i < moves.length; i++) {
      Move m = TextIO.stringToMove(pos, moves[i]);
      pos.makeMove(m, ui);
      TranspositionTable.TTEntry ent = tt.probe(pos.historyHash());
      assertEquals(TranspositionTable.TTEntry.T_EXACT, ent.type);
      int score = i * 17 + 3;
      int ply = i + 1;
      int depth = i * 2 + 5;
      assertEquals(score, ent.getScore(ply));
      assertEquals(depth, ent.getDepth());
      assertEquals(score * 2 + 3, ent.evalScore);
      Move tmpMove = new Move(0, 0, 0);
      ent.getMove(tmpMove);
      assertEquals(m, tmpMove);
    }
  }
예제 #6
0
 public Unit getUnitAt(Position p) {
   if (p.getRow() == 2 && p.getColumn() == 3
       || p.getRow() == 3 && p.getColumn() == 2
       || p.getRow() == 3 && p.getColumn() == 3) {
     return new StubUnit(GameConstants.ARCHER, Player.RED);
   }
   if (p.getRow() == 4 && p.getColumn() == 4) {
     return new StubUnit(GameConstants.ARCHER, Player.BLUE);
   }
   return null;
 }
예제 #7
0
 @Test
 public void twoEqualPositionsHaveSameHashCode() {
   assertEquals(position.hashCode(), position.clone().hashCode());
 }
예제 #8
0
 @Test
 public void addReturnsExpectedPosition() {
   Position expected = new Position(ROW + 1, COL - 3);
   assertEquals(expected, position.add(new Position(1, -3)));
 }
예제 #9
0
 @Test
 public void addDoesNotAffectOriginalPosition() {
   Position clone = position.clone();
   position.add(new Position(1, -3));
   assertEquals(clone, position);
 }
예제 #10
0
 @Test
 public void clonedPositionNotSame() {
   assertNotSame(position, position.clone());
 }
예제 #11
0
 @Test
 public void clonedPositionIsEqual() {
   assertEquals(position, position.clone());
 }
예제 #12
0
 @Test
 public void getRowAndCol() {
   assertEquals(ROW, position.getRow());
   assertEquals(COL, position.getCol());
 }
예제 #13
0
  @Test
  public void testWhileInSeqStep() {
    robot = new Robot(new Energy(2400, unitOfPower.Ws), Orientation.RIGHT);
    robot.setPosition(Position.newPosition(3, 4, board));

    Program whileInSeqProgram = new Program(whileinseq, robot);
    robot.setProgram(whileInSeqProgram);

    assertEquals(1, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(5, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(6, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(7, 4, board).getElements().size());
    assertEquals(Orientation.RIGHT, robot.getOrientation());
    assertEquals(2400, robot.getAmountOfEnergy(), epsilon);

    whileInSeqProgram.step();

    assertEquals(0, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(1, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(5, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(6, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(7, 4, board).getElements().size());
    assertEquals(Orientation.RIGHT, robot.getOrientation());
    assertEquals(1900, robot.getAmountOfEnergy(), epsilon);

    whileInSeqProgram.step();

    assertEquals(0, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(1, Position.newPosition(5, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(6, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(7, 4, board).getElements().size());
    assertEquals(Orientation.RIGHT, robot.getOrientation());
    assertEquals(1400, robot.getAmountOfEnergy(), epsilon);

    whileInSeqProgram.step();

    assertEquals(0, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(5, 4, board).getElements().size());
    assertEquals(1, Position.newPosition(6, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(7, 4, board).getElements().size());
    assertEquals(Orientation.RIGHT, robot.getOrientation());
    assertEquals(900, robot.getAmountOfEnergy(), epsilon);

    whileInSeqProgram.step();

    assertEquals(0, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(5, 4, board).getElements().size());
    assertEquals(1, Position.newPosition(6, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(7, 4, board).getElements().size());
    assertEquals(Orientation.DOWN, robot.getOrientation());
    assertEquals(800, robot.getAmountOfEnergy(), epsilon);

    whileInSeqProgram.step();

    assertEquals(0, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(5, 4, board).getElements().size());
    assertEquals(1, Position.newPosition(6, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(7, 4, board).getElements().size());
    assertEquals(Orientation.DOWN, robot.getOrientation());
    assertEquals(800, robot.getAmountOfEnergy(), epsilon);

    whileInSeqProgram.step();
    whileInSeqProgram.step();
    whileInSeqProgram.step();
    whileInSeqProgram.step();
    whileInSeqProgram.step();
    whileInSeqProgram.step();
    whileInSeqProgram.step();
    whileInSeqProgram.step();
    whileInSeqProgram.step();
    whileInSeqProgram.step();

    assertEquals(0, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(5, 4, board).getElements().size());
    assertEquals(1, Position.newPosition(6, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(7, 4, board).getElements().size());
    assertEquals(Orientation.DOWN, robot.getOrientation());
    assertEquals(800, robot.getAmountOfEnergy(), epsilon);
  }
예제 #14
0
  @Test
  public void testExampleInOneLineStep() {
    robot = new Robot(new Energy(3900, unitOfPower.Ws), Orientation.RIGHT);
    robot.setPosition(Position.newPosition(3, 4, board));

    Program exampleInOneLineProgram = new Program(example, robot);
    robot.setProgram(exampleInOneLineProgram);

    assertEquals(1, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 5, board).getElements().size());
    assertEquals(0, Position.newPosition(3, 5, board).getElements().size());
    assertEquals(Orientation.RIGHT, robot.getOrientation());
    assertEquals(3900, robot.getAmountOfEnergy(), epsilon);

    exampleInOneLineProgram.step();

    assertEquals(0, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(1, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 5, board).getElements().size());
    assertEquals(0, Position.newPosition(3, 5, board).getElements().size());
    assertEquals(Orientation.RIGHT, robot.getOrientation());
    assertEquals(3400, robot.getAmountOfEnergy(), epsilon);

    exampleInOneLineProgram.step();

    assertEquals(0, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(1, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 5, board).getElements().size());
    assertEquals(0, Position.newPosition(3, 5, board).getElements().size());
    assertEquals(Orientation.DOWN, robot.getOrientation());
    assertEquals(3300, robot.getAmountOfEnergy(), epsilon);

    exampleInOneLineProgram.step();

    assertEquals(0, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(1, Position.newPosition(4, 5, board).getElements().size());
    assertEquals(0, Position.newPosition(3, 5, board).getElements().size());
    assertEquals(Orientation.DOWN, robot.getOrientation());
    assertEquals(2800, robot.getAmountOfEnergy(), epsilon);

    exampleInOneLineProgram.step();

    assertEquals(0, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(1, Position.newPosition(4, 5, board).getElements().size());
    assertEquals(0, Position.newPosition(3, 5, board).getElements().size());
    assertEquals(Orientation.LEFT, robot.getOrientation());
    assertEquals(2700, robot.getAmountOfEnergy(), epsilon);

    exampleInOneLineProgram.step();

    assertEquals(0, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 5, board).getElements().size());
    assertEquals(1, Position.newPosition(3, 5, board).getElements().size());
    assertEquals(Orientation.LEFT, robot.getOrientation());
    assertEquals(2200, robot.getAmountOfEnergy(), epsilon);

    exampleInOneLineProgram.step();

    assertEquals(0, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 5, board).getElements().size());
    assertEquals(1, Position.newPosition(3, 5, board).getElements().size());
    assertEquals(Orientation.UP, robot.getOrientation());
    assertEquals(2100, robot.getAmountOfEnergy(), epsilon);

    exampleInOneLineProgram.step();

    assertEquals(1, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 5, board).getElements().size());
    assertEquals(0, Position.newPosition(3, 5, board).getElements().size());
    assertEquals(Orientation.UP, robot.getOrientation());
    assertEquals(1600, robot.getAmountOfEnergy(), epsilon);

    exampleInOneLineProgram.step();

    assertEquals(1, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 5, board).getElements().size());
    assertEquals(0, Position.newPosition(3, 5, board).getElements().size());
    assertEquals(Orientation.RIGHT, robot.getOrientation());
    assertEquals(1500, robot.getAmountOfEnergy(), epsilon);

    exampleInOneLineProgram.step();

    assertEquals(0, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(1, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 5, board).getElements().size());
    assertEquals(0, Position.newPosition(3, 5, board).getElements().size());
    assertEquals(Orientation.RIGHT, robot.getOrientation());
    assertEquals(1000, robot.getAmountOfEnergy(), epsilon);

    exampleInOneLineProgram.step();

    assertEquals(0, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(1, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 5, board).getElements().size());
    assertEquals(0, Position.newPosition(3, 5, board).getElements().size());
    assertEquals(Orientation.DOWN, robot.getOrientation());
    assertEquals(900, robot.getAmountOfEnergy(), epsilon);

    exampleInOneLineProgram.step();
    exampleInOneLineProgram.step();
    exampleInOneLineProgram.step();
    exampleInOneLineProgram.step();
    exampleInOneLineProgram.step();
    exampleInOneLineProgram.step();
    exampleInOneLineProgram.step();
    exampleInOneLineProgram.step();
    exampleInOneLineProgram.step();
    exampleInOneLineProgram.step();

    assertEquals(0, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(1, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 5, board).getElements().size());
    assertEquals(0, Position.newPosition(3, 5, board).getElements().size());
    assertEquals(Orientation.DOWN, robot.getOrientation());
    assertEquals(900, robot.getAmountOfEnergy(), epsilon);

    exampleInOneLineProgram.step();

    assertEquals(0, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(1, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 5, board).getElements().size());
    assertEquals(0, Position.newPosition(3, 5, board).getElements().size());
    assertEquals(Orientation.DOWN, robot.getOrientation());
    assertEquals(900, robot.getAmountOfEnergy(), epsilon);
  }
예제 #15
0
  @Test
  public void testCowboyStep() {
    robot = new Robot(new Energy(15700, unitOfPower.Ws), Orientation.RIGHT);
    robot.setPosition(Position.newPosition(3, 4, board));
    board.putElement(
        Position.newPosition(3, 2, board),
        new Robot(new Energy(5000, unitOfPower.Ws), Orientation.LEFT));
    board.putElement(
        Position.newPosition(5, 4, board),
        new Robot(new Energy(5000, unitOfPower.Ws), Orientation.LEFT));
    board.putElement(
        Position.newPosition(3, 6, board),
        new Robot(new Energy(5000, unitOfPower.Ws), Orientation.LEFT));

    Program cowboyProgram = new Program(cowboy, robot);
    robot.setProgram(cowboyProgram);

    assertEquals(4, board.getElementsOf(Robot.class).size());
    assertEquals(Orientation.RIGHT, robot.getOrientation());
    assertEquals(15700, robot.getAmountOfEnergy(), epsilon);

    cowboyProgram.step();

    assertEquals(4, board.getElementsOf(Robot.class).size());
    assertEquals(Orientation.RIGHT, robot.getOrientation());
    assertEquals(14700, robot.getAmountOfEnergy(), epsilon);

    cowboyProgram.step();

    assertEquals(4, board.getElementsOf(Robot.class).size());
    assertEquals(Orientation.RIGHT, robot.getOrientation());
    assertEquals(13700, robot.getAmountOfEnergy(), epsilon);

    cowboyProgram.step();

    assertEquals(4, board.getElementsOf(Robot.class).size());
    assertEquals(Orientation.RIGHT, robot.getOrientation());
    assertEquals(12700, robot.getAmountOfEnergy(), epsilon);

    cowboyProgram.step();

    assertEquals(4, board.getElementsOf(Robot.class).size());
    assertEquals(Orientation.RIGHT, robot.getOrientation());
    assertEquals(11700, robot.getAmountOfEnergy(), epsilon);

    cowboyProgram.step();

    assertEquals(3, board.getElementsOf(Robot.class).size());
    assertEquals(Orientation.RIGHT, robot.getOrientation());
    assertEquals(10700, robot.getAmountOfEnergy(), epsilon);

    cowboyProgram.step();

    assertEquals(3, board.getElementsOf(Robot.class).size());
    assertEquals(Orientation.DOWN, robot.getOrientation());
    assertEquals(10600, robot.getAmountOfEnergy(), epsilon);

    cowboyProgram.step();

    assertEquals(3, board.getElementsOf(Robot.class).size());
    assertEquals(Orientation.DOWN, robot.getOrientation());
    assertEquals(9600, robot.getAmountOfEnergy(), epsilon);

    cowboyProgram.step();

    assertEquals(3, board.getElementsOf(Robot.class).size());
    assertEquals(Orientation.DOWN, robot.getOrientation());
    assertEquals(8600, robot.getAmountOfEnergy(), epsilon);

    cowboyProgram.step();

    assertEquals(3, board.getElementsOf(Robot.class).size());
    assertEquals(Orientation.DOWN, robot.getOrientation());
    assertEquals(7600, robot.getAmountOfEnergy(), epsilon);

    cowboyProgram.step();

    assertEquals(3, board.getElementsOf(Robot.class).size());
    assertEquals(Orientation.DOWN, robot.getOrientation());
    assertEquals(6600, robot.getAmountOfEnergy(), epsilon);

    cowboyProgram.step();

    assertEquals(2, board.getElementsOf(Robot.class).size());
    assertEquals(Orientation.DOWN, robot.getOrientation());
    assertEquals(5600, robot.getAmountOfEnergy(), epsilon);

    cowboyProgram.step();

    assertEquals(2, board.getElementsOf(Robot.class).size());
    assertEquals(Orientation.LEFT, robot.getOrientation());
    assertEquals(5500, robot.getAmountOfEnergy(), epsilon);

    cowboyProgram.step();

    assertEquals(2, board.getElementsOf(Robot.class).size());
    assertEquals(Orientation.UP, robot.getOrientation());
    assertEquals(5400, robot.getAmountOfEnergy(), epsilon);

    cowboyProgram.step();
    cowboyProgram.step();
    cowboyProgram.step();
    cowboyProgram.step();
    cowboyProgram.step();

    assertEquals(1, board.getElementsOf(Robot.class).size());
    assertEquals(Orientation.UP, robot.getOrientation());
    assertEquals(400, robot.getAmountOfEnergy(), epsilon);

    cowboyProgram.step();
    cowboyProgram.step();
    cowboyProgram.step();
    cowboyProgram.step();

    assertEquals(1, board.getElementsOf(Robot.class).size());
    assertEquals(Orientation.UP, robot.getOrientation());
    assertEquals(0, robot.getAmountOfEnergy(), epsilon);

    cowboyProgram.step();
    cowboyProgram.step();
    cowboyProgram.step();
    cowboyProgram.step();
    cowboyProgram.step();
    cowboyProgram.step();
    cowboyProgram.step();
    cowboyProgram.step();
    cowboyProgram.step();
    cowboyProgram.step();

    assertEquals(1, board.getElementsOf(Robot.class).size());
    assertEquals(Orientation.UP, robot.getOrientation());
    assertEquals(0, robot.getAmountOfEnergy(), epsilon);
  }