Package com.barrybecker4.common.geometry

Examples of com.barrybecker4.common.geometry.Box


    /**
     * @return all the empty positions on the border
     */
    private Set<Location> findEmptyBorderPositions() {

        Box bbox = tantrix.getBoundingBox();
        Set<Location> empties = new HashSet<Location>();

        for (int i = bbox.getMinCol(); i <= bbox.getMaxCol(); i++) {
            Location loc = new ByteLocation(bbox.getMinRow(), i);
            if (tantrix.get(loc) == null)  {
                empties.add(loc);
            }
            loc = new ByteLocation(bbox.getMaxRow(), i);
            if (tantrix.get(loc) == null)  {
                empties.add(loc);
            }
        }

        for (int i = bbox.getMinRow() + 1; i < bbox.getMaxRow(); i++) {
            Location loc = new ByteLocation(i, bbox.getMinCol());
            if (tantrix.get(loc) == null)  {
                empties.add(loc);
            }
            loc = new ByteLocation(i, bbox.getMaxCol());
            if (tantrix.get(loc) == null)  {
                empties.add(loc);
            }
        }

        int totalLocs = (bbox.getHeight() + 1) * (bbox.getWidth() + 1);
        assert (totalLocs == tantrix.size() || empties.size() > 0):
                "We should have found at least one empty position on the border. Num Tiles ="
                + tantrix.size() + " bbox area = " + bbox.getArea();
        return empties;
    }
View Full Code Here


    /**
     * @return all the empty neighbor positions next to the current one.
     */
    private List<Location> findEmptyNeighborLocations(Location loc) {
        List<Location> emptyNbrLocations = new LinkedList<Location>();
        Box bbox = tantrix.getBoundingBox();

        for (byte i=0; i< NUM_SIDES; i++) {

            Location nbrLoc = HexUtil.getNeighborLocation(loc, i);
            if (tantrix.get(nbrLoc) == null && bbox.contains(nbrLoc)) {
                emptyNbrLocations.add(nbrLoc);
            }
        }
        return emptyNbrLocations;
    }
View Full Code Here

    /**
     * @param visited set of visited empties.
     * @return true if any empties in the tantrix bbox are not visited
     */
    private boolean allEmptiesVisited(Set<Location> visited) {
        Box bbox = tantrix.getBoundingBox();
        for (int i = bbox.getMinRow(); i < bbox.getMaxRow(); i++) {
            for (int j = bbox.getMinCol(); j <= bbox.getMaxCol(); j++)  {
                Location loc = new ByteLocation(i, j);
                if (tantrix.get(loc) == null && !visited.contains(loc))  {
                    return false;
                }
            }
View Full Code Here

        List<Location> emptyNbrLocations = new LinkedList<Location>();
        for (byte i=0; i< NUM_SIDES; i++) {

            Location nbrLoc = HexUtil.getNeighborLocation(placement.getLocation(), i);
            if (tantrix.get(nbrLoc) == null) {
                Box newBox = new Box(boundingBox, nbrLoc);
                if (newBox.getMaxDimension() <= maxHalfPathLength) {
                    emptyNbrLocations.add(nbrLoc);
                    boundingBox = newBox;
                }
            }
        }
View Full Code Here

        for (byte i=0; i< NUM_SIDES; i++) {
            PathColor color = previous.getPathColor(i);
            if (color == primaryColor) {
                TilePlacement nbr = tantrix.getNeighbor(previous, i);
                if (nbr != null && !visited.contains(nbr.getLocation())) {
                    Box newBox = new Box(boundingBox, nbr.getLocation());
                    if (newBox.getMaxDimension() < maxHalfPathLength) {
                        pathNbrs.add(nbr);
                        visited.add(nbr.getLocation());
                        boundingBox = newBox;
                    }
                }
View Full Code Here

        IntLocation topLeft = box.getTopLeftCorner();
        g2.drawRect(topLeft.getX(), topLeft.getY(), box.getWidth(), box.getHeight());
    }

    private Box findBox(double aspectRatio, boolean keepAspectRatio) {
        Box box = new Box(firstCorner, secondCorner);

        IntLocation topLeft = box.getTopLeftCorner();
        int width = box.getWidth();
        int height = box.getHeight();

        if (keepAspectRatio)  {
            if (width > height) {
                height = (int)(width / aspectRatio);
            } else {
                width = (int)(height * aspectRatio);
            }
            box = new Box(topLeft, new IntLocation(topLeft.getY() + height, topLeft.getX() + width));
        }
        return box;
    }
View Full Code Here

    private GoEyeSet findEyesFromCandidates(GoBoardPositionLists excludedSpaceLists) {
        GoEyeSet eyes = new GoEyeSet();
        boolean ownedByPlayer1 = group_.isOwnedByPlayer1();
        GroupAnalyzer groupAnalyzer = analyzerMap_.getAnalyzer(group_);

        Box innerBox = createBoxExcludingBorder(boundingBox_);
        for ( int r = innerBox.getMinRow(); r < innerBox.getMaxRow(); r++ ) {
            for ( int c = innerBox.getMinCol(); c < innerBox.getMaxCol(); c++ ) {

                // if the empty space is already marked as being an eye, skip
                GoBoardPosition space = (GoBoardPosition) board_.getPosition( r, c );
                assert space != null : "pos r="+r +" c="+c;
                if ( !space.isVisited() && space.isUnoccupied() && !space.isInEye() ) {
View Full Code Here

        int maxCol = board_.getNumCols();

        int innerMinRow = (box.getMinRow() > 1) ? Math.min(box.getMinRow() + 1, maxRow) : 1;
        int innerMinCol = (box.getMinCol() > 1) ? Math.min(box.getMinCol() + 1, maxCol) : 1;

        return new Box(
                innerMinRow,
                innerMinCol,
                (box.getMaxRow() < maxRow) ? Math.max(box.getMaxRow(), innerMinRow) : maxRow + 1,
                (box.getMaxCol() < maxCol) ?  Math.max(box.getMaxCol(), innerMinCol) : maxCol + 1
        );
View Full Code Here

                if (row > rMax) rMax = row;
                if (col < cMin) cMin = col;
                if (col > cMax) cMax = col;
            }
        }
        return (rMin > rMax) ? new Box(0, 0, 0, 0) : new Box(rMin, cMin, rMax, cMax);
    }
View Full Code Here

        //float ratio = (float)board_.getMoveList().getNumMoves() / board_.getTypicalNumMoves();

        int min = 1;
        int rMax = board_.getNumRows();
        int cMax = board_.getNumCols();
        Box box = new Box(min, min, rMax, cMax);

        GoBoardPositionLists emptyLists = new GoBoardPositionLists();

        for ( int i = min; i <= rMax; i++ )  {
           for ( int j = min; j <= cMax; j++ ) {
View Full Code Here

TOP

Related Classes of com.barrybecker4.common.geometry.Box

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.