Package com.barrybecker4.puzzle.tantrix.model

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


     * @return true if there exists a primary path or loop.
     */
    public static boolean hasOrderedPrimaryPath(TilePlacementList tiles, PathColor primaryColor) {
        if (tiles.size() < 2) return true;

        TilePlacement lastTile = tiles.get(0);

        for (int i=1; i<tiles.size(); i++)  {
            TilePlacement currentTile = tiles.get(i);
            Map<Integer, Location> outgoing = currentTile.getOutgoingPathLocations(primaryColor);
            if (!outgoing.containsValue(lastTile.getLocation())) {
                return false;
            }
            lastTile = currentTile;
        }
View Full Code Here


            return 1000.0;
        }
        if (tiles_.size() == 1) {
            return 1.0;
        }
        TilePlacement first = getFirst();
        TilePlacement last = getLast();
        Location end1 = first.getLocation();
        Location end2 = last.getLocation();

        // if they touch return distance of 0
        if (first.getOutgoingPathLocations(primaryPathColor_).containsValue(end2)
                && last.getOutgoingPathLocations(primaryPathColor_).containsValue(end1)) {
            return 0;
        }

        return HexUtil.distanceBetween(end1, end2);
    }
View Full Code Here

    /** make an ordered path list from the tiles in tileList */
    private TilePlacementList reorderTiles(TilePlacementList tileList, Tantrix tantrix) {

        LinkedList<TilePlacement> newList = new LinkedList<TilePlacement>();
        TilePlacement lastAdded = tileList.remove(0);
        newList.add(lastAdded);

        Iterator<Location> outgoing =
                lastAdded.getOutgoingPathLocations(primaryPathColor_).values().iterator();

        addForwardTiles(newList, outgoing.next(), tileList, tantrix);
        if (outgoing.hasNext())  {
            addBackwardTiles(newList, outgoing.next(), tileList, tantrix);
        }
View Full Code Here

    }

    /** add forward or backward tiles to the beginning or end of path respectively */
    private void addTiles(LinkedList<TilePlacement> newList, Location outLocation,
                          TilePlacementList remaining, Tantrix tantrix, boolean forward) {
        TilePlacement nextPlacement = tantrix.get(outLocation);

        if (nextPlacement != null && !newList.contains(nextPlacement) && !remaining.isEmpty()) {
            if (forward)
                newList.addLast(nextPlacement);
            else {
                newList.addFirst(nextPlacement);
            }
            remaining.remove(nextPlacement);
            Collection<Location> outgoing = nextPlacement.getOutgoingPathLocations(primaryPathColor_).values();
            for (Location loc : outgoing) {
                addTiles(newList, loc, remaining, tantrix, forward);
            }
        }
    }
View Full Code Here

        if (!board.getUnplacedTiles().isEmpty()) {
            return false;
        }

        int numVisited = 0;
        TilePlacement lastTilePlaced = board.getLastTile();
        TilePlacement currentTile = lastTilePlaced;
        TilePlacement previousTile = null;
        TilePlacement nextTile;

        do {
            nextTile = findNeighborTile(currentTile, previousTile);
            previousTile = currentTile;
            currentTile = nextTile;
View Full Code Here

    private TilePlacement findNeighborTile(TilePlacement currentPlacement, TilePlacement previousTile) {

        for (byte i = 0; i < NUM_SIDES; i++) {
            PathColor color = currentPlacement.getPathColor(i);
            if (color == board.getPrimaryColor()) {
                TilePlacement nbr = board.getNeighbor(currentPlacement, i);
                if (nbr != null && !nbr.equals(previousTile)) {
                    return nbr;
                }
            }
        }
        return null;
View Full Code Here

    @Override
    public boolean isFit(TilePlacement placement) {
        boolean primaryPathMatched = false;

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

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

                if (pathColor == nbr.getPathColor((byte)(i+3))) {
                    if (pathColor == primaryColor) {
                        primaryPathMatched = true;
                    }
                }  else {
                    return false;
View Full Code Here

     * @param tile the tile to place.
     * @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

    @Override
    public boolean isFit(TilePlacement placement) {

        boolean fits = true;
        for (byte i = 0; i < NUM_SIDES; i++) {
            TilePlacement nbr = tantrix.getNeighbor(placement, i);

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

                if ((pathColor == primaryColor || nbrColor == primaryColor) && pathColor != nbrColor) {
                    fits = false;
                }
            }
View Full Code Here

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

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.