Beispiel #1
0
        static Snake DAlgoStr(string[] pa, int N, string[] pb, int M, VState VState, int d)
        {
            int MAX = N + M;

            for (int k = -d; k <= d; k += 2)
            {
                bool down = (k == -d || (k != d && VState[k - 1] < VState[k + 1]));

                int xStart = down ? VState[k + 1] : VState[k - 1];
                int yStart = xStart - (down ? k + 1 : k - 1);

                int xEnd = down ? xStart : xStart + 1;
                int yEnd = xEnd - k;

                int snake = 0;
                while (xEnd < N && yEnd < M && pa[xEnd].Equals(pb[yEnd]))
                {
                    xEnd++; yEnd++; snake++;
                }

                VState[k] = xEnd;

                // Debug.WriteLine( "  k:" + k + " V[k-1]:" + ( k - 1 >= -MAX ? VState[ k - 1 ].ToString() : "X" ) + " V[k+1]:" + ( k + 1 <= MAX ? VState[ k + 1 ].ToString() : "X" ) + ( down ? " down" : " right" ) + " Start:" + xStart + "," + yStart + " End:" + xEnd + "," + yEnd );

                if (xEnd >= N && yEnd >= M)
                {
                    return(new Snake(0, N, 0, M, true, xStart, yStart, down, snake));
                }
            }

            return(null);
        }
Beispiel #2
0
 // Initialize node and create empty children list
 public Node(VState state, Node parent,
             IEnumerable <Move> moves, float cost)
 {
     this.state    = state;
     this.children = new List <Node>();                  // Currently not used
     this.parent   = parent;
     this.moves    = new List <Move>(moves);
     this.cost     = cost;
 }
        public Enemy(Vector2f position, int direction, Element element)
        {
            float speed = Game.Rand.Next ((int)MIN_SPEED, (int)MAX_SPEED);
              int dir = UsefulTools.RandomPolarity ();
              Vector2f velocity = new Vector2f (dir * speed, 0);

              Init (position, velocity, element);

              HITBOX_INSET = new IntRect (31, 26, 34, 66);

              // Animation Stuff
              AnimationState = AState.Standing;
              VerticalState = VState.OnGround;

              UpdateHitbox ();

              ResetTimer ();
        }
Beispiel #4
0
        public static int GetSimilarityValue(string fileA, string fileB, bool forward, DiffMode mode)
        {
            int retVal = 0;

            string[] strArrayA;
            string[] strArrayB;

            int diagLength = 0;

            var snakes  = new List <Snake>();
            var vstates = new List <VState>();

            if (mode == DiffMode.SlowByChar)
            {
                string strA = System.IO.File.ReadAllText(fileA);
                string strB = System.IO.File.ReadAllText(fileB);

                strA = strA.RemoveWhitespace();
                strB = strB.RemoveWhitespace();

                strArrayA = strA.ToCharArray().Select(c => c.ToString()).ToArray();
                strArrayB = strB.ToCharArray().Select(c => c.ToString()).ToArray();
            }

            else
            {
                strArrayA = System.IO.File.ReadAllLines(fileA);
                strArrayB = System.IO.File.ReadAllLines(fileB);
            }

            var VState = new VState(strArrayA.Length, strArrayB.Length);

            diagLength = CompareStr(snakes, vstates, strArrayA, strArrayA.Length, strArrayB, strArrayB.Length, VState, forward);

            retVal = ComputeSimilarityPercentage2(strArrayA.Length, strArrayB.Length, diagLength);


            // return new Results(V.Memory, snakes, forward, vs);
            return(retVal);
        }
        public PlayerObj(int playerNumber)
        {
            PlayerNumber = playerNumber;

              Element element = PlayerElements [PlayerNumber];
              Dimensions = DAO.GetSprite (element).TextureRect;
              Position = Controller.PlayerStartPos [PlayerNumber];

              Init (Position, new Vector2f (0, 0), element);

              // States
              AnimationState = AState.Standing;
              VerticalState = VState.OnGround;

              // Set Custom Hitbox
              HITBOX_INSET = new IntRect (32, 32, 32, 56);

              ActionPoint = new Vector2f (HITBOX_INSET.Width / 2, HITBOX_INSET.Height);
              UpdateHitbox ();

              ResetTimer ();
        }
 public void OnGround(Tile tile)
 {
     // Check if state is being thrown
       if (AnimationState == AState.Thrown) {
     Velocity.X = 0;
     Velocity.Y = 0;
       } else if (VerticalState != VState.Jumping) {
     SetY (tile.HitBox.Top - (Dimensions.Height - HitBox.Height));
     Velocity.Y = 0;
     VerticalState = VState.OnGround;
       }
 }
        public void Fall()
        {
            if (VerticalState == VState.OnGround)
            ChangeDirection ();

              if (Velocity.Y > 0)
            VerticalState = VState.Falling;
              else if (Velocity.Y < 0)
            VerticalState = VState.Jumping;
        }
Beispiel #8
0
        static int CompareStr(List <Snake> snakes, IList <VState> vStates, string[] pa, int N, string[] pb, int M, VState VState, bool forward)
        {
            // Debug.WriteLine("\n\nDiffGreedy " + (forward ? "FORWARD" : "REVERSE") + " ( " + N + ", " + M + " )");

            Snake last = null;

            int DELTA = N - M;

            int diagLength = 0;

            int d = 0;

            for (; d <= (N + M); d++)
            {
                // Debug.WriteLine( "Calculating d: " + d );

                last = DAlgoStr(pa, N, pb, M, VState, d);

                vStates.Add(VState.CreateCopy(d, 0));

                if (last != null)
                {
                    break;
                }
            }

            if (last == null)
            {
                throw new InvalidOperationException("No solution was found!");
            }

            // Debug.WriteLine( "Solution D: " + d + " " + last );

            diagLength = SolveForwardStr(snakes, vStates, pa, pb, N, M);

            return(diagLength);
        }
Beispiel #9
0
 // Constructor without moves, sets moves to empty list
 public Node(VState state, Node parent)
     : this(state, parent, new List <Move>(), 0.0f)
 {
 }
 public void ResetPosition()
 {
     SetPosition (Controller.PlayerStartPos [PlayerNumber]);
       AnimationState = AState.Standing;
       VerticalState = VState.OnGround;
       Velocity.X = 0;
       Velocity.Y = 0;
       ResetShooting ();
 }
 public void OnGround(Tile tile)
 {
     if (VerticalState != VState.Jumping) {
     SetY (tile.HitBox.Top - (Dimensions.Height - HitBox.Height));
     Velocity.Y = 0;
     VerticalState = VState.OnGround;
       }
 }
 public void Fall()
 {
     if (Velocity.Y > 0)
     VerticalState = VState.Falling;
       else if (Velocity.Y < 0)
     VerticalState = VState.Jumping;
 }