Beispiel #1
0
        public List<Direction> GetDirection(Location loc1, Location loc2)
        {
            List<Direction> directions = new List<Direction>();
            if (loc1.row < loc2.row)
            {
                if (loc2.row - loc1.row >= this.rows / 2)
                {
                    directions.Add(Direction.NORTH);
                }
                else
                {
                    directions.Add(Direction.SOUTH);
                }
            }
            else if (loc1.row > loc2.row)
            {
                if (loc1.row - loc2.row >= this.rows / 2)
                {
                    directions.Add(Direction.SOUTH);
                }
                else
                {
                    directions.Add(Direction.NORTH);
                }
            }

            if (loc1.col < loc2.col)
            {
                if (loc2.col - loc1.col >= this.cols / 2)
                {
                    directions.Add(Direction.WEST);
                }
                else
                {
                    directions.Add(Direction.EAST);
                }
            }
            else if (loc1.col > loc2.col)
            {
                if (loc1.col - loc2.col >= this.cols / 2)
                {
                    directions.Add(Direction.WEST);
                }
                else
                {
                    directions.Add(Direction.EAST);
                }
            }
            return directions;
        }
Beispiel #2
0
 /// <summary>
 /// Create a new location constrained by the map size by moving in the direction specified
 /// </summary>
 /// <param name="loc">original location</param>
 /// <param name="direction">direction to move</param>
 /// <returns>location created after moving in direction from original location</returns>
 public Location GetLocation(Location loc, Direction direction)
 {
     return new Location((loc.row + this.DIRECTIONS[(int)direction, 0]) % rows, (loc.col + this.DIRECTIONS[(int)direction, 1]) % cols);
 }
Beispiel #3
0
 public bool IsUnoccupied(Location loc)
 {
     // land, food and dead are unoccupied
     if (this.game_map[loc.row, loc.col] == Game.LAND || this.game_map[loc.row, loc.col] == Game.FOOD || this.game_map[loc.row, loc.col] == Game.DEAD)
     {
         return true;
     }
     // eg Player A to Z, or Game.Water
     return false;
 }
Beispiel #4
0
        // returns the eclidean distance between two locations
        public double GetDistance(Location loc1, Location loc2)
        {
            int d1 = Math.Abs(loc1.row - loc2.row),
                d2 = Math.Abs(loc1.col - loc2.col),
                dr = Math.Min(d1, this.rows - d1),
                dc = Math.Min(d2, this.cols - d2);

            return Math.Sqrt(dr * dr + dc * dc);
        }