Package com.barrybecker4.puzzle.tantrix.model

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


     * @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

    }

    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

     *   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

     * @return null if the resulting permuted path is not valid (i.e. has overlaps)
     */
    private TantrixPath createPermutedPath(TantrixPath subPath1, TantrixPath subPath2) {

        // add tiles from the first path in reverse order
        TilePlacementList tiles = new TilePlacementList();
        for (TilePlacement p : subPath1.getTilePlacements()) {
            tiles.addFirst(p);
        }

        tiles.addAll(pivotPath.getTilePlacements());
        tiles.addAll(subPath2.getTilePlacements());
        TantrixPath path = null;
        if (isValid(tiles)) {
            assert (TantrixPath.hasOrderedPrimaryPath(tiles, path_.getPrimaryPathColor())) :
                    "out of order path tiles \nsubpath1" + subPath1 + "\npivot="+ pivotPath
                            + "\nsubpath2=" + subPath2 + "\norigPath="+ path_;
View Full Code Here

        initialize(type, path);
    }

    private void initialize(PathType type, TantrixPath path) {

        TilePlacementList tiles = path.getTilePlacements();
        primColor = path.getPrimaryPathColor();

        for (int i=0; i<path.size(); i++) {
            HexTile tile = tiles.get(i).getTile();

            if (isTileType(tile, type)) {
                add(i);
            }
        }
View Full Code Here

        int numTiles = path.size();
        double distance = path.getEndPointDistance();
        boolean isLoop = distance == 0 && path.isLoop();

        ConsistencyChecker checker = new ConsistencyChecker(path.getTilePlacements(), path.getPrimaryPathColor());
        int numFits = checker.numFittingTiles();
        boolean allFit = numFits == numTiles;
        boolean consistentLoop = isLoop && allFit;
        boolean perfectLoop = false;
        double compactness = determineCompactness(path);
View Full Code Here

        boolean perfectLoop = false;
        double compactness = determineCompactness(path);

        if (consistentLoop) {
            Tantrix tantrix = new Tantrix(path.getTilePlacements());
            InnerSpaceDetector innerDetector = new InnerSpaceDetector(tantrix);
            perfectLoop = !innerDetector.hasInnerSpaces();
            //System.out.println("perfect loop");
        }

        double fitness =
                LOOP_PROXIMITY_WEIGHT * (numTiles - distance) / (0.1 + numTiles)
View Full Code Here

                               boolean useConcurrency) {
        super(board);
        puzzlePanel_ = puzzlePanel;
        strategy = useConcurrency ? OptimizationStrategyType.CONCURRENT_GENETIC_SEARCH :
                                    OptimizationStrategyType.GENETIC_SEARCH;
        evaluator = new PathEvaluator();
    }
View Full Code Here

     * @return list of moves to a solution.
     */
    @Override
    public TilePlacementList solve()  {

        ParameterArray initialGuess = new TantrixPath(board);
        assert(initialGuess.size() > 0) : "The random path should have some tiles!";
        long startTime = System.currentTimeMillis();

        Optimizer optimizer = new Optimizer(this);
        optimizer.setListener(this);

View Full Code Here

TOP

Related Classes of com.barrybecker4.puzzle.tantrix.model.TilePlacementList

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.