static Offset <FDouble> Serialise(FlatBufferBuilder b, IHasDouble numeral) { FDouble.StartFDouble(b); var vec2 = numeral.ObservationValue; var granularity = numeral.DoubleSpace.DecimalGranularity; var xs = numeral.DoubleSpace.Xspace; var ys = numeral.DoubleSpace.Yspace; FDouble.AddXRange(b, FRange.CreateFRange(b, granularity, xs.Max, xs.Min, xs.NormalisedBool)); FDouble.AddYRange(b, FRange.CreateFRange(b, granularity, ys.Max, ys.Min, ys.NormalisedBool)); FDouble.AddVec2(b, FVector2.CreateFVector2(b, vec2.x, vec2.y)); return(FDouble.EndFDouble(b)); }
static Offset <FObjective> Serialise(FlatBufferBuilder b, EnvironmentDescription description) { var ob_name = "None"; var ep_len = -1; var a = 0; var f = 0f; var c = 0f; var d = false; if (description.ObjectiveFunction != null) { ob_name = description.ObjectiveFunction.Identifier; ep_len = description.ObjectiveFunction.EpisodeLength; f = description.ObjectiveFunction.SignalSpace.Min; c = description.ObjectiveFunction.SignalSpace.Max; a = description.ObjectiveFunction.SignalSpace.DecimalGranularity; d = description.ObjectiveFunction.SignalSpace.NormalisedBool; } var objective_name_offset = b.CreateString(ob_name); FObjective.StartFObjective(b); FObjective.AddMaxEpisodeLength(b, ep_len); FObjective.AddSignalSpace(b, FRange.CreateFRange(b, a, f, c, d)); FObjective.AddObjectiveName(b, objective_name_offset); return(FObjective.EndFObjective(b)); }
static Offset <FTriple> Serialise(FlatBufferBuilder b, IHasTriple numeral) { FTriple.StartFTriple(b); var vec3 = numeral.ObservationValue; FTriple.AddVec3(b, FVector3.CreateFVector3(b, vec3.x, vec3.y, vec3.z)); var granularity = numeral.TripleSpace.DecimalGranularity; var xs = numeral.TripleSpace.Xspace; var ys = numeral.TripleSpace.Yspace; var zs = numeral.TripleSpace.Zspace; FTriple.AddXRange(b, FRange.CreateFRange(b, granularity, xs.Max, xs.Min, xs.NormalisedBool)); FTriple.AddYRange(b, FRange.CreateFRange(b, granularity, ys.Max, ys.Min, ys.NormalisedBool)); FTriple.AddZRange(b, FRange.CreateFRange(b, granularity, zs.Max, zs.Min, zs.NormalisedBool)); return(FTriple.EndFTriple(b)); }
static Offset <FArray> Serialise(FlatBufferBuilder b, IHasFloatArray float_a) { var v_offset = FArray.CreateArrayVectorBlock(b, float_a.ObservationArray); //var v_offset = CustomFlatBufferImplementation.CreateFloatVector(b, float_a.ObservationArray); var ranges_vector = new VectorOffset(); FArray.StartRangesVector(b, float_a.ObservationSpace.Length); foreach (var tra in float_a.ObservationSpace) { FRange.CreateFRange(b, tra.DecimalGranularity, tra.Max, tra.Min, tra.NormalisedBool); } ranges_vector = b.EndVector(); FArray.StartFArray(b); FArray.AddArray(b, v_offset); FArray.AddRanges(b, ranges_vector); return(FArray.EndFArray(b)); }
void Start() { if (planetPosition == null) { planetPosition = new PlanetPosition(gameObject); planetPosition.GenerateSeed(); } else { planetPosition.SetParent(gameObject); } if (Data == null) { return; } if (Data.IsEmpty()) { Create(); } else { Visualize(); } EcoZone = Star.EcosphereZone(this); }
/// <summary> /// </summary> /// <param name="b"></param> /// <param name="sensor"></param> /// <returns></returns> static Offset <FQTObs> Serialise(FlatBufferBuilder b, IHasQuaternionTransform sensor) { var pos = sensor.Position; var rot = sensor.Rotation; var pos_range = sensor.PositionSpace; var rot_range = sensor.RotationSpace; FQTObs.StartFQTObs(b); FQTObs.AddPosRange(b, FRange.CreateFRange(b, pos_range.DecimalGranularity, pos_range.Max, pos_range.Min, pos_range.NormalisedBool)); FQTObs.AddRotRange(b, FRange.CreateFRange(b, rot_range.DecimalGranularity, rot_range.Max, rot_range.Min, rot_range.NormalisedBool)); FQTObs.AddTransform(b, FQuaternionTransform.CreateFQuaternionTransform(b, pos.x, pos.y, pos.z, rot.x, rot.y, rot.z, rot.w)); return(FQTObs.EndFQTObs(b)); }
public void Create() { GameObject star = Instantiate(StarPrefab, this.transform.position, Quaternion.identity); star.transform.SetParent(this.transform); star.GetComponent <Star>().Create(); ecoZone = Star.EcosphereZone(star); PlanetPosition planetPosition = new PlanetPosition(star); planetPosition.GenerateSeed(); List <float> positions = planetPosition.Positions(); float creationChance = (1f / positions.Count) * 3f; foreach (var position in positions) { //if (Random.Range(0f, 1f) < creationChance) //if (Random.Range(0f, 1f) < 0.4f) { float radius = ((SpaceMath.AU * position) / SpaceMath.Unit); Vector3 pos = new Vector3(1, 0, 0).normalized *radius *DistanceMult; GameObject planet = Instantiate(PlanetPrefab, this.transform.position + pos, Quaternion.identity); planet.transform.SetParent(star.transform); Zone planetZone = PlanetPositionZone(position); planet.GetComponent <Planet>().Create(planetZone); } } }
public static FRange EcosphereZone(Star star) { FRange ecoZone = new FRange(); ecoZone.Value = Mathf.Sqrt(star.Data.Luminosity.Value); ecoZone.From = ecoZone.Value * 0.95f; ecoZone.To = ecoZone.Value * 1.35f; return(ecoZone); }
static Offset <FConfigurable> Serialise( FlatBufferBuilder b, IConfigurable configurable, string identifier) { var n = b.CreateString(identifier); int observation_offset; FObservation observation_type; if (configurable is IHasQuaternionTransform) { observation_offset = Serialise(b, (IHasQuaternionTransform)configurable).Value; observation_type = FObservation.FQTObs; } else if (configurable is PositionConfigurable) { observation_offset = Serialise(b, (PositionConfigurable)configurable).Value; observation_type = FObservation.FTriple; } else if (configurable is IHasSingle) { observation_offset = Serialise(b, (IHasSingle)configurable).Value; observation_type = FObservation.FSingle; // ReSharper disable once SuspiciousTypeConversion.Global } else if (configurable is IHasDouble) { // ReSharper disable once SuspiciousTypeConversion.Global observation_offset = Serialise(b, (IHasDouble)configurable).Value; observation_type = FObservation.FDouble; } else if (configurable is EulerTransformConfigurable) { observation_offset = Serialise(b, (IHasEulerTransform)configurable).Value; observation_type = FObservation.FETObs; } else { FConfigurable.StartFConfigurable(b); FConfigurable.AddConfigurableName(b, n); return(FConfigurable.EndFConfigurable(b)); } FConfigurable.StartFConfigurable(b); FConfigurable.AddConfigurableName(b, n); FConfigurable.AddConfigurableValue(b, observation_offset); FConfigurable.AddConfigurableValueType(b, observation_type); FConfigurable.AddConfigurableRange(b, FRange.CreateFRange(b, 0, 0, 0, false)); return(FConfigurable.EndFConfigurable(b)); }
static Offset <FSingle> Serialise(FlatBufferBuilder b, IHasSingle numeral) { FSingle.StartFSingle(b); FSingle.AddValue(b, numeral.ObservationValue); var range_offset = FRange.CreateFRange(b, numeral.SingleSpace.DecimalGranularity, numeral.SingleSpace.Max, numeral.SingleSpace.Min, numeral.SingleSpace.NormalisedBool); FSingle.AddRange(b, range_offset); return(FSingle.EndFSingle(b)); }
static Offset <FActuator> Serialise(FlatBufferBuilder b, IActuator actuator, string identifier) { var n = b.CreateString(identifier); FActuator.StartFActuator(b); FActuator.AddActuatorName(b, n); FActuator.AddActuatorRange(b, FRange.CreateFRange(b, actuator.MotionSpace.DecimalGranularity, actuator.MotionSpace.Max, actuator.MotionSpace.Min, actuator.MotionSpace.NormalisedBool)); return(FActuator.EndFActuator(b)); }
IEnumerable <FRange> GenerateRanges(IEnumerable <int> months) { foreach (int m in months) { FRange range = new FRange(); range.attractor = m; range.includeLow = true; range.includeHigh = true; int window = 1 + Math.Min(2, m / 12); // yes, integer division is what we want range.low = m - window; range.high = m + window; yield return(range); } }
static Offset <FMotor> build_motor(FlatBufferBuilder b, Motor motor, string identifier) { var n = b.CreateString(identifier); FMotor.StartFMotor(b); FMotor.AddMotorName(b, n); FMotor.AddValidInput( b, FRange.CreateFRange( b, motor.MotionValueSpace.DecimalGranularity, motor.MotionValueSpace.MaxValue, motor.MotionValueSpace.MinValue)); FMotor.AddEnergySpentSinceReset(b, motor.GetEnergySpend()); return(FMotor.EndFMotor(b)); }
static Offset <FQuadruple> Serialise(FlatBufferBuilder b, IHasQuadruple numeral) { FQuadruple.StartFQuadruple(b); var quad = numeral.ObservationValue; FQuadruple.AddQuat(b, FQuaternion.CreateFQuaternion(b, quad.x, quad.y, quad.z, quad.z)); var granularity = numeral.QuadSpace.DecimalGranularity; var xs = numeral.QuadSpace.Xspace; var ys = numeral.QuadSpace.Yspace; var zs = numeral.QuadSpace.Zspace; var ws = numeral.QuadSpace.Wspace; FQuadruple.AddXRange(b, FRange.CreateFRange(b, granularity, xs.Max, xs.Min, xs.NormalisedBool)); FQuadruple.AddYRange(b, FRange.CreateFRange(b, granularity, ys.Max, ys.Min, ys.NormalisedBool)); FQuadruple.AddZRange(b, FRange.CreateFRange(b, granularity, zs.Max, zs.Min, zs.NormalisedBool)); FQuadruple.AddWRange(b, FRange.CreateFRange(b, granularity, ws.Max, ws.Min, ws.NormalisedBool)); return(FQuadruple.EndFQuadruple(b)); }
public void Create() { if (Class == StarClass.Random) { Data = StarData.GetData(); } else { Data = StarData.GetData(Class); } Data.Mutate(); float index = Random.Range(0.0f, 1f); Data.Luminosity.RandomValue(index, Mathf.Lerp); Data.Radius.RandomValue(index, Mathf.Lerp); Data.Color.RandomValue(index, Color.Lerp); Data.Mass.RandomValue(index, Mathf.Lerp); this.Evolution = Data.EvolutionState; this.Class = Data.StarClass; Visualize(); DestroyPlanets(); EcoZone = Star.EcosphereZone(this); }
public static float remap01(this float value, FRange fromTo) => value.remap(fromTo.from, fromTo.to, 0f, 1f);