protected override IEnumerator MakeRequestCoroutine(Action <WorldSimulationState> onComplete, Action onError)
        {
            WorldSimulationState state      = null;
            WorldIndex           worldIndex = null;

            _worldPersistanceService.Load((index) => worldIndex = index, () => { });

            yield return(new WaitUntil(() => worldIndex != null));

            string filepath = String.Join(DataConfig.DirectoryDelimiter, _indexGenerator.RootPath(Application.persistentDataPath), SimulationConfiguration.IndexFilename);

            var request = new LoadSimulationStateJob.LoadSimulationStateJobRequest(filepath);
            LoadSimulationStateJob loadJob = new LoadSimulationStateJob(request);

            loadJob.Start();

            yield return(new WaitUntil(() => loadJob.IsDone));

            if (loadJob.Output == null)
            {
                state = _simulationConfiguration.GenerateSimulationState(worldIndex);
            }
            else
            {
                state = loadJob.Output;
            }

            onComplete(state);
        }
Ejemplo n.º 2
0
        public void Within50KmFromMelbourne3000()
        {
            // The region Melbourne was initially defined to be 50km from 3000 so make
            // sure this still holds for now.

            var    locationReference = _locationQuery.ResolveLocation(_australia, "Melbourne");
            Region melbourneMetro    = locationReference.Region;

            locationReference = _locationQuery.ResolveLocation(_australia, "Melbourne VIC 3000");
            Locality melbourne3000 = locationReference.Locality;

            double   distMax    = 0;
            Locality mostRemote = null;

            foreach (Locality locality in _locationQuery.GetLocalities(melbourneMetro))
            {
                double dist = WorldIndex.EarthDistance(
                    melbourne3000.Centroid.Latitude, melbourne3000.Centroid.Longitude,
                    locality.Centroid.Latitude, locality.Centroid.Longitude);

                if (dist > distMax)
                {
                    distMax    = dist;
                    mostRemote = locality;
                }
            }

            Assert.IsTrue(distMax <= 50, "The '" + mostRemote.Name + "' locality has a distance + " + distMax + "km which is more than 50km away from Melbourne VIC 3000.");
        }
Ejemplo n.º 3
0
        public void Within50KmFromSydney2000()
        {
            var    locationReference = _locationQuery.ResolveLocation(_australia, "Sydney");
            Region sydneyMetro       = locationReference.Region;

            locationReference = _locationQuery.ResolveLocation(_australia, "Sydney NSW 2000");
            Locality sydney2000 = locationReference.Locality;

            double   distMax    = 0;
            Locality mostRemote = null;

            foreach (Locality locality in _locationQuery.GetLocalities(sydneyMetro))
            {
                double dist = WorldIndex.EarthDistance(
                    sydney2000.Centroid.Latitude, sydney2000.Centroid.Longitude,
                    locality.Centroid.Latitude, locality.Centroid.Longitude);

                if (dist > distMax)
                {
                    distMax    = dist;
                    mostRemote = locality;
                }
            }

            Assert.IsTrue(distMax <= 50, "The '" + mostRemote.Name + "' locality has a distance + " + distMax + "km which is more than 50km away from Sydney NSW 2000.");
        }
Ejemplo n.º 4
0
        public void Example4()
        {
            var baseWorld = LogicSolver.WorldService.GetNewWorldConstant();
            var baseIndex = new WorldIndex(baseWorld);

            var relation = new AccessibilityRelation(new List <IRelationProperty>()
            {
                new SerialProperty(),
                new TransitiveProperty()
            });

            //x
            var variable = LogicSolver.TermNamer.GetNewVariable();
            var func     = LogicSolver.TermNamer.GetNewFunction(new List <Terminal>()
            {
                variable
            });
            var baseFormula = new AtomicFormula(func, baseIndex);

            var formula = new BinaryFormula(
                new QuantifierFormula(new UnaryFormula(baseFormula, UnaryConnective.Necessity, baseIndex), variable, QuantifierConnective.ForAll, baseIndex),
                new UnaryFormula(new QuantifierFormula(baseFormula, variable, QuantifierConnective.ForAll, baseIndex), UnaryConnective.Necessity, baseIndex),
                BinaryConnective.Implication, baseIndex);

            var solver = new LogicSolver(relation);

            Assert.IsTrue(solver.Solve(formula));
        }
 public WorldDataAccess(WorldIndex worldIndex, DataConfig dataConfig)
 {
     _cache       = new Dictionary <string, LoadedArea>();
     _saveCache   = new Dictionary <string, SaveAreaJob>();
     _loadJobPool = new List <LoadAreaJob>();
     _worldIndex  = worldIndex;
     _dataConfig  = dataConfig;
 }
