Examples of XYLocation


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

  public NQueensBoard getBoardForIndividual(Individual<Integer> individual) {
    int boardSize = individual.length();
    NQueensBoard board = new NQueensBoard(boardSize);
    for (int i = 0; i < boardSize; i++) {
      int pos = individual.getRepresentation().get(i);
      board.addQueenAt(new XYLocation(i, pos));
    }

    return board;
  }
View Full Code Here

Examples of aima.core.util.datastructure.XYLocation

  public List<XYLocation> getUnMarkedPositions() {
    List<XYLocation> result = new ArrayList<XYLocation>();
    for (int col = 0; col < 3; col++) {
      for (int row = 0; row < 3; row++) {
        if (isEmpty(col, row)) {
          result.add(new XYLocation(col, row));
        }
      }
    }
    return result;
  }
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

    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++;
    }
    // Subtract the gap position from the # of misplaced tiles
    // as its not actually a tile (see issue 73).
    if (numberOfMisplacedTiles > 0) {
View Full Code Here

Examples of aima.core.util.datastructure.XYLocation

  public double h(Object state) {
    EightPuzzleBoard board = (EightPuzzleBoard) state;
    int retVal = 0;
    for (int i = 1; i < 9; i++) {
      XYLocation loc = board.getLocationOf(i);
      retVal += evaluateManhattanDistanceOf(i, loc);
    }
    return retVal;

  }
View Full Code Here

Examples of aima.core.util.datastructure.XYLocation

    // Ensure is added to the environment
    addEnvironmentObject(eo);
  }

  public void moveObject(EnvironmentObject eo, XYLocation.Direction direction) {
    XYLocation presentLocation = envState.getCurrentLocationFor(eo);

    if (null != presentLocation) {
      XYLocation locationToMoveTo = presentLocation.locationAt(direction);
      if (!(isBlocked(locationToMoveTo))) {
        moveObjectToAbsoluteLocation(eo, locationToMoveTo);
      }
    }
  }
View Full Code Here

Examples of aima.core.util.datastructure.XYLocation

    return false;
  }

  public void makePerimeter() {
    for (int i = 0; i < envState.width; i++) {
      XYLocation loc = new XYLocation(i, 0);
      XYLocation loc2 = new XYLocation(i, envState.height - 1);
      envState.moveObjectToAbsoluteLocation(new Wall(), loc);
      envState.moveObjectToAbsoluteLocation(new Wall(), loc2);
    }

    for (int i = 0; i < envState.height; i++) {
      XYLocation loc = new XYLocation(0, i);
      XYLocation loc2 = new XYLocation(envState.width - 1, i);
      envState.moveObjectToAbsoluteLocation(new Wall(), loc);
      envState.moveObjectToAbsoluteLocation(new Wall(), loc2);
    }
  }
View Full Code Here

Examples of aima.core.util.datastructure.XYLocation

  public XYEnvironmentState(int width, int height) {
    this.width = width;
    this.height = height;
    for (int h = 1; h <= height; h++) {
      for (int w = 1; w <= width; w++) {
        objsAtLocation.put(new XYLocation(h, w),
            new LinkedHashSet<EnvironmentObject>());
      }
    }
  }
View Full Code Here

Examples of aima.core.util.datastructure.XYLocation

  }

  public Set<EnvironmentObject> getObjectsNear(Agent agent, int radius) {
    Set<EnvironmentObject> objsNear = new LinkedHashSet<EnvironmentObject>();

    XYLocation agentLocation = getCurrentLocationFor(agent);
    for (XYLocation loc : objsAtLocation.keySet()) {
      if (withinRadius(radius, agentLocation, loc)) {
        objsNear.addAll(objsAtLocation.get(loc));
      }
    }
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.