예제 #1
0
        public void Build_ValidOptions_MapGenerated()
        {
            IJson       json           = new Json();
            IMapFactory mapFactory     = new MapFactory();
            IRandom     random         = new FastRandom();
            var         manager        = new TerrainManager(json);
            var         options        = default(MapGeneratorOptions);
            var         terrainOptions = default(MountainsideTerrainGeneratorOptions);

            using (StreamReader reader = GetText("generator.json")) {
                options = json.Deserialize <MapGeneratorOptions>(reader.ReadToEnd());
            }
            using (StreamReader reader = GetText("terraingenerator.json")) {
                terrainOptions = json.Deserialize <MountainsideTerrainGeneratorOptions>(reader.ReadToEnd());
            }
            using (StreamReader reader = GetText("terrain.json")) {
                manager.Load(reader);
            }
            IMapTerrainGenerator generator = new MountainsideTerrainGenerator(random, manager, options, terrainOptions);
            IMap map = mapFactory.Create(options.Rows, options.Columns, generator.Initialize);

            generator.Build(map);

            Assert.IsNotNull(map);

            WriteMapToImage(map);
        }
예제 #2
0
        static void Main(string[] args)
        {
            var map = ManualInput ? new InputHelper().HandleInput() : MapFactory.Create(Maps.Hard3);

            Console.Clear();
            Console.WriteLine("Sudoku to solve: ");
            Console.WriteLine(map + "\n");

            var stopwatch = new Stopwatch();

            stopwatch.Start();

            var solver = new SudokuSolver();

            solver.AddStrategy(new CandidateChecking());
            solver.AddStrategy(new Backtracking());
            var solution = solver.Solve(map);

            stopwatch.Stop();
            if (solution.IsSolved)
            {
                Console.WriteLine($"\nSolution ({stopwatch.ElapsedMilliseconds} ms):");
                Console.WriteLine(solution);
            }
            else
            {
                Console.WriteLine($"\nSudoku could not be solved ({stopwatch.ElapsedMilliseconds} ms)");
            }

            Console.ReadLine();
        }
예제 #3
0
파일: Server.cs 프로젝트: liuqimin/MagCore
 private static void LoadMaps()
 {
     if (Directory.Exists(_path))
     {
         var files = Directory.GetFiles(_path, "*.map", SearchOption.AllDirectories);
         foreach (var file in files)
         {
             var map = MapFactory.Create(file);
             _maps.Add(map.Name.Trim().ToLower(), map);
         }
     }
 }
예제 #4
0
        public void TestRectMapLoad()
        {
            var map = MapFactory.Create(@"E:\github\MagCore\src\server\MagCore.Server\Maps\RectSmall.map");

            Assert.IsNotNull(map);
            Assert.AreEqual(map.Size.H, 10);
            Assert.AreEqual(map.Size.W, 10);

            for (int i = 0; i < map.Rows.Count; i++)
            {
                for (int j = 0; j < map.Rows[i].Count; j++)
                {
                    Debug.Write((int)map.Rows[i].Cells[j].Type);
                }
                Debug.WriteLine("");
            }
        }
예제 #5
0
        public void OneTimeSetUp()
        {
            IMapFactory factory = new MapFactory();

            _map = factory.Create(10, 10, DefaultInitializer);
        }