Ejemplo n.º 6
0
 public LoadAreaJob(WorldIndex index, DataConfig dataConfig, List <LoadedArea> loadedAreas, string areaDataDirectoryPath)
 {
     _worldIndex            = index;
     _areaDataDirectoryPath = areaDataDirectoryPath;
     _dataConfig            = dataConfig;
     _loadedAreasRequests   = new List <LoadedArea>();
     SetJob(loadedAreas);
 }
Ejemplo n.º 7
0
 public void WorldIndexTestsInitialize()
 {
     if (_world == null)
     {
         _world = new WorldIndex();
         _world.BuildUp(_locationQuery, true);
         _australia = _locationQuery.GetCountry("Australia");
     }
 }
    public WorldSimulationState GenerateSimulationState(WorldIndex worldIndex)
    {
        WorldSimulationState state = new WorldSimulationState();

        state.Dimensions          = Dimemsions;
        state.WorldDimensions     = worldIndex.Dimensions;
        state.Radius              = Radius;
        state.SimulationDevisions = SimulationDevisions;

        return(state);
    }
Ejemplo n.º 9
0
        // other

        private Point GetNextPosition()
        {
            Block[] blocks = CurrentFloor >= 0 ? Program.WorldMap[WorldIndex.X, WorldIndex.Y].Dungeon.Floors[CurrentFloor].Blocks : Program.WorldMap[WorldIndex.X, WorldIndex.Y].Blocks;
            int     width = Program.WorldMap[WorldIndex.X, WorldIndex.Y].Width, height = Program.WorldMap[WorldIndex.X, WorldIndex.Y].Height;

            int GetPosValue(Point pos)
            {
                bool playerIsNearby = WorldIndex.Equals(Program.Player.WorldIndex) && CurrentFloor == Program.Player.CurrentFloor && (Position.DistFrom(Program.Player.Position) <= SightDist);

                return((playerIsNearby ? Program.WorldMap[WorldIndex.X, WorldIndex.Y].DijkstraMaps.DistToPlayerMap[pos.X * width + pos.Y] * CurrentDesires[DesireType.KillPlayer] : 0)
                       + Program.WorldMap[WorldIndex.X, WorldIndex.Y].DijkstraMaps.DistToItemsMap[pos.X * width + pos.Y] * CurrentDesires[DesireType.Treasure]);
            }

            int GetPatrolPosValue(Point pos)
            {
                return(Program.WorldMap[WorldIndex.X, WorldIndex.Y].Dungeon.Floors[CurrentFloor].PatrolMaps.PatrolGoals[curPatrolDestIndex][pos.X * width + pos.Y]);
            }

            List <Point> bestPositions = new List <Point>();
            int          bestVal       = !patrolling?GetPosValue(Position) : GetPatrolPosValue(Position);

            for (int i = Math.Max(0, Position.X - 1); i <= Math.Min(width - 1, Position.X + 1); i++)
            {
                for (int j = Math.Max(0, Position.Y - 1); j <= Math.Min(height - 1, Position.Y + 1); j++)
                {
                    if (Position.Equals(new Point(i, j)) || blocks[i * width + j].Solid)
                    {
                        continue;
                    }

                    int thisVal = !patrolling?GetPosValue(new Point(i, j)) : GetPatrolPosValue(new Point(i, j));

                    if (thisVal <= bestVal)
                    {
                        bestPositions.Add(new Point(i, j));
                        bestVal = thisVal;
                    }
                }
            }

            for (int i = bestPositions.Count - 1; i >= 0; i--)
            {
                if ((!patrolling ? GetPosValue(bestPositions[i]) : GetPatrolPosValue(bestPositions[i])) != bestVal)
                {
                    bestPositions.RemoveAt(i);
                }
            }

            return(bestPositions.Count > 0 ? bestPositions[Program.RNG.Next(0, bestPositions.Count)] : new Point());
        }
Ejemplo n.º 10
0
    public WorldDataToken(TokenRequest request, WorldIndex index, LoadedArea[,] loadedAreas)
    {
        _areas = new AreaIndex[loadedAreas.GetLength(0), loadedAreas.GetLength(1)];

        for (int i = 0; i < loadedAreas.GetLength(0); i++)
        {
            for (int j = 0; j < loadedAreas.GetLength(1); j++)
            {
                _areas[i, j] = loadedAreas[i, j].Result.Result;
            }
        }

        _request     = request;
        _index       = index;
        _loadedAreas = loadedAreas;
    }
