Examples of TilePlacementList


Examples of com.barrybecker4.puzzle.tantrix.model.TilePlacementList

            optimizer.doOptimization(strategy, initialGuess, SOLVED_THRESH);

        solution_ =
            new TantrixBoard(((TantrixPath)solution).getTilePlacements(), board.getPrimaryColor());

        TilePlacementList moves;
        if (evaluateFitness(solution) >= SOLVED_THRESH) {
            moves = ((TantrixPath)solution).getTilePlacements();
        } else {
            moves = null;
        }
View Full Code Here

Examples of com.barrybecker4.puzzle.tantrix.model.TilePlacementList

     * @throws IllegalStateException if tiles do not form a primary path.
     */
    public TantrixPath(TilePlacementList tiles, PathColor primaryColor) {
        assert primaryColor != null;
        primaryPathColor_ = primaryColor;
        tiles_ = new TilePlacementList(tiles);

        if (!hasOrderedPrimaryPath(tiles, primaryColor)) {
            throw new IllegalStateException(
                    "The following " + tiles.size() +" tiles must form a primary path :\n" + tiles);
        }
View Full Code Here

Examples of com.barrybecker4.puzzle.tantrix.model.TilePlacementList

     * @param startIndex  tile to add first
     * @param endIndex  tile to add last
     * @return sub path
     */
    public TantrixPath subPath(int startIndex, int endIndex) {
        TilePlacementList pathTiles = new TilePlacementList();
        if (startIndex <= endIndex) {
            for (int i = startIndex; i <= endIndex; i++) {
                pathTiles.add(this.tiles_.get(i));
            }
        }
        else  {
            for (int i = startIndex; i >= endIndex; i--) {
                pathTiles.add(this.tiles_.get(i));
            }
        }
        return new TantrixPath(pathTiles, primaryPathColor_);
    }
View Full Code Here

Examples of com.barrybecker4.puzzle.tantrix.model.TilePlacementList

     */
    private List<TantrixPath> findPermutedPaths(double radius) {

        List<TantrixPath> permutedPaths = new ArrayList<TantrixPath>();
        PathPivotPermuter permuter = new PathPivotPermuter(path);
        TilePlacementList tiles = path.getTilePlacements();
        int numTiles = path.size();

        if (radius >= 0.4) {
            for (int i = 1; i < numTiles - 1; i++) {
                addAllPermutedPaths(permuter.findPermutedPaths(i, i), permutedPaths);
            }
        }
        else if (radius >= 0.1) {
            // to avoid trying too many paths, increment by something more than one if many tiles.
            int inc = 1 + path.size()/4;
            // n^2 * 7 permuted paths will be added.
            for (int pivot1 = 1; pivot1 < numTiles-1; pivot1+=rand(inc)) {
                for (int pivot2 = pivot1; pivot2 < numTiles-1; pivot2+=rand(inc)) {
                    addAllPermutedPaths(permuter.findPermutedPaths(pivot1, pivot2), permutedPaths);
                }
            }
        }
        else if (permutedPaths.isEmpty()) {
            List<PathType> types = Arrays.asList(PathType.values());
            Collections.shuffle(types, MathUtil.RANDOM);
            Iterator<PathType> typeIter = types.iterator();

            do {
                SameTypeTileMixer mixer = new SameTypeTileMixer(typeIter.next(), path);
                addAllPermutedPaths(mixer.findPermutedPaths(), permutedPaths);
            } while (typeIter.hasNext());
        }

        // as a last resort use this without checking for it in the cache.
        if (permutedPaths.isEmpty()) {

            List<TantrixPath> paths;
            do {
                int pivotIndex1 = 1 + MathUtil.RANDOM.nextInt(tiles.size()-2);
                int pivotIndex2 = 1 + MathUtil.RANDOM.nextInt(tiles.size()-2);
                paths = permuter.findPermutedPaths(pivotIndex1, pivotIndex2);
                System.out.println("paths unexpectedly empty! when p1="+pivotIndex1 + " p2="+ pivotIndex2);
            } while (paths.isEmpty());
            return paths;
        }
View Full Code Here

Examples of com.barrybecker4.puzzle.tantrix.model.TilePlacementList

     * Throw an error if not. Should not change the order if the tiles are already arranged on a path.
     * @param tantrix
     * @return the tiles in path order. Error if no path.
     */
    public TilePlacementList reorder(Tantrix tantrix) {
        TilePlacementList tiles = new TilePlacementList(tantrix);
        if (tantrix.size() < 2) {
            return tiles;
        }

        return reorderTiles(tiles, tantrix);
View Full Code Here

Examples of com.barrybecker4.puzzle.tantrix.model.TilePlacementList

        }
        if (newList.size() != tantrix.size()) {
             throw new IllegalStateException("Did not find a path among " + tileList);
        }

        return new TilePlacementList(newList);
    }
View Full Code Here

Examples of com.barrybecker4.puzzle.tantrix.model.TilePlacementList

     * @param loc the location to try and place it at.
     * @return the placements (at most 3) if any could be found, else an empty list.
     */
    public TilePlacementList getFittingPlacements(HexTile tile, Location loc) {
        TilePlacement placement = new TilePlacement(tile, loc, Rotation.ANGLE_0);
        TilePlacementList validPlacements = new TilePlacementList();

        for (int i = 0; i < NUM_SIDES; i++) {
            if (isFit(placement)) {
                validPlacements.add(placement);
            }
            placement = placement.rotate();
        }
        return validPlacements;
    }
View Full Code Here

Examples of com.barrybecker4.puzzle.tantrix.model.TilePlacementList

     * @return the whole path rotated and translated so that the same end is connected at
     *   the a different point the pivot tile. There is only one other valid point that it can connect to.
     */
    @Override
    public TantrixPath mutate(TilePlacement pivotTile, TantrixPath subPath) {
        TilePlacementList tiles = new TilePlacementList();
        TilePlacementList subPathTiles = subPath.getTilePlacements();
        TilePlacement firstTile = subPathTiles.get(0);
        Location firstTileLocation = firstTile.getLocation();
        int numRotations = findRotationsToSwapLocation(firstTileLocation, pivotTile);
        int directionToPivot = findOutgoingDirection(firstTile, pivotTile.getLocation());

        Location newLocation = HexUtil.getNeighborLocation(pivotTile.getLocation(), numRotations);
        Location origLocation = pivotTile.getLocation();

        numRotations = numRotations + 3 - directionToPivot;
        Rotation tileRotation = firstTile.getRotation().rotateBy(numRotations);

        TilePlacement previousTilePlacement = new TilePlacement(firstTile.getTile(), newLocation, tileRotation);
        tiles.add(previousTilePlacement);

        // this part almost the same as reverser
        for (int i=1; i<subPathTiles.size(); i++) {
            TilePlacement currentTile = subPathTiles.get(i);

            newLocation = findOtherOutgoingLocation(previousTilePlacement, origLocation);

            Rotation tileRotation1 = currentTile.getRotation().rotateBy(numRotations);
            TilePlacement currentTilePlacement = new TilePlacement(currentTile.getTile(), newLocation, tileRotation1);
View Full Code Here

Examples of com.barrybecker4.puzzle.tantrix.model.TilePlacementList

    }

    public TantrixPath permute(List<Integer> oldIndices, List<Integer> newIndices) {
        TantrixPath permutedPath = originalPath.copy();

        TilePlacementList auxList = new TilePlacementList();

        //System.out.println("new indices = " + newIndices);
        //System.out.println("old indices = " + oldIndices);

        for (int i=0; i<oldIndices.size(); i++) {
           auxList.set(i, permutedPath.getTilePlacements().get(newIndices.get(i)));
        }

        PrimaryPathFitter fitter =
                new PrimaryPathFitter(permutedPath.getTilePlacements(), color);

        TilePlacementList origPlacements = permutedPath.getTilePlacements();
        for (int i=0; i<newIndices.size(); i++) {

            int oldIndex = oldIndices.get(i);
            TilePlacement oldPlacement = auxList.get(i);
            TilePlacement newPlacement =
                    findNewPlacement(oldPlacement.getTile(), origPlacements.get(oldIndex).getLocation(), fitter);
            origPlacements.set(oldIndex, newPlacement);
        }

        return permutedPath;
    }
View Full Code Here

Examples of com.barrybecker4.puzzle.tantrix.model.TilePlacementList

     *   the same point on the pivot tile.
     */
     @Override
     public TantrixPath mutate(TilePlacement pivotTile, TantrixPath subPath) {

         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
         for (int i = subPathTiles.size()-2; i >= 0; i--) {
             TilePlacement currentTile = subPathTiles.get(i);

             newLocation = findOtherOutgoingLocation(previousTilePlacement, origLocation);

             tileRotation = currentTile.getRotation().rotateBy(numRotations);
             TilePlacement currentTilePlacement = new TilePlacement(currentTile.getTile(), newLocation, tileRotation);
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.