コード例 #1
0
        /// <summary>
        /// calculates the angle of an attacking pirate on us ralative to the target we are sailing to.
        /// </summary>
        /// <param name="pirate"></param>
        /// <param name="enemy"></param>
        /// <param name="target"></param>
        /// <returns></returns>
        public int CalculateAngleOfAttack(Pirate pirate, Pirate enemy, Location target)
        {
            //crate 2 vectors
            Location U = target.Subtract(pirate.Location);         //from pirate to target
            Location V = enemy.Location.Subtract(pirate.Location); //from pirate to enemy

            double cosAngle = ((U.Col * V.Col) + (U.Row * V.Row)) / (System.Math.Sqrt((U.Row ^ 2) + (U.Col ^ 2)) * System.Math.Sqrt((V.Row ^ 2) + (V.Col ^ 2)));
            double radAngle = 0;

            if (cosAngle <= 1 && cosAngle >= -1)
            {
                radAngle = System.Math.Acos(cosAngle);
            }
            return((int)(radAngle * (180 / System.Math.PI)));
        }
コード例 #2
0
        // Same as before, but now consider turns too
        public Location PredictLocationByMovement(SpaceObject obj, int turns)
        {
            List <SpaceObject> spaceObjects    = new List <SpaceObject>();
            Location           currentLocation = null;

            if (obj.Location != null)
            {
                currentLocation = obj.Location;
                GameSettings.Game.Debug("obl location != null" + currentLocation);
            }
            else
            {
                GameSettings.Game.Debug("obl location == null");
                return(null);
            }
            Location previousLocation = null;

            // Location initialLocation = null;

            // First, check the type of obj
            if (obj is Pirate)
            {
                Pirate pirate = obj as Pirate;
                if (GameSettings.Game.Turn == 0)
                {
                    return(pirate.InitialLocation);
                }
                foreach (Pirate p in GameSettings.Game.GetEnemyLivingPirates())
                {
                    if (pirate.Equals(p))
                    {
                        previousLocation = GameSettings.LastGameEnemyPirates[pirate.Id];
                        // initialLocation = p.InitialLocation;
                        // GameSettings.Game.Debug("pervious location "+previousLocation);
                    }
                }

                foreach (Pirate p in GameSettings.Game.GetMyLivingPirates())
                {
                    if (pirate.Equals(p))
                    {
                        previousLocation = GameSettings.LastGameMyLivingPirates[p.Id];
                        // initialLocation = p.InitialLocation;
                        // GameSettings.Game.Debug("pervious location "+previousLocation);
                    }
                }
                // spaceObjects.AddRange(GameSettings.LastGameMyLivingPirates[GameSettings..Count - 2].GetEnemyLivingPirates().ToList());
            }
            else if (obj is Asteroid)
            {
                Asteroid asteroid = obj as Asteroid;
                if (GameSettings.Game.Turn == 0)
                {
                    return(asteroid.InitialLocation);
                }
                previousLocation = GameSettings.LastGameLivingAsteroids[asteroid.Id];
                // initialLocation = asteroid.InitialLocation;
                // GameSettings.Game.Debug("pervious location "+previousLocation);
            }
            else if (obj is Wormhole)
            {
                Wormhole wormhole = obj as Wormhole;
                if (GameSettings.Game.Turn == 0)
                {
                    return(wormhole.InitialLocation);
                }
                previousLocation = GameSettings.LastGameWormholes[wormhole.Id];
                // initialLocation = wormhole.InitialLocation;
                // GameSettings.Game.Debug("pervious location "+previousLocation);

                // spaceObjects.AddRange(GameSettings.GameList[GameSettings.GameList.Count - 2].GetLivingAsteroids().ToList());
            }
            else
            {
                return(null);
            }

            /*foreach (SpaceObject movingObj in spaceObjects) // Check on every SpaceObject on the list defined before:
             * {
             *  if (movingObj.Id == obj.Id) // Is it the original object?
             *  {
             *      previousLocation = movingObj.Location; // Then get it's past Location! put it in "previousLocation"
             *      // break;
             *  }
             * }*/

            // Now, calculate it's predicted Location
            GameSettings.Game.Debug("boo");
            if (previousLocation != null)
            {
                GameSettings.Game.Debug("previousLocation != null");
                Location substraction = currentLocation.Subtract(previousLocation);
                Location nextLocation = currentLocation;
                // GameSettings.Game.Debug("movment "+substraction);
                for (int i = 0; i < turns; i++)
                {
                    nextLocation = nextLocation.Add(substraction);
                }
                // GameSettings.Game.Debug("next turns location "+nextLocation);
                return(nextLocation);
            }
            else
            {
                GameSettings.Game.Debug("previousLocation == null");
                return(null);
            }
        }