Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Macros = ParseJson <List <KeyMacro> >(JSON_MACROS);
            if (Macros.Count == 0)
            {
                Macros.Add(CreateDummyMacro());
            }
            Simulator = ParseJson <SimulationProcessor>(JSON_CONFIG);

            Application.Run(new frmMain());
        }
Exemplo n.º 3
0
        public void Tick(float deltaTime)
        {
            if (mAIIterator.Count == 0)
            {
                CreateAITask(0, 1, deltaTime, 575);
                CreateAITask(1, 0, deltaTime, 575);
            }

            foreach (uint id in mAIIterator)
            {
                mActiveInput[id] = mControlResults[id].Take();
            }
            ActiveState = SimulationProcessor.ProcessState(ActiveState, SimulationData, mActiveInput, deltaTime);
            foreach (uint id in mAIIterator)
            {
                mControlRequests[id].Add(ActiveState);  //TODO: Should copy!
            }
        }
Exemplo n.º 4
0
        private SimulationState GetPrimedState(Option option)
        {
            SimulationState simState = new SimulationState(2);

            //Add the state resulting from this option, and a mock shot to track hits
            simState.AddVehicle(mControlledID, option.ResultingState);
            simState.SetProjectileCount(mControlledID, 1);
            DynamicPosition2 mockProjectile = SimulationProcessor.CreateProjectileState(option.ResultingState.DynamicTransform, mSimData.GetVehiclePrototype(mControlledID).Guns, 0, mDeltaTime);

            simState.GetProjectiles(mControlledID).Add(mockProjectile);
            //Add the existing enemy projectiles, if they have any hope to hit
            simState.SetProjectileCount(mTargetID, mEnemyProjectiles.Count);
            simState.GetProjectiles(mTargetID).AddRange(mEnemyProjectiles);
            VehicleState targetRandomState = GetRandomNextState(mTargetRootState, mSimData.GetVehiclePrototype(mTargetID), mRandom, mDeltaTime);

            simState.AddVehicle(mTargetID, targetRandomState);
            return(simState);
        }
Exemplo n.º 5
0
        private void ComputeResidueRolloutHits(SimulationState finalState, ref OptionPayout payout)
        {
            var remainingOwnProjectiles = finalState.GetProjectiles(mControlledID);

            if (remainingOwnProjectiles.Count > 0)
            {
                var targetState = finalState.GetVehicle(mTargetID);
                foreach (var projectile in remainingOwnProjectiles)
                {
                    if (SimulationProcessor.ProjectileHitsVehicle(targetState.DynamicTransform, mSimData.GetVehiclePrototype(mTargetID), projectile, 1000f))
                    {
                        payout.ShotsLanded += 1;
                    }
                }
            }
            var remainingEnemyProjectiles = finalState.GetProjectiles(mTargetID);

            if (remainingEnemyProjectiles.Count > 0)
            {
                var controlledState     = finalState.GetVehicle(mControlledID);
                var controlledPrototype = mSimData.GetVehiclePrototype(mControlledID);
                foreach (var projectile in remainingEnemyProjectiles)
                {
                    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, 1000f))
                        {
                            payout.ShotsTaken += 1;
                        }
                        else
                        {
                            float timeToImpact;
                            float distanceSq = MonteCarloVehicleAI.ShotDistanceSq(projectile, controlledState.DynamicTransform.DynamicPosition, out timeToImpact);
                            payout.ProjectileThreat += 1f / (timeToImpact * timeToImpact * distanceSq);
                        }
                    }
                }
            }
        }
Exemplo n.º 6
0
        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;
        }
Exemplo n.º 7
0
 public static void RequestUpdate()
 {
     instance.UpdateRequested = true;
     SimulationProcessor.RequestUpdate();
 }