Package aima.core.util.datastructure

Examples of aima.core.util.datastructure.XYLocation


  @Test
  public void testPrint() {

    NQueensBoard board2 = new NQueensBoard(2);
    board2.addQueenAt(new XYLocation(0, 0));
    String expected = " Q  - \n -  - \n";
    Assert.assertEquals(expected, board2.getBoardPic());
  }
View Full Code Here


  }

  @Test
  public void testDontPlaceTwoQueensOnOneSquare() {

    board.addQueenAt(new XYLocation(0, 0));
    board.addQueenAt(new XYLocation(0, 0));
    Assert.assertEquals(1, board.getNumberOfQueensOnBoard());
  }
View Full Code Here

    Assert.assertEquals(1, board.getNumberOfQueensOnBoard());
  }

  @Test
  public void testSimpleHorizontalAttack() {
    XYLocation loc = new XYLocation(0, 0);
    board.addQueenAt(loc);
    Assert.assertEquals(0, board.getNumberOfAttacksOn(loc));
    Assert.assertEquals(1, board.getNumberOfAttacksOn(new XYLocation(1, 0)));
    Assert.assertEquals(1, board.getNumberOfAttacksOn(loc.right()));
    Assert.assertEquals(1, board.getNumberOfAttacksOn(new XYLocation(7, 0)));
  }
View Full Code Here

    Assert.assertEquals(1, board.getNumberOfAttacksOn(new XYLocation(7, 0)));
  }

  @Test
  public void testSimpleVerticalAttack() {
    XYLocation loc = new XYLocation(0, 0);
    board.addQueenAt(loc);
    Assert.assertEquals(0, board.getNumberOfAttacksOn(loc));
    Assert.assertEquals(1, board.getNumberOfAttacksOn(loc.down()));
    Assert.assertEquals(1, board.getNumberOfAttacksOn(new XYLocation(0, 7)));
  }
View Full Code Here

    Assert.assertEquals(1, board.getNumberOfAttacksOn(new XYLocation(0, 7)));
  }

  @Test
  public void testSimpleDiagonalAttack() {
    XYLocation loc = new XYLocation(3, 3);
    board.addQueenAt(loc);
    Assert.assertEquals(0, board.getNumberOfAttacksOn(loc));
    Assert.assertEquals(1, board.getNumberOfAttacksOn(loc.down().right()));
    Assert.assertEquals(1, board.getNumberOfAttacksOn(loc.down().left()));
    Assert.assertEquals(1, board.getNumberOfAttacksOn(loc.up().left()));
    Assert.assertEquals(1, board.getNumberOfAttacksOn(loc.up().right()));
    Assert.assertEquals(1, board.getNumberOfAttacksOn(new XYLocation(7, 7)));
    Assert.assertEquals(1, board.getNumberOfAttacksOn(new XYLocation(0, 0)));
    Assert.assertEquals(1, board.getNumberOfAttacksOn(new XYLocation(6, 0)));
    Assert.assertEquals(1, board.getNumberOfAttacksOn(new XYLocation(0, 6)));
  }
View Full Code Here

    Assert.assertEquals(1, board.getNumberOfAttacksOn(new XYLocation(0, 6)));
  }

  @Test
  public void testMultipleQueens() {
    XYLocation loc1 = new XYLocation(3, 3);
    board.addQueenAt(loc1);
    Assert.assertEquals(1, board.getNumberOfAttacksOn(loc1.right()));

    board.addQueenAt(loc1.right().right());
    Assert.assertEquals(1, board.getNumberOfAttacksOn(loc1));
    Assert.assertEquals(2, board.getNumberOfAttacksOn(loc1.right()));

    board.addQueenAt(loc1.right().down());
    Assert.assertEquals(2, board.getNumberOfAttacksOn(loc1));
    Assert.assertEquals(3, board.getNumberOfAttacksOn(loc1.right()));
    Assert.assertEquals(2, board.getNumberOfAttacksOn(loc1.right().right()));
  }
