Search in sources :

Example 6 with Team

use of spacesettlers.clients.Team in project spacesettlers by amymcgovern.

the class SpaceSettlersSimulator method updateTeamInfo.

/**
 * Update the team infomation that is sharable
 */
private void updateTeamInfo() {
    LinkedHashSet<ImmutableTeamInfo> teamInfo = new LinkedHashSet<ImmutableTeamInfo>();
    for (Team team : teams) {
        teamInfo.add(new ImmutableTeamInfo(team));
    }
    simulatedSpace.setTeamInfo(teamInfo);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ImmutableTeamInfo(spacesettlers.clients.ImmutableTeamInfo) Team(spacesettlers.clients.Team)

Example 7 with Team

use of spacesettlers.clients.Team in project spacesettlers by amymcgovern.

the class SpaceSettlersSimulator method updateScores.

/**
 * Updates the scores for the teams
 */
private void updateScores() {
    if (simConfig.getScoringMethod().equalsIgnoreCase("Resources")) {
        for (Team team : teams) {
            team.setScore(team.getSummedTotalResources());
        }
    } else if (simConfig.getScoringMethod().equalsIgnoreCase("ResourcesAndCores")) {
        for (Team team : teams) {
            team.setScore(team.getSummedTotalResources() + 100.0 * team.getTotalCoresCollected());
        }
    } else if (simConfig.getScoringMethod().equalsIgnoreCase("Beacons")) {
        for (Team team : teams) {
            int beacons = 0;
            for (Ship ship : team.getShips()) {
                beacons += ship.getNumBeacons();
            }
            team.setScore(beacons);
        }
    } else if (simConfig.getScoringMethod().equalsIgnoreCase("Kills")) {
        for (Team team : teams) {
            team.setScore(team.getTotalKillsInflicted());
        }
    } else if (simConfig.getScoringMethod().equalsIgnoreCase("Hits")) {
        for (Team team : teams) {
            team.setScore(team.getTotalHitsInflicted());
        }
    } else if (simConfig.getScoringMethod().equalsIgnoreCase("Damage")) {
        for (Team team : teams) {
            team.setScore(team.getTotalDamageInflicted());
        }
    } else if (simConfig.getScoringMethod().equalsIgnoreCase("DamageCorrected")) {
        for (Team team : teams) {
            // not subtracting damage received because it is a negative number (inflicted is positive)
            team.setScore(1000 * team.getTotalKillsInflicted() + team.getTotalDamageInflicted() + team.getTotalDamageReceived());
        }
    } else if (simConfig.getScoringMethod().equalsIgnoreCase("DamageCorrected2018")) {
        for (Team team : teams) {
            // not subtracting damage received because it is a negative number (inflicted is positive)
            team.setScore(1000 * team.getTotalKillsInflicted() + team.getTotalDamageInflicted() + team.getTotalDamageReceived() - (1000 * ((team.getTotalKillsReceived() + 1) * team.getTotalKillsReceived()) / 2.0) + (team.getSummedTotalResources() / 2.0));
        }
    } else if (simConfig.getScoringMethod().equalsIgnoreCase("Cores")) {
        for (Team team : teams) {
            team.setScore(team.getTotalCoresCollected());
        }
    } else if (simConfig.getScoringMethod().equalsIgnoreCase("Flags")) {
        // this scores by the raw number of flags collected (competitive ladder)
        for (Team team : teams) {
            team.setScore(team.getTotalFlagsCollected());
        }
    } else if (simConfig.getScoringMethod().equalsIgnoreCase("TotalFlags")) {
        // this score sums the flags for the two sides (cooperative ladder)
        int totalFlags = 0;
        for (Team team : teams) {
            totalFlags += team.getTotalFlagsCollected();
        }
        for (Team team : teams) {
            team.setScore(totalFlags);
        }
    } else {
        System.err.println("Error: Scoring method " + simConfig.getScoringMethod() + " is not recognized.  Scores will all be 0.");
    }
}
Also used : Team(spacesettlers.clients.Team) Ship(spacesettlers.objects.Ship)

Example 8 with Team

use of spacesettlers.clients.Team in project spacesettlers by amymcgovern.

the class JSpaceSettlersComponent method paintComponent.

/**
 * Draw the space background and all the sub components
 */
protected void paintComponent(final Graphics g) {
    super.paintComponent(g);
    final Graphics2D graphics = (Graphics2D) g;
    graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    // handle a race condition in the GUI
    if (scaleTransform == null) {
        return;
    }
    graphics.transform(scaleTransform);
    // draw space
    g.setColor(Color.BLACK);
    g.fillRect(0, 0, this.width, this.height);
    // handle an annoying race condition in the GUI
    if (simulator == null) {
        return;
    }
    // draw graphic for all the objects
    Set<AbstractObject> allObjects = new LinkedHashSet<AbstractObject>(simulator.getAllObjects());
    for (AbstractObject object : allObjects) {
        SpacewarGraphics graphic = object.getGraphic();
        if (graphic != null) {
            if (graphic.isDrawable()) {
                drawShadow(graphic, graphics);
            }
        }
    }
    // and draw any team graphics from this round
    for (Team team : simulator.getTeams()) {
        Set<SpacewarGraphics> teamShadows = team.getGraphics();
        if (teamShadows != null) {
            for (SpacewarGraphics graphic : teamShadows) {
                if (graphic.isDrawable()) {
                    drawShadow(graphic, graphics);
                }
            }
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) SpacewarGraphics(spacesettlers.graphics.SpacewarGraphics) AbstractObject(spacesettlers.objects.AbstractObject) Team(spacesettlers.clients.Team) Graphics2D(java.awt.Graphics2D)

Example 9 with Team

use of spacesettlers.clients.Team in project spacesettlers by amymcgovern.

the class ResourcesPanel method updateData.

public void updateData(SpaceSettlersSimulator simulator, String teamName) {
    Team team = null;
    for (Team curTeam : simulator.getTeams()) {
        if (curTeam.getLadderName().equalsIgnoreCase(teamName)) {
            team = curTeam;
            break;
        }
    }
    ResourcePile avail = team.getAvailableResources();
    ResourcePile total = team.getTotalResources();
    waterAvail.setText("" + avail.getResourceQuantity(ResourceTypes.WATER));
    fuelAvail.setText("" + avail.getResourceQuantity(ResourceTypes.FUEL));
    metalsAvail.setText("" + avail.getResourceQuantity(ResourceTypes.METALS));
    waterTotal.setText("" + total.getResourceQuantity(ResourceTypes.WATER));
    fuelTotal.setText("" + total.getResourceQuantity(ResourceTypes.FUEL));
    metalsTotal.setText("" + total.getResourceQuantity(ResourceTypes.METALS));
}
Also used : ResourcePile(spacesettlers.objects.resources.ResourcePile) Team(spacesettlers.clients.Team)

Example 10 with Team

use of spacesettlers.clients.Team in project spacesettlers by amymcgovern.

the class Ladder method run.

/**
 * Runs the ladder for the specified number of games
 * @throws SimulatorException
 */
@SuppressWarnings("unchecked")
public void run() throws SimulatorException {
    ArrayList<HighLevelTeamConfig[]> clientsPerMatch = getAllClientsForAllMatches();
    int numGames = clientsPerMatch.size() * ladderConfig.getNumRepeatMatches();
    System.out.println("Ladder will run " + numGames + " games");
    System.out.println("Variable teams are: ");
    for (HighLevelTeamConfig team : ladderConfig.getVariableTeams()) {
        System.out.println(team);
    }
    int gameIndex = 0;
    for (int repeat = 0; repeat < ladderConfig.getNumRepeatMatches(); repeat++) {
        for (HighLevelTeamConfig[] teamsForMatch : clientsPerMatch) {
            gameIndex++;
            // setup the simulator for this match
            simConfig.setTeams(teamsForMatch);
            // set the bases to match the teams for this game.  Read in the ones
            // from the config file first (and rename them)
            // only make new ones if we don't have enough
            BaseConfig[] defaultBases = simConfig.getBases();
            BaseConfig[] baseConfig = new BaseConfig[teamsForMatch.length];
            for (int i = 0; i < teamsForMatch.length; i++) {
                if (i < defaultBases.length) {
                    baseConfig[i] = defaultBases[i];
                    baseConfig[i].setTeamName(teamsForMatch[i].getTeamName());
                } else {
                    baseConfig[i] = new BaseConfig(teamsForMatch[i].getTeamName());
                }
            }
            simConfig.setBases(baseConfig);
            // if there are flags, then set the flags to also match the teams for this game
            FlagConfig[] flagConfigs = simConfig.getFlags();
            if (flagConfigs != null && flagConfigs.length > 0) {
                if (flagConfigs.length != teamsForMatch.length) {
                    throw new SimulatorException("Error: The number of flags in the config file doesn't match the number of teams for the match");
                }
                for (int i = 0; i < teamsForMatch.length; i++) {
                    flagConfigs[i].setTeamName(teamsForMatch[i].getTeamName());
                }
            }
            // tell the user the match is about to begin
            String str = "***Game " + gameIndex + " / " + numGames + " with teams ";
            for (HighLevelTeamConfig team : teamsForMatch) {
                str += (team.getTeamName() + " ");
            }
            str += "***";
            System.out.println(str);
            ladderOutputString.add(str);
            try {
                // try to make a simulator and run it
                simulator = new SpaceSettlersSimulator(simConfig, parserConfig);
                str = "***Game " + gameIndex + " / " + numGames + " with teams ";
                Set<Team> teams = simulator.getTeams();
                for (Team team : teams) {
                    str += (team.getTeamName() + " = " + team.getLadderName() + " ");
                }
                str += "***";
                System.out.println(str);
                ladderOutputString.add(str);
                // run the game
                simulator.run();
                // get the teams and print out their scores
                for (Team team : teams) {
                    str = "Team: " + team.getLadderName() + " scored " + team.getScore();
                    ladderOutputString.add(str);
                    System.out.println(str);
                    TeamRecord thisRecord;
                    if (ladderResultsMap.containsKey(team.getLadderName())) {
                        thisRecord = ladderResultsMap.get(team.getLadderName());
                    } else {
                        thisRecord = new TeamRecord(team);
                    }
                    thisRecord.update(team);
                    ladderResultsMap.put(team.getLadderName(), thisRecord);
                }
            } catch (Exception e) {
                System.err.println("Error in match : skipping and moving to next one");
                ladderOutputString.add("Error in match : skipping and moving to next one");
                ladderOutputString.add(e.toString());
                e.printStackTrace();
            }
        }
    }
    // the games are over so sort the records
    sortedLadderResults = new ArrayList<TeamRecord>();
    for (TeamRecord record : ladderResultsMap.values()) {
        sortedLadderResults.add(record);
    }
    Collections.sort(sortedLadderResults, new TeamRecordComparator());
    System.out.println("Overall team order: ");
    for (TeamRecord record : sortedLadderResults) {
        System.out.println(record.getTeamName() + " average score " + record.getAverageScore());
    }
}
Also used : IOException(java.io.IOException) SimulatorException(spacesettlers.simulator.SimulatorException) SpaceSettlersSimulator(spacesettlers.simulator.SpaceSettlersSimulator) Team(spacesettlers.clients.Team) SimulatorException(spacesettlers.simulator.SimulatorException)

Aggregations

Team (spacesettlers.clients.Team)10 Ship (spacesettlers.objects.Ship)4 LinkedHashSet (java.util.LinkedHashSet)2 AbstractObject (spacesettlers.objects.AbstractObject)2 Asteroid (spacesettlers.objects.Asteroid)2 Position (spacesettlers.utilities.Position)2 Graphics2D (java.awt.Graphics2D)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 UUID (java.util.UUID)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 AbstractAction (spacesettlers.actions.AbstractAction)1 DoNothingAction (spacesettlers.actions.DoNothingAction)1 PurchaseTypes (spacesettlers.actions.PurchaseTypes)1 ImmutableTeamInfo (spacesettlers.clients.ImmutableTeamInfo)1 TeamClient (spacesettlers.clients.TeamClient)1 SpacewarGraphics (spacesettlers.graphics.SpacewarGraphics)1