Package com.barrybecker4.common.geometry

Examples of com.barrybecker4.common.geometry.MutableIntLocation


    }

    @Override
    protected Player createPlayer() {
        int ct = table_.getRowCount();
        Planet planet = new Planet((char)('A'+ct), GalacticPlayer.DEFAULT_NUM_SHIPS, 10, new ByteLocation(0,0));
        Color newColor = MultiGamePlayer.getNewPlayerColor(getPlayers());
        GalacticPlayer player = GalacticPlayer.createGalacticPlayer(
                                             "Admiral "+(ct+1), planet, newColor, true);
        planet.setOwner(player);
        return player;


    public void render(Graphics2D g2, TilePlacement tilePlacement,
                       Location topLeftCorner, double radius) {

        if (tilePlacement == null) return;
        boolean isOddRow = tilePlacement.getLocation().getRow() % 2 == 1;
        Location location =
            tilePlacement.getLocation().decrementOnCopy(topLeftCorner);

        double x = radius/2
                + ((location.getCol() - (isOddRow ? -0.25:  -0.75)) * 2 * radius * HexUtil.ROOT3D2);
        double y = radius/+ TOP_MARGIN
                + ((location.getRow() + 0.6) * 3.0 * radius / 2.0);

        Point point = new Point((int)x, (int)y);
        drawHexagon(g2, point, radius);
        pathRenderer.drawPath(g2, 0, tilePlacement, point, radius);
        pathRenderer.drawPath(g2, 1, tilePlacement, point, radius);

        hexRadius = (1.0 - MARGIN_FRAC) * minEdge / (board.getEdgeLength() * ROOT3 * .9);

        setHints(g2);
        drawGrid(g2, board);

        Location topLeftCorner = board.getBoundingBox().getTopLeftCorner();

        for (Location loc : board.getTantrixLocations()) {
            TilePlacement placement = board.getTilePlacement(loc);
            tileRenderer.render(g2, placement, topLeftCorner, hexRadius);
        }

        currentLocation_.setLocation( currentLocation_.getX() + v.getX(),  currentLocation_.getY() + v.getY());

        // if the destination planet lies on the line from where we were to where we are now,
        // then we overshot. set the currentLocation to the destination planet location.
        Line2D.Double line = new Line2D.Double(oldLocation, currentLocation_);
        Location dLoc = destination_.getLocation();
        if (line.intersects(dLoc.getCol(),  dLoc.getRow(), INTERSECT_TOLERANCE, INTERSECT_TOLERANCE)) {
            currentLocation_.setLocation(dLoc.getCol(), dLoc.getRow());
            // the order never leaves once it has arrived. The order will be destroyed.
            hasArrived_ = true;
        }
    }

    /**
     * @return a unit vector pointing in the current direction of movement.
     */
    private Point2D getUnitDirection() {
        Location dLoc = destination_.getLocation();
        Point2D unitVec =
                new Point2D.Double(dLoc.getCol() - currentLocation_.getX(), dLoc.getRow() - currentLocation_.getY());
        double dist = unitVec.distance(new Point2D.Double(0, 0));
        unitVec.setLocation(unitVec.getX()/dist, unitVec.getY()/dist);
        return unitVec;
    }

        for (final Player player : players) {
            for (Order order : ((GalacticPlayer) player).getOrders()) {

                int margin = getMargin();

                Location begin = order.getOrigin().getLocation();
                Point2D end = order.getCurrentLocation();

                g2.setColor(order.getOwner().getColor());
                int beginX = (int) (margin + cellSize * (begin.getCol() - 0.5));
                int beginY = (int) (margin + cellSize * begin.getRow() - 0.5);
                int endX = (int) (margin + cellSize * (end.getX() - 0.5));
                int endY = (int) (margin + cellSize * (end.getY() - 0.5));

                g2.drawLine(beginX, beginY, endX, endY);


    /**
     * Find the potential for one of the bbox's rows or columns.
     * @return eye potential for row and column at pos
     */
    public float getRunPotential(Location position, int rowInc, int colInc, int maxRow, int maxCol) {
        MutableIntLocation pos = new MutableIntLocation(position);
        float runPotential = 0;
        int breadth = (rowInc == 1) ? (maxRow - pos.getRow()) : (maxCol - pos.getCol());
        GoBoardPosition startSpace = (GoBoardPosition) board_.getPosition( pos );

        do {
            GoBoardPosition nextSpace = (GoBoardPosition) board_.getPosition( pos );
            GoBoardPosition firstSpace = nextSpace;
            boolean containsEnemy = false;
            int runLength = 0;
            boolean player1 = groupString_.isOwnedByPlayer1();
            while (inRun(pos, maxRow, maxCol, nextSpace, player1)) {
                if (containsEnemy(player1, nextSpace)) {
                    containsEnemy = true;
                }
                runLength++;
                pos.increment(rowInc, colInc);
                nextSpace = (GoBoardPosition) board_.getPosition( pos );
            }
            boolean bounded = isBounded(startSpace, nextSpace, firstSpace);
            runPotential += accrueRunPotential(rowInc, pos, breadth, firstSpace, containsEnemy, runLength, bounded);

            pos.increment(rowInc, colInc);

        } while (pos.getCol() <= maxCol && pos.getRow() <= maxRow);

        return runPotential;
    }

    public static void initialize(String localeName, List<String> resourcePaths, ILog logger) {
        assert resourcePaths != null;
        assert logger != null;
        logger_ = logger;

        messageContext_ = new MessageContext(resourcePaths);
        messageContext_.setLogger(logger_);
        messageContext_.setDebugMode(debug_);
        messageContext_.setLocale(localeName);
    }

     * @return the cut points
     */
    public double[] getCutPoints(Range range, int maxNumTicks) {

        validateArguments(range);
        Range finalRange = new Range(range);
        if (range.getExtent() <= MIN_RANGE) {
            finalRange.add(range.getMin() + MIN_RANGE);
        }

        List<Double> positions = new ArrayList<Double>(10);

        if (finalRange.getExtent() < MIN_RANGE) {
            positions.add(finalRange.getMin());
        } else {
            determineCutPoints(maxNumTicks, finalRange, positions);
        }

        double[] result = new double[positions.size()];

    void determineCutPoints(int maxTicks, Range finalRange, List<Double> positions) {

        double extent = Rounder.round(finalRange.getExtent(), false);
        double d = Rounder.round(extent / (maxTicks - 1), true);
        Range roundedRange =
                new Range(Math.floor(finalRange.getMin() / d) * d, Math.ceil(finalRange.getMax() / d) * d);

        addPoints(positions, roundedRange, finalRange, d);
    }

TOP

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

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.