View Full Code Here

    Assert.assertEquals(2, board.getNumberOfAttacksOn(loc1.right().right()));
  }

  @Test
  public void testBoardDisplay() {
    board.addQueenAt(new XYLocation(0, 5));
    board.addQueenAt(new XYLocation(1, 6));
    board.addQueenAt(new XYLocation(2, 1));
    board.addQueenAt(new XYLocation(3, 3));
    board.addQueenAt(new XYLocation(4, 6));
    board.addQueenAt(new XYLocation(5, 4));
    board.addQueenAt(new XYLocation(6, 7));
    board.addQueenAt(new XYLocation(7, 7));
    Assert.assertEquals(" -  -  -  -  -  -  -  - \n"
        + " -  -  Q  -  -  -  -  - \n" + " -  -  -  -  -  -  -  - \n"
        + " -  -  -  Q  -  -  -  - \n" + " -  -  -  -  -  Q  -  - \n"
        + " Q  -  -  -  -  -  -  - \n" + " -  Q  -  -  Q  -  -  - \n"
        + " -  -  -  -  -  -  Q  Q \n", board.getBoardPic());
View Full Code Here

    Assert.assertEquals(expected[8], boardRepr[8]);
  }

  @Test
  public void testGetLocation() {
    Assert.assertEquals(new XYLocation(0, 2), board.getLocationOf(0));
    Assert.assertEquals(new XYLocation(1, 1), board.getLocationOf(1));
    Assert.assertEquals(new XYLocation(2, 2), board.getLocationOf(2));
    Assert.assertEquals(new XYLocation(2, 1), board.getLocationOf(3));
    Assert.assertEquals(new XYLocation(0, 1), board.getLocationOf(4));
    Assert.assertEquals(new XYLocation(0, 0), board.getLocationOf(5));
    Assert.assertEquals(new XYLocation(1, 0), board.getLocationOf(6));
    Assert.assertEquals(new XYLocation(2, 0), board.getLocationOf(7));
    Assert.assertEquals(new XYLocation(1, 2), board.getLocationOf(8));
  }
View Full Code Here

    Assert.assertEquals(new XYLocation(1, 2), board.getLocationOf(8));
  }

  @Test
  public void testGetValueAt() {
    Assert.assertEquals(5, board.getValueAt(new XYLocation(0, 0)));
    Assert.assertEquals(4, board.getValueAt(new XYLocation(0, 1)));
    Assert.assertEquals(0, board.getValueAt(new XYLocation(0, 2)));
    Assert.assertEquals(6, board.getValueAt(new XYLocation(1, 0)));
    Assert.assertEquals(1, board.getValueAt(new XYLocation(1, 1)));
    Assert.assertEquals(8, board.getValueAt(new XYLocation(1, 2)));
    Assert.assertEquals(7, board.getValueAt(new XYLocation(2, 0)));
    Assert.assertEquals(3, board.getValueAt(new XYLocation(2, 1)));
    Assert.assertEquals(2, board.getValueAt(new XYLocation(2, 2)));
  }
View Full Code Here

  }

  @Test
  public void testGetPositions() {
    List<XYLocation> expected = new ArrayList<XYLocation>();
    expected.add(new XYLocation(0, 2));
    expected.add(new XYLocation(1, 1));
    expected.add(new XYLocation(2, 2));
    expected.add(new XYLocation(2, 1));
    expected.add(new XYLocation(0, 1));
    expected.add(new XYLocation(0, 0));
    expected.add(new XYLocation(1, 0));
    expected.add(new XYLocation(2, 0));
    expected.add(new XYLocation(1, 2));

    List<XYLocation> actual = board.getPositions();
    Assert.assertEquals(expected, actual);
  }
View Full Code Here

TOP

Related Classes of aima.core.util.datastructure.XYLocation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.