public int this[Planet p1, Planet p2] { get { if (!m_Initialised) throw new InvalidStateException(); int x = p1.Id, y = p2.Id; /* Use only half of the matrix to avoid double calculations (DistanceTo is a symmetric relation) */ if( x + y > m_NumPlanets ) { int tmp = x; x = y; y = tmp; } int ret = m_DistanceMatrix[x, y]; if( ret == 0 ) { double dx = p1.X - p2.X, dy = p1.Y - p2.Y; ret = m_DistanceMatrix[p1.Id, p2.Id] = (int) Math.Ceiling( Math.Sqrt( dx*dx + dy*dy ) ); } return ret; } }
private static double PolynomialDistanceWeight(Planet p, Planet reference, Polynomial poly) { return ( (double)p.GrowthRate / ( (double)p.ShipCount * /* Addition vs multiplication seems to make very little difference here */ (poly * p.DistanceTo(reference)) ) ) * ( (p.Owner == Players.Singleton.You) ? 2 : 1 ); }
public Fleet(GameState gs, Player owner, int shipCount, int sourcePlanet, int destinationPlanet, int totalTripLength, int turnsRemaining) { m_Owner = owner; m_ShipCount = shipCount; m_SourcePlanet = gs.Planets[sourcePlanet]; m_DestinationPlanet = gs.Planets[destinationPlanet]; m_TotalTripLength = totalTripLength; m_TurnsRemaining = turnsRemaining; }
public PlanetRender( Planet planet ) { EllipseGeometry planetGeom; FormattedText text; Geometry textGeom; double radius = Math.Sqrt(planet.GrowthRate) / c_RadiusScale; /* Area proportional to growth rate */ planetGeom = new EllipseGeometry(new Point(planet.X, planet.Y), radius, radius); m_gg.Children.Add(planetGeom); text = new FormattedText( planet.ShipCount.ToString(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Tahoma"), radius < 0.6 ? 0.6 : radius, Brushes.Black); textGeom = text.BuildGeometry(new Point(planet.X - text.Width / 2, planet.Y - text.Height / 2)); m_gg.Children.Add(textGeom); m_gg.Freeze( ); }
private static double Weight(Planet p) { return ((double)p.GrowthRate / (double)p.ShipCount) * ((p.Owner == Players.Singleton.You) ? 2 : 1); }
static private double NoDistanceWeight(Planet p) { return (((double)p.GrowthRate / (double)p.ShipCount) * ((p.Owner == Players.Singleton.You) ? 2 : 1)); }
private static double DistanceOnlyWeight(Planet p, Planet reference) { return 1 / (double)p.DistanceTo(reference); }
public Order( Planet sourcePlanet, Planet destinationPlanet, int shipCount ) { m_SourcePlanet = sourcePlanet; m_DestinationPlanet = destinationPlanet; m_ShipCount = shipCount; }