src/model/Model.java
private Agent applyAction(Agent agent) {
        Agent victim = null;
        Action action = agent.act();
        
        if (action != Action.WAIT && action.direction == null) {
            return null;
        }

        Cell targetCell;
        switch (action) {
        case MOVE:
            targetCell = world.grid[agent.x + action.direction.x][agent.y + action.direction.y];
            if (worldWrapper.isFree(targetCell.x, targetCell.y)) {
                world.grid[agent.x][agent.y].occupant = null;
                agent.x += action.direction.x;
                agent.y += action.direction.y;
                world.grid[agent.x][agent.y].occupant = agent;
                log.finer(String.format("%s moved %s", agent, action.direction));
            }
            break;
        case ROB:
            targetCell = world.grid[agent.x + action.direction.x][agent.y + action.direction.y];
            victim = targetCell.occupant;
            if (victim != null) {
                maxCrime = Math.max(maxCrime, ++world.grid[agent.x][agent.y].crimeCount);
                log.info(String.format("Round %d: %s robbed %s!", round, agent, victim));
            }
            break;
        case WAIT:
            log.finer(String.format("%s waited", agent));
            break;
        default:
            log.finer(String.format("%s has no idea what it's doing, go home %s", agent, agent));
            break;
        }
        
        return victim;
    }
/**
     * Gets the specified agent's action and commits it to the model.
     * Returns a victim agent, if there was a victim in this action.
     * Otherwise, returns null.
     */
Gets the specified agent's action and commits it to the model.
Returns a victim agent, if there was a victim in this action.
Otherwise, returns null.
Gets the specified agent ' s action and commits it to the model . Returns a victim agent if there was a victim in this action . Otherwise returns null .
private Agent applyAction(Agent agent) {
        Agent victim = null;
        Action action = agent.act();
        if (action != Action.WAIT && action.direction == null) {
            return null;
        }
        Cell targetCell;
        switch (action) {
        case MOVE:
            targetCell = world.grid[agent.x + action.direction.x][agent.y + action.direction.y];
            if (worldWrapper.isFree(targetCell.x, targetCell.y)) {
                world.grid[agent.x][agent.y].occupant = null;
                agent.x += action.direction.x;
                agent.y += action.direction.y;
                world.grid[agent.x][agent.y].occupant = agent;
                log.finer(String.format("%s moved %s", agent, action.direction));
            }
            break;
        case ROB:
            targetCell = world.grid[agent.x + action.direction.x][agent.y + action.direction.y];
            victim = targetCell.occupant;
            if (victim != null) {
                maxCrime = Math.max(maxCrime, ++world.grid[agent.x][agent.y].crimeCount);
                log.info(String.format("Round %d: %s robbed %s!", round, agent, victim));
            }
            break;
        case WAIT:
            log.finer(String.format("%s waited", agent));
            break;
        default:
            log.finer(String.format("%s has no idea what it's doing, go home %s", agent, agent));
            break;
        }
        return victim;
    }
private Agent applyAction ( Agent agent ) { Agent victim = null ; Action action = agent . act ( ) ; if ( action != Action . WAIT && action . direction == null ) { return null ; } Cell targetCell ; switch ( action ) { case MOVE : targetCell = world . grid [ agent . x + action . direction . x ] [ agent . y + action . direction . y ] ; if ( worldWrapper . isFree ( targetCell . x , targetCell . y ) ) { world . grid [ agent . x ] [ agent . y ] . occupant = null ; agent . x += action . direction . x ; agent . y += action . direction . y ; world . grid [ agent . x ] [ agent . y ] . occupant = agent ; log . finer ( String . format ( "%s moved %s" , agent , action . direction ) ) ; } break ; case ROB : targetCell = world . grid [ agent . x + action . direction . x ] [ agent . y + action . direction . y ] ; victim = targetCell . occupant ; if ( victim != null ) { maxCrime = Math . max ( maxCrime , ++ world . grid [ agent . x ] [ agent . y ] . crimeCount ) ; log . info ( String . format ( "Round %d: %s robbed %s!" , round , agent , victim ) ) ; } break ; case WAIT : log . finer ( String . format ( "%s waited" , agent ) ) ; break ; default : log . finer ( String . format ( "%s has no idea what it's doing, go home %s" , agent , agent ) ) ; break ; } return victim ; }
Gets the specified agent's action and commits it to the model.
Gets the specified agent ' s action and commits it to the model .