コード例 #1
0
ファイル: RiskyMoonSolution.cs プロジェクト: ungood/puzzles
        public void PrintSolution()
        {
            var latticeCalculator = new SliceSphereLatticeCalculator(new TurtleCircleLatticeCalculator());
            var riskCalculator = new AStarRiskCalculator();

            var puzzle = new RiskyMoonPuzzle(latticeCalculator, riskCalculator);

            Console.WriteLine("Solution: {0:N10}", puzzle.Solve());
        }
コード例 #2
0
ファイル: SphereLatticeTests.cs プロジェクト: ungood/puzzles
        public void CompareSliceToNaiveForVariousRadii([Range(2, 20)] int radius)
        {
            var naive = new ParallelNaiveSphereLatticeCalculator();
            var slice = new SliceSphereLatticeCalculator(new TurtleCircleLatticeCalculator());

            var expected = naive.FindLatticePoints(radius).ToArray();
            var actual = slice.FindLatticePoints(radius);

            actual.AssertSequenceEquivalentTo(expected);
        }
コード例 #3
0
ファイル: RiskCalculatorTests.cs プロジェクト: ungood/puzzles
        public void FirstFiftyGroupedByRisk()
        {
            var latticeCalculator = new SliceSphereLatticeCalculator(new TurtleCircleLatticeCalculator());
            var riskCalculator = new AStarRiskCalculator();

            var groups = Enumerable.Range(1, 50).AsParallel()
                .Select(radius =>
                {
                    var stations = latticeCalculator.FindLatticePoints(radius).Select(coord => new Station(coord));
                    return riskCalculator.CalculateRisk(stations, radius);
                })
                .GroupBy(result => result.TotalRisk)
                .OrderBy(grp => grp.Key);

            foreach(var grp in groups)
            {
                Console.Write("{0}, {1}:", grp.Key, grp.First().TotalDistanceRatio);
                foreach(var value in grp.OrderBy(result => result.Radius))
                {
                    Console.Write(" {0:N0}", value.Radius);
                }
                Console.WriteLine();
            }
        }
コード例 #4
0
ファイル: RiskCalculatorTests.cs プロジェクト: ungood/puzzles
        private RiskResult FindResult(int radius)
        {
            var latticeCalculator = new SliceSphereLatticeCalculator(new TurtleCircleLatticeCalculator());
            var riskCalculator = new AStarRiskCalculator();

            var stations = latticeCalculator.FindLatticePoints(radius).Select(coord => new Station(coord));
            return riskCalculator.CalculateRisk(stations, radius);
        }
コード例 #5
0
ファイル: RiskCalculatorTests.cs プロジェクト: ungood/puzzles
        public void MaxZ()
        {
            var latticeCalculator = new SliceSphereLatticeCalculator(new TurtleCircleLatticeCalculator());
            var riskCalculator = new AStarRiskCalculator();

            var results = Enumerable.Range(1, 50).AsParallel()
                .Select(radius =>
                {
                    var stations = latticeCalculator.FindLatticePoints(radius).Select(coord => new Station(coord));
                    return riskCalculator.CalculateRisk(stations, radius);
                })
                .OrderBy(result => result.Radius);

            foreach (var result in results)
            {
                var maxZ = result.Path.Max(path => path.Source.CartesianLocation.Z - path.Target.CartesianLocation.Z);
                Console.WriteLine("{0}: {1}", result.Radius, maxZ);
            }
        }