Exemple #1
0
        public void Move(Car self, World world, Game game, Move move)
        {
            if (stop)
                return;

            if (world.Tick == 0)
            {
                startX = self.X;
                startY = self.Y;
                prevX = self.X;
                prevY = self.Y;
            }

            move.EnginePower = 0;

            if (world.Tick > game.InitialFreezeDurationTicks)
            {

                double nextWaypointX = (self.NextWaypointX + 0.5D) * game.TrackTileSize;
                double nextWaypointY = (self.NextWaypointY + 0.5D) * game.TrackTileSize;

                double angleToWaypoint = self.GetAngleTo(nextWaypointX, nextWaypointY);
                double distToWaypoint = self.GetDistanceTo(nextWaypointX, nextWaypointY);

                double speedModule = Math.Sqrt(self.SpeedX * self.SpeedX + self.SpeedY * self.SpeedY);

                travelled += self.GetDistanceTo(prevX, prevY);
                travelled2 += self.GetDistanceTo(prevX, prevY);

                prevX = self.X;
                prevY = self.Y;

                move.EnginePower = 1;

                if (travelled > 1500)
                {
                    move.EnginePower = 0;

                    if (self.EnginePower == 0)
                    {
                        if (t == -10)
                        {
                            travelled2 = 0;
                            Console.WriteLine("S: {0},{1} {2}", self.X, self.Y, self.SpeedY);
                            t = 1;
                            SimulatedControl ctrl = new SimulatedControl();

                            ctrl.enginePower = move.EnginePower;

                            pos = simulator.Simulate(t, 1, self, world, game, ctrl);
                            Console.WriteLine("P: {0},{1} {2}", pos.position.X, pos.position.Y, pos.speed.Y);
                        }
                        else if (t > 1)
                        {
                            t--;
                        }
                        else if (t == 1)
                        {
                            t--;

                            Console.WriteLine("R: {0},{1} {2}", self.X, self.Y, self.SpeedY);

                            Console.WriteLine("%: {0} / {1} ({2})", travelled2, self.GetDistanceTo(pos.position.X, pos.position.Y), 100 * self.GetDistanceTo(pos.position.X, pos.position.Y) / travelled2);

                        }
                    }
                }
            }
        }
Exemple #2
0
        public SimulatedPosition Simulate(int ticks, int step, Car self, World world, Game game, SimulatedControl control)
        {
            SimulatedPosition pos = new SimulatedPosition(self, game);

            this.game = game;

            for (int t = 0; t < ticks; t += step)
            {
                for (int a = 0; a < 10; a++)
                {
                    //pos.enginePower = AgjustPower(pos.enginePower, control.enginePower, 0.1);
                    pos.Update(0.1);
                }

            }

            return pos;
        }