package mock.model; import network.Messages.Enums.BoatStatusEnum; import network.Messages.LatestMessages; import shared.dataInput.BoatDataSource; import shared.dataInput.RaceDataSource; import shared.dataInput.RegattaDataSource; import shared.model.*; import java.util.Iterator; import java.util.List; public class RaceLogic { private RaceState raceState; /** * The scale factor of the race. * See {@link Constants#RaceTimeScale}. */ private int scaleFactor; /** * Object used to generate changes in wind speed/direction. */ private WindGenerator windGenerator; public RaceLogic(BoatDataSource boatDataSource, RaceDataSource raceDataSource, RegattaDataSource regattaDataSource, LatestMessages latestMessages, Polars polars, int timeScale) { this.raceState = new RaceState(boatDataSource, raceDataSource, regattaDataSource, latestMessages, polars); this.raceState.run(); //Set up wind generator. It may be tidier to create this outside the race (with the values sourced from a data file maybe?) and pass it in. this.windGenerator = new WindGenerator( Bearing.fromDegrees(225), Bearing.fromDegrees(215), Bearing.fromDegrees(235), 12d, 8d, 16d ); raceState.setWind(windGenerator.generateBaselineWind()); } private void changeWindDirection() { Wind nextWind = windGenerator.generateNextWind(raceState.getWind()); raceState.setWind(nextWind); } /** * Returns the number of boats that are still active in the race. * They become inactive by either finishing or withdrawing. * @return The number of boats still active in the race. */ protected int getNumberOfActiveBoats() { int numberOfActiveBoats = 0; for (MockBoat boat : raceState.getBoats()) { //If the boat is currently racing, count it. if (boat.getStatus() == BoatStatusEnum.RACING) { numberOfActiveBoats++; } } return numberOfActiveBoats; } /** * Returns a list of boats in the race. * @return List of boats in the race. */ public List getBoats() { return raceState.getBoats(); } }