Ejemplo n.º 1
0
 @Test
 public void testPieceFlip() {
   Othello o = new Othello();
   o.restart(Piece.BLACK);
   o.move(2, 3);
   assertEquals(Piece.BLACK, o.getEntry(3, 3));
 }
Ejemplo n.º 2
0
 @Test
 public void testMoreBlackPieces() {
   Othello o = new Othello();
   o.restart(Piece.BLACK);
   o.move(2, 3);
   assertTrue(o.moreBlackPieces());
 }
Ejemplo n.º 3
0
 @Test
 public void testConstructor() {
   Othello o = new Othello();
   assertEquals(Piece.NONE, o.getEntry(7, 7));
   assertEquals(Piece.NONE, o.getEntry(0, 0));
   assertEquals(Piece.NONE, o.getEntry(3, 4));
 }
Ejemplo n.º 4
0
  public int playN(Player white, Player black, int n) {
    long startTime = System.nanoTime();
    int scoreW = 0;
    int scoreB = 0;

    for (int i = 0; i < n; i++) {
      Othello o = new Othello();
      white.init(1, 9000000000L, new Random());
      black.init(0, 9000000000L, new Random());
      boolean blackMove = true;
      Move prevMove = null;

      while (o.gameStatus() == 0) {
        Move move =
            blackMove
                ? black.nextMove(prevMove, 90000000L, 90000000L)
                : white.nextMove(prevMove, 90000000L, 90000000L);
        if (move != null) o.makeMove((blackMove ? 2 : 1), move);
        prevMove = move;
        blackMove = !blackMove;
      }
      if (o.gameStatus() == 1) scoreW++;
      else if (o.gameStatus() == 2) scoreB++;
      System.out.println(o);
    }
    long endTime = System.nanoTime();
    System.out.println(((double) (endTime - startTime)) / (Math.pow(10.0, 9.0)));
    return scoreW - scoreB;
  }
Ejemplo n.º 5
0
 @Test
 public void testValidMove() {
   Othello o = new Othello();
   o.restart(Piece.BLACK);
   boolean valid = o.validMove(Piece.BLACK, 2, 3);
   assertTrue(valid);
   valid = o.validMove(Piece.BLACK, 5, 3);
 }
Ejemplo n.º 6
0
 @Test
 public void testRestart() {
   Othello o = new Othello();
   o.restart(Piece.BLACK);
   assertTrue(o.getTurn().equals(Piece.BLACK));
   assertEquals(o.getEntry(3, 4), Piece.BLACK);
   assertEquals(o.getEntry(3, 3), Piece.WHITE);
 }
Ejemplo n.º 7
0
 @Test
 public void testCopyConstructor() {
   Othello o1 = new Othello();
   o1.restart(Piece.BLACK);
   Othello o2 = new Othello(o1);
   o2.setTurn(Piece.WHITE);
   assertEquals(Piece.BLACK, o1.getTurn());
   assertEquals(Piece.WHITE, o2.getTurn());
 }
Ejemplo n.º 8
0
 @Test
 public void testMoreWhitePieces() {
   Othello o = new Othello();
   o.setEntry(Piece.WHITE, 0, 0);
   assertTrue(o.moreWhitePieces());
 }
Ejemplo n.º 9
0
 @Test
 public void testEqualPieces() {
   Othello o = new Othello();
   assertTrue(o.equalPieces());
 }
Ejemplo n.º 10
0
 @Test
 public void testCount() {
   Othello o = new Othello();
   o.restart(Piece.BLACK);
   assertEquals(2, o.count(Piece.WHITE));
 }
Ejemplo n.º 11
0
 @Test
 public void testSetEntry() {
   Othello o = new Othello();
   o.setEntry(Piece.WHITE, 1, 2);
   assertEquals(Piece.WHITE, o.getEntry(1, 2));
 }
Ejemplo n.º 12
0
 @Test
 public void testSetTurn() {
   Othello o = new Othello();
   o.setTurn(Piece.WHITE);
   assertEquals(o.getTurn(), Piece.WHITE);
 }