Examples of TilePlacement


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

     */
    public int numPrimaryFits(TilePlacement placement) {

        int numFits = 0;
        for (byte i = 0; i < NUM_SIDES; i++) {
            TilePlacement nbr = tantrix.getNeighbor(placement, i);

            if (nbr != null) {
                PathColor pathColor = placement.getPathColor(i);

                if (pathColor == primaryColor && pathColor == nbr.getPathColor(i+3)) {
                    numFits++;
                }
            }
        }
        assert numFits <= 2 : "There cannot be more than 2 primary path fits.";
View Full Code Here

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

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

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

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

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

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

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

Examples of com.jcloisterzone.board.TilePlacement

        if (sym == TileSymmetry.S4) {
            List<TilePlacement> options = new ArrayList<>(action.getOptions());
            Collections.sort(options);
            int size = options.size();
            for (int i = 0; i < size; i++) {
                TilePlacement tp = options.get(i);
                if (i == 0 || !options.get(i-1).getPosition().equals(tp.getPosition())) {
                    queue.push(new TilePlacementChoice(choice, savePoint, action, tp));
                }
            }
        } else {
            for (TilePlacement tp : action.getOptions()) {
View Full Code Here

Examples of com.jcloisterzone.board.TilePlacement

        getServer().pass();
        return true;
    }

    protected boolean selectDummyTilePlacement(TilePlacementAction action) {
        TilePlacement nearest = null;
        Position p0 = new Position(0, 0);
        int min = Integer.MAX_VALUE;
        for (TilePlacement tp : action) {
            int dist = tp.getPosition().squareDistance(p0);
            if (dist < min) {
                min = dist;
                nearest = tp;
            }
        }
        getServer().placeTile(nearest.getRotation(), nearest.getPosition());
        return true;
    }
View Full Code Here

Examples of com.jcloisterzone.board.TilePlacement

    @Override
    public void enter() {
      TilePlacementAction action = new TilePlacementAction(game.getCurrentTile());
      for (Entry<Position, Set<Rotation>> entry: getBoard().getAvailablePlacements().entrySet()) {
        for (Rotation rotation : entry.getValue()) {
          action.add(new TilePlacement(entry.getKey(), rotation));
        }
      }
        game.post(new SelectActionEvent(getActivePlayer(), action, false));
    }
View Full Code Here

Examples of com.jcloisterzone.board.TilePlacement

    @Override
    public void mouseClicked(MouseEvent e, Position p) {
        if (e.getButton() == MouseEvent.BUTTON1) {
            if (getPreviewPosition() != null && isActive() && allowedRotation) {
                e.consume();
                action.perform(getClient().getServer(), new TilePlacement(p, previewRotation));
            }
        }
    }
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.