Package aima.core.environment.eightpuzzle

Examples of aima.core.environment.eightpuzzle.EightPuzzleBoard


     * agent.
     */
    @Override
    public void prepare(String changedSelector) {
      AgentAppFrame.SelectionState selState = frame.getSelection();
      EightPuzzleBoard board = null;
      switch (selState.getValue(EightPuzzleFrame.ENV_SEL)) {
      case 0: // three moves
        board = new EightPuzzleBoard(new int[] { 1, 2, 5, 3, 4, 0, 6,
            7, 8 });
        break;
      case 1: // medium
        board = new EightPuzzleBoard(new int[] { 1, 4, 2, 7, 5, 8, 3,
            0, 6 });
        break;
      case 2: // extreme
        board = new EightPuzzleBoard(new int[] { 0, 8, 7, 6, 5, 4, 3,
            2, 1 });
        break;
      case 3: // random
        board = new EightPuzzleBoard(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8});
        Random r = new Random(System.currentTimeMillis());
        for (int i = 0; i < 200 ; i++) {
          switch (r.nextInt(4)) {
          case 0: board.moveGapUp(); break;
          case 1: board.moveGapDown(); break;
          case 2: board.moveGapLeft(); break;
          case 3: board.moveGapRight(); break;
          }
        }
      }
      env = new EightPuzzleEnvironment(board);
      agent = null;
View Full Code Here


*/

public class GenerateRandomEightPuzzleBoard {
  public static void main(String[] args) {
    Random r = new Random();
    EightPuzzleBoard board = new EightPuzzleBoard(new int[] { 0, 1, 2, 3,
        4, 5, 6, 7, 8 });
    for (int i = 0; i < 50; i++) {
      int th = r.nextInt(4);
      if (th == 0) {
        board.moveGapUp();
      }
      if (th == 1) {
        board.moveGapDown();
      }
      if (th == 2) {
        board.moveGapLeft();
      }
      if (th == 3) {
        board.moveGapRight();
      }
    }
    System.out.println(board);
  }
View Full Code Here

    try {
      // EightPuzzleBoard extreme = new EightPuzzleBoard(new int[]
      // {2,0,5,6,4,8,3,7,1});
      // EightPuzzleBoard extreme = new EightPuzzleBoard(new int[]
      // {0,8,7,6,5,4,3,2,1});
      EightPuzzleBoard board = new EightPuzzleBoard(new int[] { 7, 1, 8,
          0, 4, 6, 2, 3, 5 });

      Problem problem = new Problem(board,
          EightPuzzleFunctionFactory.getActionsFunction(),
          EightPuzzleFunctionFactory.getResultFunction(),
View Full Code Here

public class EightPuzzleBoardMoveTest {
  EightPuzzleBoard board;

  @Before
  public void setUp() {
    board = new EightPuzzleBoard(new int[] { 0, 5, 4, 6, 1, 8, 7, 3, 2 });
  }
View Full Code Here

  }

  @Test
  public void testPosition1MoveUp() {
    board.moveGapUp();
    Assert.assertEquals(new EightPuzzleBoard(new int[] { 0, 5, 4, 6, 1, 8,
        7, 3, 2 }), board);
  }
View Full Code Here

  }

  @Test
  public void testPosition1MoveDown() {
    board.moveGapDown();
    Assert.assertEquals(new EightPuzzleBoard(new int[] { 6, 5, 4, 0, 1, 8,
        7, 3, 2 }), board);
  }
View Full Code Here

  }

  @Test
  public void testPosition1MoveLeft() {
    board.moveGapLeft();
    Assert.assertEquals(new EightPuzzleBoard(new int[] { 0, 5, 4, 6, 1, 8,
        7, 3, 2 }), board);
  }
View Full Code Here

  }

  @Test
  public void testPosition1MoveRight() {
    board.moveGapRight();
    Assert.assertEquals(new EightPuzzleBoard(new int[] { 5, 0, 4, 6, 1, 8,
        7, 3, 2 }), board);
  }
View Full Code Here

  @Test
  public void testPosition2MoveUp() {
    // { 5, 0, 4, 6, 1, 8, 7, 3, 2 }
    setGapToPosition2();
    board.moveGapUp();
    Assert.assertEquals(new EightPuzzleBoard(new int[] { 5, 0, 4, 6, 1, 8,
        7, 3, 2 }), board);
  }
View Full Code Here

    try {
      // EightPuzzleBoard extreme = new EightPuzzleBoard(new int[]
      // {2,0,5,6,4,8,3,7,1});
      // EightPuzzleBoard extreme = new EightPuzzleBoard(new int[]
      // {0,8,7,6,5,4,3,2,1});
      EightPuzzleBoard board = new EightPuzzleBoard(new int[] { 7, 1, 8,
          0, 4, 6, 2, 3, 5 });

      Problem problem = new Problem(board,
          EightPuzzleFunctionFactory.getActionsFunction(),
          EightPuzzleFunctionFactory.getResultFunction(),
View Full Code Here

TOP

Related Classes of aima.core.environment.eightpuzzle.EightPuzzleBoard

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.