use of aima.core.util.datastructure.XYLocation in project aima-java by aimacode.
the class NQueensViewCtrl method update.
/** Updates the view. */
public void update(NQueensBoard board) {
int size = board.getSize();
if (queens.length != size * size) {
gridPane.getChildren().clear();
gridPane.getColumnConstraints().clear();
gridPane.getRowConstraints().clear();
queens = new Polygon[size * size];
RowConstraints c1 = new RowConstraints();
c1.setPercentHeight(100.0 / size);
ColumnConstraints c2 = new ColumnConstraints();
c2.setPercentWidth(100.0 / size);
for (int i = 0; i < board.getSize(); i++) {
gridPane.getRowConstraints().add(c1);
gridPane.getColumnConstraints().add(c2);
}
for (int i = 0; i < queens.length; i++) {
StackPane field = new StackPane();
queens[i] = createQueen();
field.getChildren().add(queens[i]);
int col = i % size;
int row = i / size;
field.setBackground(new Background(new BackgroundFill((col % 2 == row % 2) ? Color.WHITE : Color.LIGHTGRAY, null, null)));
gridPane.add(field, col, row);
}
}
double scale = 0.2 * gridPane.getWidth() / gridPane.getColumnConstraints().size();
for (int i = 0; i < queens.length; i++) {
Polygon queen = queens[i];
queen.setScaleX(scale);
queen.setScaleY(scale);
XYLocation loc = new XYLocation(i % size, i / size);
if (board.queenExistsAt(loc)) {
queen.setVisible(true);
queen.setFill(board.isSquareUnderAttack(loc) ? Color.RED : Color.BLACK);
} else {
queen.setVisible(false);
}
}
}
use of aima.core.util.datastructure.XYLocation in project aima-java by aimacode.
the class EightPuzzleViewCtrl method update.
/** Updates the view. */
public void update() {
for (int i = 0; i < 9; i++) {
int tileNo = board.getValueAt(new XYLocation(i / 3, i % 3));
tileBtns[i].setText(tileNo == 0 ? "" : Integer.toString(tileNo));
tileBtns[i].setDisable(tileNo == 0);
}
}
use of aima.core.util.datastructure.XYLocation in project aima-java by aimacode.
the class XYEnvironmentTest method testMoveObjectToAbsoluteLocation.
@Test
public void testMoveObjectToAbsoluteLocation() {
XYLocation loc = new XYLocation(5, 5);
env.moveObjectToAbsoluteLocation(a, loc);
Assert.assertEquals(new XYLocation(5, 5), env.getCurrentLocationFor(a));
}
use of aima.core.util.datastructure.XYLocation in project aima-java by aimacode.
the class XYEnvironmentTest method testMoveWithBlockingWalls.
@Test
public void testMoveWithBlockingWalls() {
XYLocation loc = new XYLocation(5, 5);
env.moveObjectToAbsoluteLocation(a, loc);
XYLocation northLoc = new XYLocation(5, 6);
XYLocation southLoc = new XYLocation(5, 4);
XYLocation westLoc = new XYLocation(4, 5);
// wall to the north of
env.addObjectToLocation(new Wall(), northLoc);
// object
Assert.assertTrue(env.isBlocked(northLoc));
// wall to the south of
env.addObjectToLocation(new Wall(), southLoc);
// object
// wall to the west of
env.addObjectToLocation(new Wall(), westLoc);
// object
Assert.assertEquals(4, env.getEnvironmentObjects().size());
// should not move
env.moveObject(a, XYLocation.Direction.North);
// should not move
env.moveObject(a, XYLocation.Direction.South);
// should not move
env.moveObject(a, XYLocation.Direction.West);
// SHOULD move
env.moveObject(a, XYLocation.Direction.East);
Assert.assertEquals(new XYLocation(6, 5), env.getCurrentLocationFor(a));
}
use of aima.core.util.datastructure.XYLocation in project aima-java by aimacode.
the class XYEnvironmentTest method testAddObjectTwice.
@Test
public void testAddObjectTwice() {
Assert.assertEquals(1, env.getAgents().size());
XYLocation loc = new XYLocation(5, 5);
AbstractAgent b = new MockAgent();
env.addObjectToLocation(b, loc);
Assert.assertEquals(2, env.getAgents().size());
Assert.assertEquals(loc, env.getCurrentLocationFor(b));
}
Aggregations