Package environment

Examples of environment.Cell


            Logger.getLogger(GUIController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void ejectAgents(Agent tracer) {
        Cell beforeDeathCell = tracer.getUnit().getLastOccupiedCell();
        short xleft = beforeDeathCell.getX();
        short xright = beforeDeathCell.getX();
        short yleft = beforeDeathCell.getY();
        short yright = beforeDeathCell.getY();
        short direction = tracer.getLastDirection();
        short cols = tracer.getWorld().getParams().getCols();
        short rows = tracer.getWorld().getParams().getRows();
        switch (direction) {
            case 0:
                xleft--;
                xright++;
                if (xleft < 0) {
                    xleft = (short) (cols - 1);
                }
                if (xright >= cols) {
                    xright = 0;
                }
                break;
            case 1:
                xleft--;
                yleft--;
                xright++;
                yright++;
                if (xleft < 0) {
                    xleft = (short) (cols - 1);
                }
                if (xright >= cols) {
                    xright = 0;
                }
                if (yleft < 0) {
                    yleft = (short) (rows - 1);
                }
                if (yright >= rows) {
                    yright = 0;
                }
                break;
            case 2:
                yleft--;
                yright++;
                if (yleft < 0) {
                    yleft = (short) (rows - 1);
                }
                if (yright >= rows) {
                    yright = 0;
                }
                break;
            case 3:
                xleft++;
                yleft--;
                xright--;
                yright++;
                if (xleft >= cols) {
                    xleft = 0;
                }
                if (xright < 0) {
                    xright = (short) (cols - 1);
                }
                if (yleft < 0) {
                    yleft = (short) (rows - 1);
                }
                if (yright >= rows) {
                    yright = 0;
                }
                break;
            case 4:
                xleft++;
                xright--;
                if (xright < 0) {
                    xright = (short) (cols - 1);
                }
                if (xleft >= cols) {
                    xleft = 0;
                }
                break;
            case 5:
                xleft++;
                yleft++;
                xright--;
                yright--;
                if (xright < 0) {
                    xright = (short) (cols - 1);
                }
                if (xleft >= cols) {
                    xleft = 0;
                }
                if (yright < 0) {
                    yright = (short) (rows - 1);
                }
                if (yleft >= rows) {
                    yleft = 0;
                }
                break;
            case 6:
                yleft++;
                yright--;
                if (yright < 0) {
                    yright = (short) (rows - 1);
                }
                if (yleft >= rows) {
                    yleft = 0;
                }
                break;
            case 7:
                xleft--;
                yleft++;
                xright++;
                yright--;
                if (xright >= cols) {
                    xright = 0;
                }
                if (xleft < 0) {
                    xleft = (short) (cols - 1);
                }
                if (yright < 0) {
                    yright = (short) (rows - 1);
                }
                if (yleft >= rows) {
                    yleft = 0;
                }
                break;
            default:
                break;
        }
        Cell rightCell = tracer.getWorld().getCell(xright, yright);
        Cell leftCell = tracer.getWorld().getCell(xleft, yleft);

        int leftOrRight = tracer.getLeftOrRight();
        Cell internalCell = null, externalCell = null;
        if (leftOrRight == -1) {
            internalCell = leftCell;
            externalCell = rightCell;
        } else if (leftOrRight == 1) {
            internalCell = rightCell;
View Full Code Here


    private void move(int downMove, int rightMove) {
        getUnit().setLastOccupiedCell(getUnit().getCell());
        if (isAlive()) {
            int oldX = getUnit().getCell().getX();
            int oldY = getUnit().getCell().getY();
            Cell cell = getUnit().move(getDnaParams().getSpecies(), downMove, rightMove, getProgenitor());
            if (oldX != cell.getX() || oldY != cell.getY()) {
                Color resultantColor = null;
                Resource resource = getUnit().getCell().getResource();
                int artisticType = resource.getType();
                if (artisticType == ResourceConstants.ARTISTIC_COLOR_RESOURCE) {
                    // colore dell'agente in RGB
View Full Code Here

    public static List<Cell> getSortedOutline(Set<Cell> shape, Cell unitCell, short cols, short rows) {
        List<Cell> listCell = new ArrayList<Cell>();
        shape.remove(unitCell);
        listCell.add(unitCell);
        while (!shape.isEmpty()) {
            Cell nearestCell = getNearestCell(shape, listCell.get(listCell.size() - 1), cols, rows);
            shape.remove(nearestCell);
            listCell.add(nearestCell);
        }
        listCell.remove(0);
        return listCell;
View Full Code Here

        y = getNormalizedMovement(y, rows);
        return Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
    }

    private static Cell getNearestCell(Set<Cell> shape, Cell unitCell, short cols, short rows) {
        Cell nearestCell = null;
        double nearestDistance = 0.0;
        if (shape.size() == 1) {
            Cell c = shape.iterator().next();
            return new Cell(c.getX(), c.getY());
        }
        for (Cell c : shape) {
            double dist = getDistance(c, unitCell, cols, rows);
            if (nearestCell == null) {
                nearestDistance = dist;
                nearestCell = new Cell(c.getX(), c.getY());
                if (dist == 1.0) {
                    break;
                }
            } else {
                if (dist < nearestDistance) {
                    nearestDistance = dist;
                    nearestCell = new Cell(c.getX(), c.getY());
                }
            }
        }
        return nearestCell;
    }
View Full Code Here

    private void move(int downMove, int rightMove) {
        getUnit().setLastOccupiedCell(getUnit().getCell());
        if (isAlive()) {
            int oldX = getUnit().getCell().getX();
            int oldY = getUnit().getCell().getY();
            Cell cell = getUnit().move(getDnaParams().getSpecies(), downMove, rightMove, getProgenitor());
            if (oldX != cell.getX() || oldY != cell.getY()) {
                Resource resource = getUnit().getCell().getResource();
                int artisticType = resource.getType();
                if (artisticType == ResourceConstants.ARTISTIC_TRACE_RESOURCE) {
                    TraceResource traceResource = (TraceResource) resource;
                    traceResource.setColor(getInternalColor());
                    traceResource.setTracer(this.toString());
                    duplicate();
                } else if (artisticType == ResourceConstants.ARTISTIC_COLOR_RESOURCE) {
                    TraceResource traceResource = new TraceResource(this.toString());
                    traceResource.setColor(getInternalColor());
                    getUnit().getCell().setResource(traceResource);
                }
                if (getBirthCell() == null) {
                    setBirthCell(new Cell(cell.getX(), cell.getY(), cell.getResource(), null));
                    System.err.println("BIRTH CELL: (" + getBirthCell().getX() + "," + getBirthCell().getY() + ") for tracer " + this.toString());
                }
            }
            getUnit().getCell().cellChanged();
        }
View Full Code Here

                controllers.get(idWorld).updateGUIAgent(agent);
            }
        } else if (event.equals(EventConstants.CELL_EVENT)) {
            World world = (World) o;
            int idWorld = world.getId();
            Cell cell = world.getChangedCell();
            controllers.get(idWorld).updateGUICell(cell);
        }
    }
View Full Code Here

                short deltaY = (short) ((Math.random() * (radius * 2 + 1)) - radius);
                short xCenter = EnvironmentFunction.getNormalizedX((short) (x + deltaX), getWorld().getParams().getCols());
                short yCenter = EnvironmentFunction.getNormalizedY((short) (y + deltaY), getWorld().getParams().getRows());
                Set<Cell> cells = circleMidpoint(xCenter, yCenter, radius);
                List<Cell> orderedCells = EnvironmentFunction.getSortedOutline(cells, getUnit().getCell(), getParams().getCols(), getParams().getRows());
                Cell lastCell = getUnit().getCell();
                for (Cell c : orderedCells) {
                    Integer[] dir = new Integer[2];
                    dir[0] = (int) EnvironmentFunction.getNormalizedMovement((short) (c.getX() - lastCell.getX()), getWorld().getParams().getCols());
                    dir[1] = (int) EnvironmentFunction.getNormalizedMovement((short) (c.getY() - lastCell.getY()), getWorld().getParams().getRows());
                    directionList.add(dir);
                    lastCell = c;
                }
                break;
            default:
View Full Code Here

    }

    public void resetGUIGrid(World world) {
        for (int i = 0; i < params.getCols(); i++) {
            for (int j = 0; j < params.getRows(); j++) {
                Cell cell = world.getCell(i, j);
                Color color = getCellColor(cell);
                guiWorld.updateCell(i, j, color);
            }
        }
    }
View Full Code Here

TOP

Related Classes of environment.Cell

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.