Package com.barrybecker4.puzzle.tantrix.model

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


     */
    @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);
            assert fits(currentTilePlacement, previousTilePlacement) :
                    " current=" + currentTilePlacement +" (" + i  +") did not fit with " + previousTilePlacement
                            + " when swapping " + subPath + " at pivot = "+ pivotTile + " with primColor = " + primaryColor
                            + " The outgoing locations from curent are "  + currentTilePlacement.getOutgoingPathLocations(primaryColor);

            tiles.add(currentTilePlacement);
            origLocation = previousTilePlacement.getLocation(); //currentTilePlacement.getLocation();
            previousTilePlacement = currentTilePlacement;
        }
View Full Code Here


        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

    /**
     * @return The new placement with the tile rotated so it fits at the new location.
     */
    private TilePlacement findNewPlacement(HexTile tile, Location location, PrimaryPathFitter fitter) {
        TilePlacement newPlacement =
                new TilePlacement(tile, location, Rotation.ANGLE_0);
        int ct = 0;
        while (!fitter.isFit(newPlacement) && ct < HexTile.NUM_SIDES) {
            //System.out.println("new placement = " + newPlacement);
            newPlacement = newPlacement.rotate();
            ct++;
        }
        if (ct >= HexTile.NUM_SIDES) {
            throw new IllegalStateException("could not fit " + tile + " at " + location + " in " + fitter.getTantrix());
        }
View Full Code Here

     @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);
             assert fits(currentTilePlacement, previousTilePlacement) :
                " current=" + currentTilePlacement +" (" + i  +") did not fit with " + previousTilePlacement
                        + " when reversing " + subPath + " at pivot = "+ pivotTile;

             tiles.add(currentTilePlacement);
View Full Code Here

     */
    private List<TantrixPath> createPermutedPathList(TantrixPath subPath1, TantrixPath subPath2) {
        PathColor primaryColor = path_.getPrimaryPathColor();
        SubPathMutator swapper = new SubPathSwapper(primaryColor);
        SubPathMutator reverser = new SubPathReverser(primaryColor);
        TilePlacement firstPivot = pivotPath.getFirst();
        TilePlacement lastPivot = pivotPath.getLast();

        TantrixPath subPath1Reversed = reverser.mutate(firstPivot, subPath1);
        TantrixPath subPath2Reversed = reverser.mutate(lastPivot, subPath2);
        TantrixPath subPath1Swapped = swapper.mutate(firstPivot, subPath1);
        TantrixPath subPath2Swapped = swapper.mutate(lastPivot, subPath2);
View Full Code Here

            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

        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.TilePlacement

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.