Package koth.util

Examples of koth.util.Vector


        Algorithms.sort(Algorithms.ReversedComparator.<Integer>getInstance(), dists, allies);
        // Most endangered pawn must flee!
        for (int i = 0; i < allies.size(); ++i) {
            Pawn a = allies.get(i);
            for (Move m : Move.getNonzeros()) {
                Vector t = a.getLocation().add(m);
                if (game.isFree(t) && distanceToFoes(t, foes) > dists.get(i))
                    return new Action(a, m);
            }
        }
        // We can't flee anymore :'(
View Full Code Here


     * @see <a href=http://en.wikipedia.org/wiki/Maze_generation_algorithm#Randomized_Prim.27s_algorithm>Wikipedia</a>
     */
    public static Set<Vector> generate(int size, float redundantProbability, Random random) {
        // Add origin as a maze tile
        Set<Vector> tiles = new HashSet<Vector>();
        tiles.add(new Vector());
        Set<Vector> walls = new HashSet<Vector>();
        walls.add(new Vector(1, 0));
        walls.add(new Vector(-1, 0));
        walls.add(new Vector(0, 1));
        walls.add(new Vector(0, -1));
        // Repeat specified number of times
        for (int n = 1; n < size;) {
            // Choose randomly a wall
            Vector wall = Algorithms.random(walls, random);
            walls.remove(wall);
            // Check if both endpoints already exist
            Move dir = wall.getX() % 2 == 0 ? Move.North : Move.East;
            Vector a = wall.add(dir), b = wall.sub(dir);
            boolean ac = tiles.contains(a), bc = tiles.contains(b);
            if (ac && bc && random.nextFloat() >= redundantProbability)
                continue;
            // Add tiles to maze
            tiles.add(wall);
            ++n;
            if (!ac) {
                tiles.add(a);
                ++n;
            }
            if (!bc) {
                tiles.add(b);
                ++n;
            }
            // Add neighbors as walls
            for (Move m : Move.getNonzeros()) {
                Vector am = a.add(m);
                if (!tiles.contains(am))
                    walls.add(am);
                Vector bm = b.add(m);
                if (!tiles.contains(bm))
                    walls.add(bm);
            }
        }
        return tiles;
View Full Code Here

        long score = Long.MAX_VALUE;
        for (int n = 0; n < 50; ++n) {
            List<Vector> test = new ArrayList<Vector>(teams);
            long cost = 0;
            for (int i = 0; i < teams; ++i) {
                Vector p = Algorithms.random(tiles, random);
                test.add(p);
                for (int j = 0; j < i; ++j) {
                    long d = max - dists.get(p).get(test.get(j));
                    cost += d * d;
                }
View Full Code Here

            throw new IllegalArgumentException();
        // Create tiles
        Set<Vector> tiles = new HashSet<Vector>();
        for (int x = 0; x < size; ++x)
            for (int y = 0; y < size; ++y)
                tiles.add(new Vector(x, y));
        // Add all tiles as spawns
        List<Set<Vector>> spawns = new ArrayList<Set<Vector>>();
        for (int i = 0; i < teams; ++i)
            spawns.add(tiles);
        return new Board(tiles, spawns);
View Full Code Here

            for (int y = -n; y <= n; ++y) {
                int style = at(x, y, outer, inner, bridgeWidth, bridgeLength);
                if (style < 0)
                    continue;
                if (style == 0)
                    tiles.add(new Vector(x, y));
                else
                    spawns.get(style - 1).add(new Vector(x, y));
            }
        return new Board(tiles, spawns);
    }
View Full Code Here

                    tilesCopy.addAll(s);
                }
        this.tiles = Collections.unmodifiableSet(tilesCopy);
        this.spawns = Collections.unmodifiableList(spawnsCopy);
        if (this.tiles.isEmpty())
            min = max = new Vector();
        else {
            Iterator<Vector> it = this.tiles.iterator();
            Vector i = it.next(), min = i, max = i;
            while (it.hasNext()) {
                i = it.next();
                min = min.min(i);
                max = max.max(i);
            }
View Full Code Here

    @Override
    public String toString() {
        String txt = "";
        for (int y = max.getY(); y >= min.getY(); --y) {
            for (int x = min.getX(); x <= max.getX(); ++x)
                txt += isTile(new Vector(x, y)) ? '.' : ' ';
            txt += "\r\n";
        }
        return txt;
    }
View Full Code Here

        return null;
    }

    private void move(Listener listener, HashSet<Pawn> pawns, Pawn pawn, Move move) {
        // 1. Test if out of world -> Dies instantly
        Vector dest = pawn.getLocation().add(move.getDelta());
        Pawn next = pawn;
        Pawn target = null;
        if (board.isVoid(dest))
            next = next.damaged(next.getHealth());
        else {
View Full Code Here

    public String toString() {
        String txt = "";
        for (int y = board.getMax().getY(); y >= board.getMin().getY(); --y) {
            for (int x = board.getMin().getX(); x <= board.getMax().getX(); ++x) {
                char c = ' ';
                Vector l = new Vector(x, y);
                Pawn p = getPawn(l);
                if (p != null) {
                    assert p.getTeam() >= 0 && p.getTeam() < 10;
                    c = (char)(p.getTeam() + '0');
                } else if (board.isTile(l))
View Full Code Here

TOP

Related Classes of koth.util.Vector

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.