Examples of NQueensBoard


Examples of aima.core.environment.nqueens.NQueensBoard

    /**
     * Displays the board state by labeling and coloring the square buttons.
     */
    protected void showState() {
      NQueensBoard board = ((NQueensEnvironment) env).getBoard();
      if (currSize != board.getSize()) {
        currSize = board.getSize();
        removeAll();
        setLayout(new GridLayout(currSize, currSize));
        squareButtons = new JButton[currSize * currSize];
        for (int i = 0; i < currSize * currSize; i++) {
          JButton square = new JButton("");
          square.setMargin(new Insets(0, 0, 0, 0));
          square
              .setBackground((i % currSize) % 2 == (i / currSize) % 2 ? Color.WHITE
                  : Color.LIGHT_GRAY);
          square.addActionListener(this);
          squareButtons[i] = square;
          add(square);
        }
      }
      for (int i = 0; i < currSize * currSize; i++)
        squareButtons[i].setText("");
      Font f = new java.awt.Font(Font.SANS_SERIF, Font.PLAIN, Math.min(
          getWidth(), getHeight())
          * 3 / 4 / currSize);
      for (XYLocation loc : board.getQueenPositions()) {
        JButton square = squareButtons[loc.getXCoOrdinate()
            + loc.getYCoOrdinate() * currSize];
        square.setForeground(board.isSquareUnderAttack(loc) ? Color.RED
            : Color.BLACK);
        square.setFont(f);
        square.setText("Q");
      }
      validate();
View Full Code Here

Examples of aima.core.environment.nqueens.NQueensBoard

     * Creates an n-queens environment and clears the current search agent.
     */
    @Override
    public void prepare(String changedSelector) {
      AgentAppFrame.SelectionState selState = frame.getSelection();
      NQueensBoard board = null;
      switch (selState.getValue(NQueensFrame.ENV_SEL)) {
      case 0: // 4 x 4 board
        board = new NQueensBoard(4);
        break;
      case 1: // 8 x 8 board
        board = new NQueensBoard(8);
        break;
      case 2: // 8 x 8 board
        board = new NQueensBoard(16);
        break;
      case 3: // 32 x 32 board
        board = new NQueensBoard(32);
        break;
      }
      env = new NQueensEnvironment(board);
      if (selState.getValue(NQueensFrame.PROBLEM_SEL) == 1)
        for (int i = 0; i < board.getSize(); i++)
          board.addQueenAt(new XYLocation(i, 0));
      boardDirty = false;
      agent = null;
      frame.getEnvView().setEnvironment(env);
    }
View Full Code Here

Examples of aima.core.environment.nqueens.NQueensBoard

  }

  private static void nQueensWithRecursiveDLS() {
    System.out.println("\nNQueensDemo recursive DLS -->");
    try {
      Problem problem = new Problem(new NQueensBoard(8),
          NQueensFunctionFactory.getIActionsFunction(),
          NQueensFunctionFactory.getResultFunction(),
          new NQueensGoalTest());
      Search search = new DepthLimitedSearch(8);
      SearchAgent agent = new SearchAgent(problem, search);
View Full Code Here

Examples of aima.core.environment.nqueens.NQueensBoard

  }

  private static void nQueensWithBreadthFirstSearch() {
    try {
      System.out.println("\nNQueensDemo BFS -->");
      Problem problem = new Problem(new NQueensBoard(8),
          NQueensFunctionFactory.getIActionsFunction(),
          NQueensFunctionFactory.getResultFunction(),
          new NQueensGoalTest());
      Search search = new BreadthFirstSearch(new TreeSearch());
      SearchAgent agent2 = new SearchAgent(problem, search);
View Full Code Here

Examples of aima.core.environment.nqueens.NQueensBoard

  }

  private static void nQueensWithDepthFirstSearch() {
    System.out.println("\nNQueensDemo DFS -->");
    try {
      Problem problem = new Problem(new NQueensBoard(8),
          NQueensFunctionFactory.getIActionsFunction(),
          NQueensFunctionFactory.getResultFunction(),
          new NQueensGoalTest());
      Search search = new DepthFirstSearch(new GraphSearch());
      SearchAgent agent = new SearchAgent(problem, search);
View Full Code Here

Examples of aima.core.environment.nqueens.NQueensBoard

  }

  private static void nQueensWithIterativeDeepeningSearch() {
    System.out.println("\nNQueensDemo Iterative DS  -->");
    try {
      Problem problem = new Problem(new NQueensBoard(8),
          NQueensFunctionFactory.getIActionsFunction(),
          NQueensFunctionFactory.getResultFunction(),
          new NQueensGoalTest());
      Search search = new IterativeDeepeningSearch();
      SearchAgent agent = new SearchAgent(problem, search);
View Full Code Here

Examples of aima.core.environment.nqueens.NQueensBoard

  }

  private static void nQueensSimulatedAnnealingSearch() {
    System.out.println("\nNQueensDemo Simulated Annealing  -->");
    try {
      Problem problem = new Problem(new NQueensBoard(8),
          NQueensFunctionFactory.getIActionsFunction(),
          NQueensFunctionFactory.getResultFunction(),
          new NQueensGoalTest());
      SimulatedAnnealingSearch search = new SimulatedAnnealingSearch(
          new AttackingPairsHeuristic());
View Full Code Here

Examples of aima.core.environment.nqueens.NQueensBoard

  }

  private static void nQueensHillClimbingSearch() {
    System.out.println("\nNQueensDemo HillClimbing  -->");
    try {
      Problem problem = new Problem(new NQueensBoard(8),
          NQueensFunctionFactory.getIActionsFunction(),
          NQueensFunctionFactory.getResultFunction(),
          new NQueensGoalTest());
      HillClimbingSearch search = new HillClimbingSearch(
          new AttackingPairsHeuristic());
View Full Code Here

Examples of aima.core.environment.nqueens.NQueensBoard

*/
public class UniformCostSearchTest {

  @Test
  public void testUniformCostSuccesfulSearch() throws Exception {
    Problem problem = new Problem(new NQueensBoard(8),
        NQueensFunctionFactory.getIActionsFunction(),
        NQueensFunctionFactory.getResultFunction(),
        new NQueensGoalTest());
    Search search = new UniformCostSearch();
    SearchAgent agent = new SearchAgent(problem, search);
View Full Code Here

Examples of aima.core.environment.nqueens.NQueensBoard

        agent.getInstrumentation().getProperty("pathCost"));
  }

  @Test
  public void testUniformCostUnSuccesfulSearch() throws Exception {
    Problem problem = new Problem(new NQueensBoard(3),
        NQueensFunctionFactory.getIActionsFunction(),
        NQueensFunctionFactory.getResultFunction(),
        new NQueensGoalTest());
    Search search = new UniformCostSearch();
    SearchAgent agent = new SearchAgent(problem, search);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.