Package com.barrybecker4.common.geometry

Examples of com.barrybecker4.common.geometry.Location


     * @return the other outgoing location for the sourcePlacement.
     */
    protected Location findOtherOutgoingLocation(TilePlacement sourcePlacement, Location excludeLocation) {

       Map<Integer, Location> outgoingPathLocations = sourcePlacement.getOutgoingPathLocations(primaryColor);
       Location loc = null;
       for (int rot : outgoingPathLocations.keySet()) {
           loc = outgoingPathLocations.get(rot);
           if (!loc.equals(excludeLocation)) {
               break;
           }
       }
       return loc;
    }
View Full Code Here


         TilePlacementList tiles = new TilePlacementList();
         TilePlacementList subPathTiles = subPath.getTilePlacements();
         TilePlacement lastTile = subPathTiles.getLast();
         int outgoingDirection = findDirectionAwayFromLast(subPathTiles, lastTile, pivotTile);

         Location newLocation = subPathTiles.getFirst().getLocation();
         int startDir = 0;
         startDir = findOutgoingDirection(pivotTile, newLocation);
         int numRotations = startDir - 3 - outgoingDirection;

         Location origLocation = pivotTile.getLocation();
         Rotation tileRotation = lastTile.getRotation().rotateBy(numRotations);
         TilePlacement previousTilePlacement = new TilePlacement(lastTile.getTile(), newLocation, tileRotation);
         tiles.add(previousTilePlacement);

         // this part is almost the same as in swapper
View Full Code Here

    private void findSolution() {

        // Keep track of our current path. We may need to backtrack along it if we encounter a dead end.
        List<Location> solutionPath = new LinkedList<Location>();

        Location currentPosition = maze.getStartPosition();
        MazeCell currentCell = maze.getCell(currentPosition);

        // push the initial moves
        stack.pushMoves( currentPosition, new IntLocation(0, 1), 1);
        panel_.paintAll();

        Location dir;
        int depth;
        boolean solved = false;

        // while there are still paths to try and we have not yet encountered the finish
        while ( !stack.isEmpty() && !solved ) {

            GenState state = stack.remove(0)// pop

            currentPosition = state.getPosition();
            solutionPath.add(0, currentPosition);

            if (currentPosition.equals(maze.getStopPosition()))  {
                solved = true;
            }

            dir = state.getDirection();
            depth = state.getDepth();
            if ( depth > currentCell.getDepth() ) {
                currentCell.setDepth(depth);
            }

            currentCell = maze.getCell(currentPosition);
            Location nextPosition = currentCell.getNextPosition(currentPosition,  dir);

            search(solutionPath, currentCell, dir, depth, nextPosition);
        }
    }
View Full Code Here

    }


    private void advanceToNextCell(MazeCell currentCell, Location dir, int depth,
                                   Location nextPosition, MazeCell nextCell) {
        Location currentPosition;
        if ( dir.getX() == 1 ) {// east
            currentCell.eastPath = true;
            nextCell.westPath = true;
        }
        else if ( dir.getY() == 1 ) { // south
View Full Code Here

     * @param solutionPath
     */
    private void backTrack(List<Location> solutionPath) {
        GenState lastState = stack.get(0);

        Location pos;
        do {
            pos =  solutionPath.remove(0);
            MazeCell cell = maze.getCell(pos);
            cell.clearPath();
        } while ( pos != lastState.getPosition());
View Full Code Here

     * exceptions even for moderately sized mazes.
     */
    public void search() {
        stack.clear();

        Location currentPosition = maze.getStartPosition();
        MazeCell currentCell = maze.getCell(currentPosition);
        currentCell.visited = true;

        // push the initial moves
        stack.pushMoves(currentPosition, new IntLocation(0, 1), 0);
View Full Code Here

    /** find the next cell to visit, given the last cell */
    private MazeCell findNextCell(MazeCell lastCell) {

        boolean moved = false;

        Location currentPosition;
        MazeCell nextCell;
        int depth;
        Location dir;

        do {
            GenState state = stack.remove(0)// pop

            currentPosition = state.getPosition();
            dir = state.getDirection();
            depth = state.getDepth();

            if ( depth > maxDepth) {
                maxDepth = depth;
                maze.setStopPosition(currentPosition);
            }
            if ( depth > lastCell.getDepth() )  {
                lastCell.setDepth(depth);
            }

            MazeCell currentCell = maze.getCell(currentPosition);
            Location nextPosition = currentCell.getNextPosition(currentPosition, dir);
            nextCell = maze.getCell(nextPosition);

            if (nextCell.visited) {
                addWall(currentCell, dir, nextCell);
            }
View Full Code Here

        List<Direction> directions = getShuffledDirections();

        // check all the directions except the one we came from
        for ( int i = 0; i < 3; i++ ) {
            Direction direction = directions.get(i);
            Location dir = direction.apply(currentDir);
            this.add(0, new GenState(currentPosition, dir, depth));
        }
    }
View Full Code Here

        getBoard().makeMove(move);

        if (move.isPassOrResignation())  {
            hash.applyPassingMove();
        } else {
            Location loc = move.getToLocation();
            hash.applyMove(loc, getBoard().getStateIndex(getBoard().getPosition(loc)));
        }
    }
View Full Code Here

    public void undoInternalMove( TwoPlayerMove move) {
        TwoPlayerMove lastMove = (TwoPlayerMove)moveList_.getLastMove();
        assert move.equals(lastMove) : "The move we are trying to undo ("+ move +") in list="
                + moveList_+" was not equal to the last move ("+lastMove+"). all move=" + getBoard().getMoveList();

        Location loc = move.getToLocation();

        if (!move.isPassingMove()) {
            hash.applyMove(loc, getBoard().getStateIndex(getBoard().getPosition(loc)));
        }
View Full Code Here

TOP

Related Classes of com.barrybecker4.common.geometry.Location

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.