Examples of XYLocation


Examples of aima.core.util.datastructure.XYLocation

    return getValueAt(loc.getXCoOrdinate(), loc.getYCoOrdinate());
  }

  public XYLocation getLocationOf(int val) {
    int absPos = getPositionOf(val);
    return new XYLocation(getXCoord(absPos), getYCoord(absPos));
  }
View Full Code Here

Examples of aima.core.util.datastructure.XYLocation

  public List<XYLocation> getPositions() {
    ArrayList<XYLocation> retVal = new ArrayList<XYLocation>();
    for (int i = 0; i < 9; i++) {
      int absPos = getPositionOf(i);
      XYLocation loc = new XYLocation(getXCoord(absPos),
          getYCoord(absPos));
      retVal.add(loc);

    }
    return retVal;
View Full Code Here

Examples of aima.core.util.datastructure.XYLocation

  }

  public void setBoard(List<XYLocation> locs) {
    int count = 0;
    for (int i = 0; i < locs.size(); i++) {
      XYLocation loc = locs.get(i);
      this.setValue(loc.getXCoOrdinate(), loc.getYCoOrdinate(), count);
      count = count + 1;
    }
  }
View Full Code Here

Examples of aima.core.util.datastructure.XYLocation

    return getNumberOfMisplacedTiles(board);
  }

  private int getNumberOfMisplacedTiles(EightPuzzleBoard board) {
    int numberOfMisplacedTiles = 0;
    if (!(board.getLocationOf(0).equals(new XYLocation(0, 0)))) {
      numberOfMisplacedTiles++;
    }
    if (!(board.getLocationOf(1).equals(new XYLocation(0, 1)))) {
      numberOfMisplacedTiles++;
    }
    if (!(board.getLocationOf(2).equals(new XYLocation(0, 2)))) {
      numberOfMisplacedTiles++;
    }
    if (!(board.getLocationOf(3).equals(new XYLocation(1, 0)))) {
      numberOfMisplacedTiles++;
    }
    if (!(board.getLocationOf(4).equals(new XYLocation(1, 1)))) {
      numberOfMisplacedTiles++;
    }
    if (!(board.getLocationOf(5).equals(new XYLocation(1, 2)))) {
      numberOfMisplacedTiles++;
    }
    if (!(board.getLocationOf(6).equals(new XYLocation(2, 0)))) {
      numberOfMisplacedTiles++;
    }
    if (!(board.getLocationOf(7).equals(new XYLocation(2, 1)))) {
      numberOfMisplacedTiles++;
    }
    if (!(board.getLocationOf(8).equals(new XYLocation(2, 2)))) {
      numberOfMisplacedTiles++;
    }
    return numberOfMisplacedTiles;
  }
View Full Code Here

Examples of aima.core.util.datastructure.XYLocation

      for (int toX = fromX + 1; toX < boardSize; toX++) {
        int fromY = qPositions.get(fromX).getYCoOrdinate();
        boolean nonAttackingPair = true;
        // Check right beside
        int toY = fromY;
        if (board.queenExistsAt(new XYLocation(toX, toY))) {
          nonAttackingPair = false;
        }
        // Check right and above
        toY = fromY - (toX - fromX);
        if (toY >= 0) {
          if (board.queenExistsAt(new XYLocation(toX, toY))) {
            nonAttackingPair = false;
          }
        }
        // Check right and below
        toY = fromY + (toX - fromX);
        if (toY < boardSize) {
          if (board.queenExistsAt(new XYLocation(toX, toY))) {
            nonAttackingPair = false;
          }
        }

        if (nonAttackingPair) {
View Full Code Here

Examples of aima.core.util.datastructure.XYLocation

    int boardSize = individual.length();
    NQueensBoard board = new NQueensBoard(boardSize);
    for (int i = 0; i < boardSize; i++) {
      int pos = Character
          .digit(individual.charAt(i), individual.length());
      board.addQueenAt(new XYLocation(i, pos));
    }

    return board;
  }
View Full Code Here

Examples of aima.core.util.datastructure.XYLocation

      Set<Action> actions = new LinkedHashSet<Action>();

      int numQueens = board.getNumberOfQueensOnBoard();
      int boardSize = board.getSize();
      for (int i = 0; i < boardSize; i++) {
        XYLocation newLocation = new XYLocation(numQueens, i);
        if (!(board.isSquareUnderAttack(newLocation))) {
          actions.add(new QueenAction(QueenAction.PLACE_QUEEN,
              newLocation));
        }
      }
View Full Code Here

Examples of aima.core.util.datastructure.XYLocation

    public Set<Action> actions(Object state) {
      Set<Action> actions = new LinkedHashSet<Action>();
      NQueensBoard board = (NQueensBoard) state;
      for (int i = 0; i < board.getSize(); i++)
        for (int j = 0; j < board.getSize(); j++) {
          XYLocation loc = new XYLocation(i, j);
          if (!board.queenExistsAt(loc))
            actions.add(new QueenAction(QueenAction.MOVE_QUEEN, loc));
        }
      return actions;
    }
View Full Code Here

Examples of aima.core.util.datastructure.XYLocation

  public List<XYLocation> getQueenPositions() {
    ArrayList<XYLocation> result = new ArrayList<XYLocation>();
    for (int i = 0; i < size; i++) {
      for (int j = 0; j < size; j++) {
        if (queenExistsAt(i, j))
          result.add(new XYLocation(i, j));
      }
    }
    return result;

  }
View Full Code Here

Examples of aima.core.util.datastructure.XYLocation

public class TicTacToe extends Game<XYLocation> {
  public TicTacToe() {
    List<XYLocation> moves = new ArrayList<XYLocation>();
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        XYLocation loc = new XYLocation(i, j);
        moves.add(loc);
      }
    }
    initialState.put("moves", moves);
    initialState.put("player", "X");
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.