Exemplo n.º 1
0
        public static float EstimateScore(PlayerId pId, GameState state, Input move, Vector2 target)
        {
            //            prof.Start ();

            float similarity;

            if (move == Input.Noop) {
                similarity = 0f;
            } else {
                var player = state.Player (pId);

                Vector2 gravOffset = state.IsGrounded (player) ? Vector2.Zero : gravVector;

                Vector2 targetVector = Vector2.Subtract (target, player.Target + gravOffset);

                Vector2.Normalize (targetVector);

            //                Debug.WriteLine("targetVector: {0}", gravOffset);

                similarity = (float)Util.CosineSimilarity(targetVector, moveVectors [move]);
            }

            //            prof.End ();

            return -similarity;
        }
Exemplo n.º 2
0
        public GameState nextState(GameState state, Input input1, Input input2, int nSteps = 1)
        {
            loadState (state);

            Debug.WriteLineIf ((Vector2.Distance (physP1.Fixture.Body.Position, state.P1.Coords) > 0.001f ||
                                Vector2.Distance (physP2.Fixture.Body.Position, state.P2.Coords) > 0.001f),
                "The gamestate and forwardmodel are out of sync"
            );

            return nextState (state.Health, input1, input2, nSteps);
        }
Exemplo n.º 3
0
        public static GameState nextState(ForwardModel forwardModel, GameState game,
            Input p1move, Input p2move, int nSteps = 1)
        {
            GameState lastState = game;

            int intermediateSteps = 1; // set to match a reasonable Gameloop#humanInputDelayFrames() value...
            for (int i = 0; i < intermediateSteps; i++) {
                lastState = forwardModel.nextState(lastState, p1move, p2move, nSteps);
            }

            return lastState;
        }
Exemplo n.º 4
0
 protected GameState nextState(GameState state, Input move, int nSteps = 1)
 {
     return pId == PlayerId.P1 ?
         nextState (forwardModel, state, move, predictPartnerInput (state), nSteps) :
         nextState (forwardModel, state, predictPartnerInput (state), move, nSteps);
 }
Exemplo n.º 5
0
 protected float EstimateScore(GameState state, Input move, Vector2 target)
 {
     return EstimateScore (this.pId, state, move, target);
 }
Exemplo n.º 6
0
 public abstract float EstimateScore(GameState state, Input move);
Exemplo n.º 7
0
 public override float EstimateScore(GameState state, Input input)
 {
     GameObject target = NextPlatform (state);
     return EstimateScore (state, input, target.Target);
 }
Exemplo n.º 8
0
 public override float EstimateScore(GameState state, Input input)
 {
     return EstimateScore (state, input, state.Goal.Target);
 }
Exemplo n.º 9
0
        private GameState nextState(float oldHealth, Input input1, Input input2, int nSteps = 1)
        {
            // Calculate physics

            physP1.movePlayer (input1);
            physP2.movePlayer (input2);

            const float stepSize = 1 / 20f;
            world.Step (nSteps * stepSize); // XXX: pass in the right time-step

            Vector2 c1 = physP1.Fixture.Body.Position;
            Vector2 c2 = physP2.Fixture.Body.Position;
            Vector2 v1 = physP1.Fixture.Body.LinearVelocity;
            Vector2 v2 = physP2.Fixture.Body.LinearVelocity;

            // Assign values to GameState
            GameState next = initialState.Clone (
                                 p1: initialState.P1.Clone (c1, v1),
                                 p2: initialState.P2.Clone (c2, v2),
                                 health: HealthControl.Health (oldHealth, c1, c2)
                             );

            return next;
        }
Exemplo n.º 10
0
        public bool Equals(Input p)
        {
            // If parameter is null return false:
            if ((object)p == null)
            {
                return false;
            }

            // Return true if the fields match:
            return (left == p.left) && (right == p.right) && (up == p.up);
        }
