private static VehicleState GetRandomNextState(VehicleState fromState, VehiclePrototype prototype, Random randomizer, float deltaTime) { VehicleDriveControls randomControl = GetRandomControl(fromState, prototype, randomizer, deltaTime); DynamicTransform2 resultingDynamic = prototype.VehicleDrive(fromState.DynamicTransform, randomControl, deltaTime); return(new VehicleState(resultingDynamic, randomControl)); }
private void EvaluateIterationPayout( SimulationState iterationState, ref OptionPayout payout, DynamicTransform2 controlledDynamicState, VehiclePrototype controlledPrototype, DynamicTransform2 targetDynamicState, VehiclePrototype targetPrototype) { payout.ShotsTaken += iterationState.GetRegisteredHits(mTargetID); payout.ShotsLanded += iterationState.GetRegisteredHits(mControlledID); GunData controlledGun = controlledPrototype.Guns.MountedGun; GunData targetsGun = targetPrototype.Guns.MountedGun; float ownShotDistance = MonteCarloVehicleAI.ShotDistanceSq(controlledDynamicState, controlledGun, targetDynamicState.DynamicPosition); float targetShotDistance = MonteCarloVehicleAI.ShotDistanceSq(targetDynamicState, targetsGun, controlledDynamicState.DynamicPosition); float currentPositionValue = (ownShotDistance + 0.001f) / (targetShotDistance + 0.001f); payout.PositionValue = Math.Min(currentPositionValue, payout.PositionValue); }
private void SpawnVehicles() { const float vehicleSize = 5.5f; GunMount gunMount = MakeGunMount(vehicleSize); AsteroidsControlData data = new AsteroidsControlData(190f, 175f, 6.25f, 7.25f); VehicleDrive asteroidsDrive = AsteroidsControlsFactory.MakeDrive(data); VehiclePrototype asteroidsPrototype = new VehiclePrototype(vehicleSize, asteroidsDrive, AsteroidsControlsFactory.StandardConfig, gunMount); Vector2 position = new Vector2(kArenaWidth / 4, kArenaHeight / 4); Orientation2 orientation = new Orientation2(MathHelper.Pi); DynamicTransform2 initialPlacement = new DynamicTransform2(position, orientation); SpawnVehicle(asteroidsPrototype, initialPlacement); //TODO: This returns the assigned ID. Use it to setup proper control pipeline position = new Vector2(3 * kArenaWidth / 4, 3 * kArenaHeight / 4); orientation = new Orientation2(0f); initialPlacement = new DynamicTransform2(position, orientation); SpawnVehicle(asteroidsPrototype, initialPlacement); }
public void ResetAndSetup(SimulationState currentSimState) { mTargetRootState = currentSimState.GetVehicle(mTargetID); mEnemyProjectiles.Clear(); VehiclePrototype controlledPrototype = mSimData.GetVehiclePrototype(mControlledID); VehicleState controlledState = currentSimState.GetVehicle(mControlledID); var projectiles = currentSimState.GetProjectiles(mTargetID); //Cache the projectile states for next frame, but onyl those with a chance of hiting foreach (var projectile in projectiles) { Vector2 relativePosition = controlledState.DynamicTransform.Position - projectile.Position; Vector2 relativeVelocity = controlledState.DynamicTransform.Velocity - projectile.Velocity; if (Vector2.Dot(relativePosition, relativeVelocity) < 0f) { if (!SimulationProcessor.ProjectileHitsVehicle(controlledState.DynamicTransform, controlledPrototype, projectile, mDeltaTime)) { DynamicPosition2 updatedProjectile = new DynamicPosition2(projectile.Position + mDeltaTime * projectile.Velocity, projectile.Velocity); mEnemyProjectiles.Add(projectile); } } } mOptions.Clear(); controlledPrototype.ControlConfig.GetPossibleControlChanges(controlledState.ControlState, mDeltaTime, mControlOptionCache); foreach (var driveControlOption in mControlOptionCache) { VehicleControls controlOption = new VehicleControls(driveControlOption); DynamicTransform2 resultingDynamicState = controlledPrototype.VehicleDrive(controlledState.DynamicTransform, driveControlOption, mDeltaTime); VehicleState resultingVehicleState = new VehicleState(resultingDynamicState, driveControlOption); //We should not care for the gun state... I thnk... Option option = new Option(controlOption, resultingVehicleState); mOptions.Add(option); } mControlOptionCache.Clear(); mIterations = 0; }
public VehicleState(DynamicTransform2 transform, VehicleDriveControls controlState) : this(transform, controlState, new GunState()) { }
public VehicleState(DynamicTransform2 transform, VehicleDriveControls controlState, GunState gunState) { DynamicTransform = transform; ControlState = controlState; GunState = gunState; }
private uint SpawnVehicle(VehiclePrototype prototype, DynamicTransform2 placement) { VehicleState initialState = new VehicleState(placement, prototype.ControlConfig.DefaultControl); return(mMTSGame.AddVehicle(prototype, initialState)); }