use of aima.core.util.datastructure.XYLocation in project aima-java by aimacode.
the class NQueensBoardTest method testMoveNonExistentQueen.
@Test
public void testMoveNonExistentQueen() {
XYLocation from = new XYLocation(0, 0);
XYLocation to = new XYLocation(1, 1);
board.moveQueen(from, to);
Assert.assertEquals(0, board.getNumberOfQueensOnBoard());
}
use of aima.core.util.datastructure.XYLocation in project aima-java by aimacode.
the class NQueensBoardTest method testRemoveNonExistentQueen.
@Test
public void testRemoveNonExistentQueen() {
board.removeQueenFrom(new XYLocation(0, 0));
Assert.assertEquals(0, board.getNumberOfQueensOnBoard());
}
use of aima.core.util.datastructure.XYLocation in project aima-java by aimacode.
the class NQueensBoardTest method testBasics.
@Test
public void testBasics() {
Assert.assertEquals(0, board.getNumberOfQueensOnBoard());
board.addQueenAt(new XYLocation(0, 0));
Assert.assertEquals(1, board.getNumberOfQueensOnBoard());
board.addQueenAt(new XYLocation(0, 0));
Assert.assertEquals(1, board.getNumberOfQueensOnBoard());
board.addQueenAt(new XYLocation(1, 1));
Assert.assertEquals(2, board.getNumberOfQueensOnBoard());
Assert.assertTrue(board.queenExistsAt(new XYLocation(1, 1)));
Assert.assertTrue(board.queenExistsAt(new XYLocation(0, 0)));
board.moveQueen(new XYLocation(1, 1), new XYLocation(3, 3));
Assert.assertTrue(board.queenExistsAt(new XYLocation(3, 3)));
Assert.assertTrue(!(board.queenExistsAt(new XYLocation(1, 1))));
Assert.assertEquals(2, board.getNumberOfQueensOnBoard());
}
use of aima.core.util.datastructure.XYLocation in project aima-java by aimacode.
the class NQueensBoardTest method testCornerQueenAttack2.
@Test
public void testCornerQueenAttack2() {
board.addQueenAt(new XYLocation(7, 7));
Assert.assertEquals(true, board.isSquareUnderAttack(new XYLocation(0, 0)));
Assert.assertEquals(true, board.isSquareUnderAttack(new XYLocation(7, 0)));
Assert.assertEquals(true, board.isSquareUnderAttack(new XYLocation(0, 7)));
Assert.assertEquals(true, board.isSquareUnderAttack(new XYLocation(7, 0)));
Assert.assertEquals(true, board.isSquareUnderAttack(new XYLocation(6, 6)));
Assert.assertEquals(true, board.isSquareUnderAttack(new XYLocation(5, 5)));
Assert.assertEquals(false, board.isSquareUnderAttack(new XYLocation(6, 5)));
Assert.assertEquals(false, board.isSquareUnderAttack(new XYLocation(5, 6)));
}
use of aima.core.util.datastructure.XYLocation in project aima-java by aimacode.
the class NQueensCspApp method getBoard.
private NQueensBoard getBoard(Assignment<Variable, Integer> assignment) {
NQueensBoard board = new NQueensBoard(csp.getVariables().size());
for (Variable var : assignment.getVariables()) {
int col = Integer.parseInt(var.getName().substring(1)) - 1;
int row = assignment.getValue(var) - 1;
board.addQueenAt(new XYLocation(col, row));
}
return board;
}
Aggregations