Ejemplo n.º 11
0
        public void EarthDistanceTest()
        {
            // Distance between poles
            double distance = WorldIndex.EarthDistance(90, 0, -90, 0);

            Assert.AreEqual(20021, (int)Math.Round(distance));

            // Distance between pole and equator
            distance = WorldIndex.EarthDistance(90, 0, 0, 0);
            Assert.AreEqual(10010, (int)Math.Round(distance));

            // Distance between LAX and BNA (as per http://en.wikipedia.org/wiki/Great-circle_distance)
            distance = WorldIndex.EarthDistance(36.12, -86.67, 33.94, -118.40);
            Assert.AreEqual(2887, (int)Math.Round(distance));

            // Distance between Bentleigh and StKilda
            distance = WorldIndex.EarthDistance(-33.65436, 151.279053, -33.62562, 151.146759);
            Assert.AreEqual(13, (int)Math.Round(distance));
        }
Ejemplo n.º 12
0
        protected override IEnumerator MakeRequestCoroutine(Action <WorldDataAccess> onComplete, Action onError)
        {
            WorldIndex index    = null;
            bool       hasError = false;

            _worldPersistanceService.Load((worldIndex) => { index = worldIndex; }, () => { hasError = true; });

            while (index == null && !hasError)
            {
                yield return(null);
            }

            if (hasError)
            {
                onError();
            }
            else
            {
                onComplete(new WorldDataAccess(index, _dataConfig));
            }
        }
Ejemplo n.º 13
0
    public WorldIndex Load(string persistentDataPath)
    {
        SharpSerializer serializer = new SharpSerializer();
        WorldIndex      index      = null;

        string worldDirectory = string.Join(DataConfig.DirectoryDelimiter, new string[] { persistentDataPath, _dataConfig.GetRelativeWorldIndexPath(_uid) });
        string areaDirectory  = string.Join(DataConfig.DirectoryDelimiter, new string[] { worldDirectory, _dataConfig.AreaDataRelativeDirectory });
        string indexFilePath  = string.Join(DataConfig.DirectoryDelimiter, new string[] { worldDirectory, _dataConfig.IndexFilename });

        FileStream fileStream = File.Open(indexFilePath, FileMode.Open);

        Debug.Log("Loading World from " + indexFilePath);

        using (var stream = fileStream)
        {
            index = serializer.Deserialize(stream) as WorldIndex;
        }

        index.SetGenerator(this);

        return(index);
    }
Ejemplo n.º 14
0
    public WorldIndex Generate(string persistentDataPath)
    {
        SharpSerializer serializer = new SharpSerializer();

        WorldIndex index = new WorldIndex();

        index.Dimensions = _dimensions;
        index.AreaFilenameFormatSource = _dataConfig.AreaFilenameFormatSource;
        index.AreaRelativeDirectory    = _dataConfig.AreaDataRelativeDirectory;
        index.FileDataExtension        = _dataConfig.DataFileExtensions;
        index.Version           = _dataConfig.Version;
        index.SerializationType = _dataConfig.AreaSerializationType;
        index.AreaDimensions    = _dataConfig.AreaDimensions;

        string worldDirectory = string.Join(DataConfig.DirectoryDelimiter, new string[] { persistentDataPath, _dataConfig.GetRelativeWorldIndexPath(_uid) });
        string areaDirectory  = string.Join(DataConfig.DirectoryDelimiter, new string[] { worldDirectory, _dataConfig.AreaDataRelativeDirectory });
        string indexFilePath  = string.Join(DataConfig.DirectoryDelimiter, new string[] { worldDirectory, _dataConfig.IndexFilename });

        int areaDimensions = _dataConfig.AreaDimensions;

        Debug.Log("Saving World to " + indexFilePath);

        Directory.CreateDirectory(worldDirectory);
        Directory.CreateDirectory(areaDirectory);
        FileStream fileStream = File.Open(indexFilePath, FileMode.CreateNew);

        using (var stream = fileStream)
        {
            serializer.Serialize(index, fileStream);
        }

        int horizontalAreaCount = _dimensions.Width / areaDimensions;
        int verticalAreaCount   = _dimensions.Width / areaDimensions;

        for (int i = 0; i < horizontalAreaCount; i++)
        {
            for (int j = 0; j < horizontalAreaCount; j++)
            {
                AreaIndex area = new AreaIndex();

                area.DataLayer = new DataLayer();
                area.DataLayer.NoiseLayerData  = _cloudLayer.GenerateData(_dimensions, areaDimensions, i, j);
                area.DataLayer.WaterLayerData  = _waterLayer.GenerateData(_dimensions, areaDimensions, i, j);
                area.DataLayer.HeightLayerData = _heightLayer.GenerateData(_dimensions, areaDimensions, i, j);

                string     filename       = string.Format(_dataConfig.AreaFilenameFormatSource, i, j, _dataConfig.DataFileExtensions);
                FileStream areaFileStream = File.Open(String.Join(DataConfig.DirectoryDelimiter, new string[] { areaDirectory, filename }), FileMode.CreateNew);

                switch (_dataConfig.AreaSerializationType)
                {
                case SerializationType.Binary:
                    BinaryFormatter bf = new BinaryFormatter();
                    bf.Serialize(areaFileStream, area);
                    break;

                case SerializationType.SharpSerializer:
                    using (var stream = areaFileStream)
                    {
                        serializer.Serialize(area, areaFileStream);
                    }

                    break;
                }

                areaFileStream.Close();
            }
        }

        return(index);
    }
