コード例 #1
0
ファイル: Program.cs プロジェクト: sebingel/AnakinSkybot
 public AngleAndDistThrustCalculator(ICheckpointMemory checkpointMemory, IBoostUseCalculator boostUseCalculator,
                                     IAngleCalculator angleCalculator,
                                     ISlowDownCalculator slowDownCalculator, IGamestateCalculator gamestateCalculator)
 {
     this.checkpointMemory    = checkpointMemory;
     this.boostUseCalculator  = boostUseCalculator;
     this.angleCalculator     = angleCalculator;
     this.slowDownCalculator  = slowDownCalculator;
     this.gamestateCalculator = gamestateCalculator;
     boost = false;
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: sebingel/AnakinSkybot
    public void Start(IInputContainer inputContainer, IInitialCheckpointGuesser initialCheckpointGuesser,
                      ICheckpointMemory checkpointMemory, IBoostUseCalculator boostUseCalculator,
                      ITargetFinding targetFinding, IThrustCalculator thrustCalculator, ISpeedCalculator speedCalculator,
                      IGamestateCalculator gamestateCalculator)
    {
        // Game Loop
        while (true)
        {
            // Update input on start of each round
            inputContainer.Update();

            gamestateCalculator.Recalculate();

            speedCalculator.CalculateSpeed(inputContainer.PlayerPosition);

            #region Checkpoint calculations

            // Set first Checkpoint on game start (guessing)
            if (checkpointMemory.KnownCheckpoints.Count == 0)
            {
                checkpointMemory.AddCheckpoint(initialCheckpointGuesser.GuessInitialCheckPoint());
            }

            // Create a new Checkpoint with current target if we don't know all the Checkpoints yet
            if (!checkpointMemory.AllCheckPointsKnown &&
                checkpointMemory.GetCheckpointAtPosition(inputContainer.NextCheckpointLocation) == null)
            {
                checkpointMemory.AddCheckpoint(inputContainer.NextCheckpointLocation);
            }

            // Try to get the current target Checkpoint. If its null, then we add the newCP and set it as current
            // we use a threshold of 600 because we guessed the first Checkpoint
            checkpointMemory.CurrentCheckpoint =
                checkpointMemory.GetCheckpointAtPosition(inputContainer.NextCheckpointLocation);
            if (checkpointMemory.CurrentCheckpoint == null)
            {
                checkpointMemory.AddCheckpoint(inputContainer.NextCheckpointLocation);
                checkpointMemory.CurrentCheckpoint =
                    checkpointMemory.GetCheckpointAtPosition(inputContainer.NextCheckpointLocation);
            }

            // if we target the first Checkpoint we can safely say, that we know all Checkpoints
            if (checkpointMemory.CurrentCheckpoint.Id == 0 &&
                !checkpointMemory.AllCheckPointsKnown)
            {
                // update the first Checkpoint with exact values
                checkpointMemory.UpdateCheckpoint(checkpointMemory.CurrentCheckpoint,
                                                  inputContainer.NextCheckpointLocation);

                checkpointMemory.AllCheckPointsKnown = true;
            }

            Checkpoint cpAfterNextCp = null;
            if (checkpointMemory.AllCheckPointsKnown)
            {
                checkpointMemory.NextCheckpoint =
                    checkpointMemory.KnownCheckpoints.ToList()
                    .Find(x => x.Id == checkpointMemory.CurrentCheckpoint.Id + 1) ??
                    checkpointMemory.KnownCheckpoints[0];

                cpAfterNextCp =
                    checkpointMemory.KnownCheckpoints.ToList().Find(x => x.Id == checkpointMemory.NextCheckpoint.Id + 1) ??
                    checkpointMemory.KnownCheckpoints[0];
            }

            #endregion

            #region target finding

            Point target = targetFinding.GetTarget(inputContainer.PlayerPosition, checkpointMemory.CurrentCheckpoint,
                                                   checkpointMemory.NextCheckpoint, cpAfterNextCp);

            #endregion

            #region thrust calculations

            string sThrust =
                thrustCalculator.GetThrust(inputContainer.DistanceToNextCheckPoint, inputContainer.AngleToNextCheckPoint,
                                           inputContainer.PlayerPosition, target);

            #endregion

            #region status messages

            if (false)
            {
                foreach (var cp in checkpointMemory.KnownCheckpoints)
                {
                    Console.Error.WriteLine(cp.Id + " " + cp.Position.X + " " + cp.Position.Y + " " + cp.DistToNext);
                }

                Console.Error.WriteLine("cp count: " + checkpointMemory.KnownCheckpoints.Count);

                Console.Error.WriteLine("allCheckpointsKnown: " + checkpointMemory.AllCheckPointsKnown);

                Console.Error.WriteLine("nextCheckpointDist: " + inputContainer.DistanceToNextCheckPoint);

                Console.Error.WriteLine("nextCheckpointAngle: " + inputContainer.AngleToNextCheckPoint);

                //Console.Error.WriteLine("currentVectorAngle: " + currentVectorAngle);

                //Console.Error.WriteLine("currentVectorX: " + currentVectorX);
                //Console.Error.WriteLine("currentVectorY: " + currentVectorY);

                //Console.Error.WriteLine("nextCpVectorX: " + nextCpVectorX);
                //Console.Error.WriteLine("nextCpVectorY: " + nextCpVectorY);

                //Console.Error.WriteLine("lastPosition: " + lastPosition);
                //Console.Error.WriteLine("currentPosition: " + inputContainer.PlayerPosition);

                //Console.Error.WriteLine("currentVectorAngle: " + currentVectorAngle);
                //Console.Error.WriteLine("currentVectorAngle: " + currentVectorAngle);

                //Console.Error.WriteLine("distSlow: " + distSlow);

                //Console.Error.WriteLine("angleSlow: " + angleSlow);

                Console.Error.WriteLine("boostCpId: " + boostUseCalculator.GetBoostTargetCheckpoint().Id);

                //Console.Error.WriteLine("thrust: " + thrust);

                Console.Error.WriteLine("currentCP: " + checkpointMemory.CurrentCheckpoint.Id);

                Console.Error.WriteLine("nextCP: " + checkpointMemory.NextCheckpoint?.Id);
            }

            #endregion

            Console.WriteLine(target.X + " " + target.Y + " " + sThrust);
        }
    }