Exemplo n.º 11
0
        public void DrawButtonArrow(Player p, Input input, Color c)
        {
            var size = new Vector2 (1f, 0.5f) * Player.Size;

            double rotation = 0;
            Vector2 offset;

            //            Debug.WriteLine ("{0}: {1}", input.shortString(), input.ToInt);

            switch (input.ToInt) {
            case 1: //Input.Up.ToInt:
                rotation = 0;
                offset = new Vector2 (0, 1);
                break;
            case 2: //Input.Right.ToInt:
                rotation = 0.5;
                offset = new Vector2 (1, 0);
                break;
            case 3: //Input.UpRight.ToInt:
                rotation = 0.25;
                offset = new Vector2 (1, 1);
                break;
            case 4: //Input.Left.ToInt:
                rotation = -.5;
                offset = new Vector2 (-1, 0);
                break;
            case 5: //Input.UpLeft.ToInt:
                rotation = -.25;
                offset = new Vector2 (-1, 1);
                break;
            default: // This can happen when pressing left/right at the same time
                rotation = 1;
                offset = new Vector2 (0, -1);
            //                throw new KeyNotFoundException ();
                break;
            }

            DrawTriangle (size, p.Center + (offset * Player.Size), (float)(Math.PI*rotation), c);
        }
 public float EstimateScore(GameState state, Input move1, Input move2,
     Vector2 target1, Vector2 target2)
 {
     return WaypointHeuristic.EstimateScore (PlayerId.P1, state, move1, target1) +
         WaypointHeuristic.EstimateScore (PlayerId.P2, state, move2, target2);
 }
Exemplo n.º 13
0
        public override void movePlayer(Input input, float dt = 0.2f)
        {
            float mx = fix.Body.LinearVelocity.X;
            float my = fix.Body.LinearVelocity.Y;

            bool jumpButton = input.up;

            //TODO this will repeatedly jump and not respect stateful jump boosting
            if (jumpButton && Grounded) {
                my = JumpVelocity;
            } else if (!jumpButton && !Grounded && my > 0.0f) {
                my *= VariableJumpDampening;
            }

            //			if (!jumpButton)
            //				holdingJumpButton = false;
            //
            //			if (jumpButton && !holdingJumpButton && Grounded)
            //			{
            //				my = JumpVelocity;
            //				holdingJumpButton = true;
            //			}
            //			else if (!Grounded)
            //			{
            //                if (!holdingJumpButton && my > 0.0f)	{
            //					my *= VariableJumpDampening;
            //				}
            //			}

            float inputAxis = -1.0f * (input.left ? 1 : 0) + 1.0f * (input.right ? 1 : 0);
            float target = inputAxis * MaxMoveSpeed;
            float accel = (Grounded ? GroundMoveAccel : AirMoveAccel) * inputAxis * dt;

            bool hasInput = inputAxis != 0 ? true : false;
            bool isMoving = mx > 0.0f ? true : false;
            bool isAccelerating = hasInput && (!isMoving || (Math.Sign(target) == Math.Sign(mx) && Math.Abs(target) >= Math.Abs(mx)));
            bool isMovingBackward = hasInput && isMoving && Math.Sign(target) != Math.Sign(mx);
            bool frictionApplies = !hasInput || (!isAccelerating && !isMovingBackward);

            if (isAccelerating)
            {
                mx += accel;
            }
            else if (isMovingBackward)
            {
                mx += accel * 2.0f;
            }
            if (frictionApplies)
            {
                float drag = (Grounded ? GroundFriction : AirFriction) * dt;
                mx -= Math.Sign(mx) * Math.Min(Math.Abs(mx), drag);
            }
            float max = Math.Abs(target);
            mx = Util.clamp(mx, -max, max);

            fix.Body.LinearVelocity = new Vector2(mx, my);
        }
Exemplo n.º 14
0
 public abstract void movePlayer(Input input, float dt = 0.2f);