Ejemplo n.º 1
0
    internal override bool ProcessEvent(GameEvent gameEvent, IInputContainer data, out GameState nextState)
    {
        nextState = GameState.None;

        switch (gameEvent)
        {
        case GameEvent.MoveFlipper:
            if (data is FlipperInput flipper)
            {
                MoveFlipper(flipper.FlipperSide, flipper.FlipperDirection);
            }
            break;

        case GameEvent.DropBall:
            nextState = GameState.LoseBall;
            return(true);

        case GameEvent.AddScores:
            if (data is ScoreInput scoreData)
            {
                OnScored(scoreData.ScoreArgs);
            }
            break;

        case GameEvent.UpdateScores:
            UpdateGameScores();
            break;
        }
        return(false);
    }
Ejemplo n.º 2
0
 public SimpleDistanceSlowDownCalculator(ISlowDownCalculator slowDownCalculator, ICheckpointMemory checkpointMemory,
                                         IInputContainer inputContainer)
 {
     this.slowDownCalculator = slowDownCalculator;
     this.checkpointMemory   = checkpointMemory;
     this.inputContainer     = inputContainer;
 }
Ejemplo n.º 3
0
 public SmartTargetFinder(ICheckpointMemory checkpointMemory, IInputContainer inputContainer, ISpeedCalculator speed,
                          IAngleCalculator angleCalculator)
 {
     this.checkpointMemory = checkpointMemory;
     this.inputContainer   = inputContainer;
     this.speed            = speed;
     this.angleCalculator  = angleCalculator;
 }
Ejemplo n.º 4
0
 internal void ProcessInput(GameEvent gameEvent, IInputContainer data)
 {
     Debug.Log($"Input Event: {gameEvent}, Data: {data}");
     if (_currentState.ProcessEvent(gameEvent, data, out GameState nextState))
     {
         GoToState(nextState);
     }
 }
Ejemplo n.º 5
0
 public HitPredictionSlowDownCalculator(ISlowDownCalculator slowDownCalculator,
                                        IGamestateCalculator gamestateCalculator, ICheckpointMemory checkpointMemory, IInputContainer inputContainer)
 {
     this.slowDownCalculator  = slowDownCalculator;
     this.gamestateCalculator = gamestateCalculator;
     this.checkpointMemory    = checkpointMemory;
     this.inputContainer      = inputContainer;
 }
Ejemplo n.º 6
0
 public LinearMovementAngleSlowDownCalculator(ISlowDownCalculator slowDownCalculator,
                                              IGamestateCalculator gamestateCalculator, IInputContainer inputContainer, IAngleCalculator angleCalculator,
                                              ICheckpointMemory checkpointMemory)
 {
     this.slowDownCalculator  = slowDownCalculator;
     this.gamestateCalculator = gamestateCalculator;
     this.inputContainer      = inputContainer;
     this.angleCalculator     = angleCalculator;
     this.checkpointMemory    = checkpointMemory;
 }
Ejemplo n.º 7
0
    internal override bool ProcessEvent(GameEvent gameEvent, IInputContainer _, out GameState nextState)
    {
        if (gameEvent == GameEvent.Restart)
        {
            Restart();
        }

        nextState = GameState.None;
        return(false);
    }
Ejemplo n.º 8
0
    internal override bool ProcessEvent(GameEvent gameEvent, IInputContainer _, out GameState nextState)
    {
        if (gameEvent == GameEvent.StartGame)
        {
            GameController.Instance.StartGame();
            nextState = GameState.LaunchBall;
            return(true);
        }

        nextState = GameState.None;
        return(false);
    }
Ejemplo n.º 9
0
    internal override bool ProcessEvent(GameEvent gameEvent, IInputContainer data, out GameState nextState)
    {
        if (gameEvent == GameEvent.LaunchBall && data is LaunchInput launchData)
        {
            DataController.BallsController.DecrementBallsCount();
            GameController.Instance.UpdateBallsLeft(DataController.BallsController.BallsCount);
            GameController.Instance.LaunchBall(_ballTypes[Random.Range(0, _ballTypes.Length - 1)], launchData.HoldDuration);

            nextState = GameState.GameProcess;
            return(true);
        }

        nextState = GameState.None;
        return(false);
    }
Ejemplo n.º 10
0
    internal override bool ProcessEvent(GameEvent gameEvent, IInputContainer _, out GameState nextState)
    {
        nextState = GameState.None;
        switch (gameEvent)
        {
        case GameEvent.HandleBallDropped:
            if (DataController.BallsController.BallsCount > 0)
            {
                GameController.Instance.PlatNextBall();
                nextState = GameState.LaunchBall;
            }
            else
            {
                nextState = GameState.EndGame;
            }
            return(true);
        }

        return(false);
    }
Ejemplo n.º 11
0
 internal abstract void WrapInContainer(IInputContainer container);
Ejemplo n.º 12
0
 internal abstract void ContainIn(IInputContainer container);
Ejemplo n.º 13
0
 internal override void WrapInContainer(IInputContainer container) => container.Search = this;
 internal override void ContainIn(IInputContainer container)
 {
     container.Simple = this;
 }
Ejemplo n.º 15
0
 internal override void WrapInContainer(IInputContainer container) => container.Http = this;
Ejemplo n.º 16
0
 public GamestateCalculator(IInputContainer inputContainer)
 {
     this.inputContainer = inputContainer;
     GameStates          = new List <GameState>();
     lastPosition        = new Point(-1, -1);
 }
Ejemplo n.º 17
0
 internal override void ContainIn(IInputContainer container)
 {
     container.Http = this;
 }
Ejemplo n.º 18
0
 public InitialCheckpointGuesser(IInputContainer inputContainer)
 {
     this.inputContainer = inputContainer;
 }
 internal override void ContainIn(IInputContainer container)
 {
     container.Search = this;
 }
Ejemplo n.º 20
0
		internal abstract void WrapInContainer(IInputContainer container);
Ejemplo n.º 21
0
    public static Vector3 GetDir(this IInputContainer container, int id)
    {
        InputData value = container.GetRawInput(id);

        return(value.GetDir());
    }
Ejemplo n.º 22
0
    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);
        }
    }
 internal override void ContainIn(IInputContainer container)
 {
     container.Simple = this;
 }
Ejemplo n.º 24
0
 public SimpleAngleSlowDownCalculator(ISlowDownCalculator slowDownCalculator, IInputContainer inputContainer)
 {
     this.slowDownCalculator = slowDownCalculator;
     this.inputContainer     = inputContainer;
 }
Ejemplo n.º 25
0
    public static float GetAngle(this IInputContainer container, int id)
    {
        InputData value = container.GetRawInput(id);

        return(value.GetAngle());
    }
Ejemplo n.º 26
0
 internal abstract void ContainIn(IInputContainer container);
Ejemplo n.º 27
0
 internal override void ContainIn(IInputContainer container)
 {
     container.Http = this;
 }
 internal override void ContainIn(IInputContainer container)
 {
     container.Search = this;
 }