Search in sources :

Example 46 with XYLocation

use of aima.core.util.datastructure.XYLocation in project aima-java by aimacode.

the class TicTacToeTest method testVerticalLineThroughBoard.

@Test
public void testVerticalLineThroughBoard() {
    state.mark(0, 0);
    state.mark(1, 0);
    state.mark(0, 1);
    state.mark(1, 1);
    Assert.assertEquals(false, state.lineThroughBoard());
    state.mark(new XYLocation(0, 2));
    Assert.assertEquals(true, state.lineThroughBoard());
}
Also used : XYLocation(aima.core.util.datastructure.XYLocation) Test(org.junit.Test)

Example 47 with XYLocation

use of aima.core.util.datastructure.XYLocation in project aima-java by aimacode.

the class NQueensBoardTest method testSimpleDiagonalAttack.

@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)));
}
Also used : XYLocation(aima.core.util.datastructure.XYLocation) Test(org.junit.Test)

Example 48 with XYLocation

use of aima.core.util.datastructure.XYLocation in project aima-java by aimacode.

the class NQueensBoardTest method testMoveQueen.

@Test
public void testMoveQueen() {
    XYLocation from = new XYLocation(0, 0);
    XYLocation to = new XYLocation(1, 1);
    board.addQueenAt(from);
    Assert.assertEquals(1, board.getNumberOfQueensOnBoard());
    Assert.assertTrue(board.queenExistsAt(from));
    Assert.assertFalse(board.queenExistsAt(to));
    board.moveQueen(from, to);
    Assert.assertEquals(1, board.getNumberOfQueensOnBoard());
    Assert.assertFalse(board.queenExistsAt(from));
    Assert.assertTrue(board.queenExistsAt(to));
}
Also used : XYLocation(aima.core.util.datastructure.XYLocation) Test(org.junit.Test)

Example 49 with XYLocation

use of aima.core.util.datastructure.XYLocation in project aima-java by aimacode.

the class NQueensBoardTest method testBoardDisplay.

@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());
    Assert.assertEquals("--------\n" + "--Q-----\n" + "--------\n" + "---Q----\n" + "-----Q--\n" + "Q-------\n" + "-Q--Q---\n" + "------QQ\n", board.toString());
}
Also used : XYLocation(aima.core.util.datastructure.XYLocation) Test(org.junit.Test)

Example 50 with XYLocation

use of aima.core.util.datastructure.XYLocation in project aima-java by aimacode.

the class NQueensBoardTest method testAttack3.

@Test
public void testAttack3() {
    board.addQueenAt(new XYLocation(0, 0));
    Assert.assertEquals(true, board.isSquareUnderAttack(new XYLocation(0, 1)));
}
Also used : XYLocation(aima.core.util.datastructure.XYLocation) Test(org.junit.Test)

Aggregations

XYLocation (aima.core.util.datastructure.XYLocation)56 Test (org.junit.Test)42 TicTacToeState (aima.core.environment.tictactoe.TicTacToeState)5 NQueensBoard (aima.core.environment.nqueens.NQueensBoard)4 Wall (aima.core.environment.xyenv.Wall)4 MockAgent (aima.test.core.unit.agent.impl.MockAgent)4 ArrayList (java.util.ArrayList)4 AbstractAgent (aima.core.agent.impl.AbstractAgent)3 GoalTest (aima.core.search.framework.problem.GoalTest)3 EnvironmentObject (aima.core.agent.EnvironmentObject)2 TicTacToeGame (aima.core.environment.tictactoe.TicTacToeGame)2 XYEnvironment (aima.core.environment.xyenv.XYEnvironment)1 IterativeDeepeningAlphaBetaSearch (aima.core.search.adversarial.IterativeDeepeningAlphaBetaSearch)1 LinkedHashSet (java.util.LinkedHashSet)1 Background (javafx.scene.layout.Background)1 BackgroundFill (javafx.scene.layout.BackgroundFill)1 ColumnConstraints (javafx.scene.layout.ColumnConstraints)1 RowConstraints (javafx.scene.layout.RowConstraints)1 StackPane (javafx.scene.layout.StackPane)1 Polygon (javafx.scene.shape.Polygon)1