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 OptionPayout RolloutStateAndGetPayout(SimulationState simState) { OptionPayout payout = new OptionPayout(); payout.InitializeForExpand(); SimulationState iterationState = simState; const int kIterations = 22; for (int i = 0; i < kIterations; ++i) { VehicleState controlledVehicle = iterationState.GetVehicle(mControlledID); VehiclePrototype controlledPrototype = mSimData.GetVehiclePrototype(mControlledID); mControlInputMock[mControlledID] = new VehicleControls(GetRandomControl(controlledVehicle, controlledPrototype, mRandom, mDeltaTime)); VehicleState targetVehicle = iterationState.GetVehicle(mTargetID); VehiclePrototype targetPrototype = mSimData.GetVehiclePrototype(mTargetID); mControlInputMock[mTargetID] = new VehicleControls(GetRandomControl(targetVehicle, targetPrototype, mRandom, mDeltaTime)); iterationState = SimulationProcessor.ProcessState(iterationState, mSimData, mControlInputMock, mDeltaTime); EvaluateIterationPayout(iterationState, ref payout, controlledVehicle.DynamicTransform, controlledPrototype, targetVehicle.DynamicTransform, targetPrototype); } ComputeResidueRolloutHits(iterationState, ref payout); return(payout); }
public uint AddVehicle(VehiclePrototype prototype, VehicleState vehicle) { uint assignedID = RegisteredPlayers; ++RegisteredPlayers; SimulationData.RegisterPlayer(assignedID, prototype); ActiveState.AddVehicle(assignedID, vehicle); ActiveState.SetProjectileCount(assignedID, 1); return(assignedID); }
private void SetVehicleVerticesOnHash(VehiclePrototype prototype, VehicleState vehicleState) { Debug.Assert(mVertexHash.Count == 0); Vector2 position = vehicleState.DynamicTransform.Position; Vector2 sizedFacing = prototype.VehicleSize * vehicleState.DynamicTransform.Orientation.Facing; mVertexHash.Add(position + sizedFacing); mVertexHash.Add(position + PositiveRotateHelper(sizedFacing)); mVertexHash.Add(position + NegativeRotateHelper(sizedFacing)); }
private void RenderVehicles(SimulationData simData, VehicleState[] vehicles, uint[] idMap) { int colorIndex = 1; for (int i = 0; i < vehicles.Length; ++i) { VehiclePrototype prototype = simData.GetVehiclePrototype(idMap[i]); SetVehicleVerticesOnHash(prototype, vehicles[i]); mPrimitiveRenderer.PushPolygon(mVertexHash, sColors[colorIndex]); colorIndex = (colorIndex + 1) % sColors.Length; mVertexHash.Clear(); } }
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; }
private static VehicleDriveControls GetRandomControl(VehicleState fromState, VehiclePrototype prototype, Random randomizer, float deltaTime) { int randomChoice = randomizer.Next(0, prototype.ControlConfig.PossibleDeltas.Length); return(prototype.ControlConfig.GetControlFromDeltas(prototype.ControlConfig.PossibleDeltas[randomChoice], fromState.ControlState, deltaTime)); }
private uint SpawnVehicle(VehiclePrototype prototype, DynamicTransform2 placement) { VehicleState initialState = new VehicleState(placement, prototype.ControlConfig.DefaultControl); return(mMTSGame.AddVehicle(prototype, initialState)); }