Ejemplo n.º 1
0
        private static void WriteMazeInManual(HexamazeInfo maze)
        {
            const double hexWidth = 72;

            foreach (var path in new[] { @"D:\c\KTANE\HTML\Hexamaze.html", @"D:\c\KTANE\Hexamaze\Manual\Hexamaze.html" })
            {
                // Create the color chart (top-left of the manual page)
                File.WriteAllText(path, Regex.Replace(File.ReadAllText(path), @"(?<=<!--%%-->).*(?=<!--%%%-->)", options: RegexOptions.Singleline, replacement: $@"
                <svg class='legend' viewBox='-325 -375 650 750'>
                    {"red,yellow,green,cyan,blue,pink".Split(',').Select((color, i) => $"<g class='label' transform='rotate({330 + 60 * i})'><text text-anchor='middle' y='-280'>{color}</text><path d='M-124.7-150v-200M124.7-150v-200' /></g>").JoinString()}
                    <polygon class='outline' points='{Hex.LargeHexagonOutline(4, hexWidth).Select(p => $"{p.X},{p.Y}").JoinString(" ")}' />
                    {Hex.LargeHexagon(4).Select(h => h.GetCenter(hexWidth)).Select(p => $"<circle class='dot' cx='{p.X}' cy='{p.Y}' r='{hexWidth / 12}' />").JoinString()}
                </svg>"));

                // Create the main maze in the manual page
                File.WriteAllText(path, Regex.Replace(File.ReadAllText(path), @"(?<=<!--##-->).*(?=<!--###-->)", maze.CreateSvg(), RegexOptions.Singleline));
            }
        }
Ejemplo n.º 2
0
        private static bool areMarkingsUnique(HexamazeInfo maze, bool saveFiles = false)
        {
            var ambig     = 1;
            var size      = maze.Size;
            var smallSize = maze.SubmazeSize;
            var unique    = new Dictionary <string, List <Tuple <Hex, int> > >();

            foreach (var centerHex in Hex.LargeHexagon(size - smallSize + 1))
            {
                for (int rotation = 0; rotation < 6; rotation++)
                {
                    var markingsStr = Hex.LargeHexagon(smallSize).Select(h => h.Rotate(rotation) + centerHex).Select(h => maze.Markings.Get(h, Marking.None).Rotate(-rotation)).ToMarkingString();
                    List <Tuple <Hex, int> > uniqs;
                    if (unique.TryGetValue(markingsStr, out uniqs) && uniqs.Count > 0)
                    {
                        if (saveFiles)
                        {
                            var fills1 = Tuple.Create(Hex.LargeHexagon(smallSize).Select(h => h.Rotate(uniqs[0].Item2) + uniqs[0].Item1), "fed");
                            var fills2 = Tuple.Create(Hex.LargeHexagon(smallSize).Select(h => h.Rotate(rotation) + centerHex), "def");
                            ambig++;
                            File.WriteAllText($@"D:\c\KTANE\HTML\Hexamaze{ambig}.html", Regex.Replace(File.ReadAllText(@"D:\c\KTANE\HTML\Hexamaze.html"), @"\A(.*<!--##-->\s*).*?(?=\s*<!--###-->)", options: RegexOptions.Singleline, evaluator: m => m.Groups[1].Value + maze.CreateSvg(new[] { fills1, fills2 })));
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    unique.AddSafe(markingsStr, Tuple.Create(centerHex, rotation));
                }
            }

            if (!saveFiles)
            {
                return(true);
            }

            foreach (var nonUnique in unique.Where(k => k.Value.Count > 1))
            {
                Console.WriteLine($"{nonUnique.Key} = {nonUnique.Value.Select(tup => $"{tup.Item1}/{(6 - tup.Item2) % 6}").JoinString(", ")}");
            }
            return(unique.All(kvp => kvp.Value.Count <= 1));
        }