Ejemplo n.º 15
0
        static void Main(string[] args)
        {
            Console.OutputEncoding = new UnicodeEncoding();
            Console.WriteLine("Hello World!");

            #region test8

            //var baseWorld = new ConstantWorldSymbol("0");
            //var baseIndex = new WorldIndex(baseWorld);

            //var relation = new AccessibilityRelation(new List<IRelationProperty>()  {
            //        new SerialProperty()
            //});


            //var variable = LogicSolver.TermNamer.GetNewVariable();
            //var atomicFormula = new AtomicFormula(LogicSolver.TermNamer.GetNewFunction(new List<Terminal>() { variable }), baseIndex);
            //var formula = new BinaryFormula(
            //    new QuantifierFormula(new UnaryFormula(atomicFormula, UnaryConnective.Necessity, baseIndex), variable, QuantifierConnective.ForAll, baseIndex),
            //    new UnaryFormula(new QuantifierFormula(atomicFormula, variable, QuantifierConnective.ForAll, baseIndex), UnaryConnective.Necessity, baseIndex),
            //    BinaryConnective.Implication, baseIndex);

            #endregion

            #region test1

            var baseWorld = LogicSolver.WorldService.GetNewWorldConstant();
            var baseIndex = new WorldIndex(baseWorld);

            var relation = new AccessibilityRelation(new List <IRelationProperty>()
            {
                new SerialProperty(),
                new TransitiveProperty()
            });

            var variable    = LogicSolver.TermNamer.GetNewVariable();
            var baseFormula = new AtomicFormula(variable, baseIndex);
            var formula     = new BinaryFormula(
                new UnaryFormula(baseFormula, UnaryConnective.Necessity, baseIndex),
                new UnaryFormula(new UnaryFormula(baseFormula, UnaryConnective.Necessity, baseIndex), UnaryConnective.Necessity, baseIndex),
                BinaryConnective.Implication, baseIndex);

            #endregion

            //Example9
            #region test2

            //var baseWorld = LogicSolver.WorldService.GetNewWorldConstant();
            //var baseIndex = new WorldIndex(baseWorld);

            //var relation = new AccessibilityRelation(new List<IRelationProperty>() {
            //    new SerialProperty(),
            //    new TransitiveProperty()
            //});

            //var variable = LogicSolver.TermNamer.GetNewVariable();
            //var atomicFormula = new AtomicFormula(LogicSolver.TermNamer.GetNewFunction(new List<Terminal>() { variable }), baseIndex);
            //var formula = new BinaryFormula(
            //    new UnaryFormula(new QuantifierFormula(atomicFormula, variable, QuantifierConnective.ForAll, baseIndex), UnaryConnective.Necessity, baseIndex),
            //    new QuantifierFormula(new UnaryFormula(atomicFormula, UnaryConnective.Necessity, baseIndex), variable, QuantifierConnective.ForAll, baseIndex),
            //    BinaryConnective.Implication, baseIndex);

            #endregion

            Console.WriteLine();
            Console.WriteLine("Formula: " + formula.ToWorldString());
            var solver = new LogicSolver(relation);
            var result = solver.Solve(formula);

            Console.WriteLine("Proof found: " + result);
        }
Ejemplo n.º 16
0
 public SaveAreaJob(List <SaveAreaRequest> requests, WorldIndex worldIndex)
 {
     _requests   = requests;
     _worldIndex = worldIndex;
 }