示例#1
0
        private MapCoordinates FindEnemyUnitClosestDestination(Unit unit)
        {
            //_log.Debug("FindEnemyUnitClosestDestination()");

            var    surroundingCells     = _map.FindAdjacentCells(unit.Col, unit.Row, unit.UnitType, 1);
            double shortestDistance     = 9999;
            int    shortestDistanceItem = -1;

            // choose the next closest cell between the unit and dest.
            for (int i = 0; i < surroundingCells.Count; i++)
            {
                if (!_units.IsMapOccupied(surroundingCells[i].Col, surroundingCells[i].Row))
                {
                    double distance = BattleFieldOneCommonObjects.Distance(surroundingCells[i].Col, surroundingCells[i].Row, unit.Col,
                                                                           unit.Row);
                    if (distance < shortestDistance)
                    {
                        shortestDistance     = distance;
                        shortestDistanceItem = i;
                    }
                }
            }

            if (shortestDistanceItem > -1)
            {
                return(surroundingCells[shortestDistanceItem]);
            }

            return(null);
        }
示例#2
0
        public MapCoordinates FindClosestCity(int col, int row)
        {
            double closestDistance = 9999;
            var    index           = -1;

            for (var i = 0; i < CityList.Count; i++)
            {
                var distance = BattleFieldOneCommonObjects.Distance(CityList[i].Col, CityList[i].Row, col, row);
                if (distance < closestDistance)
                {
                    closestDistance = distance;
                    index           = i;
                }
            }

            if (index > -1)
            {
                return(new MapCoordinates(CityList[index].Col, CityList[index].Row));
            }

            return(null);
        }
示例#3
0
        public int FindClosestUnassignedUnit(int col, int row, NATIONALITY nationality)
        {
            var liDistance    = double.MaxValue;          // just make sure this is bigger than the map board
            var liClosestUnit = -1;

            for (var i = 0; i < _unitList.Count; i++)
            {
                if (_unitList[i].Nationality == nationality && _unitList[i].Command == UNITCOMMAND.None)
                {
                    if (_unitList[i].Col != col && _unitList[i].Row != row)
                    {
                        var liTempDistance = BattleFieldOneCommonObjects.Distance(col, row, _unitList[i].Col, _unitList[i].Row);
                        if (liTempDistance < liDistance)
                        {
                            liDistance    = liTempDistance;
                            liClosestUnit = i;
                        }
                    }
                }
            }

            return(liClosestUnit);
        }