Ejemplo n.º 1
0
        private void WriteKeypadsManual(string path, ManualFileName file, ref List <ReplaceText> replacements)
        {
            var table = string.Empty;
            var rules = _ruleManager.KeypadRuleSet.PrecedenceLists;

            for (var i = 0; i < rules[0].Count; i++)
            {
                table += "                                <tr>\n";
                for (var j = 0; j < rules.Count; j++)
                {
                    table += "                                    <td class=\"keypad-table-column\"><img class=\"keypad-symbol-image\" src=\"";

                    var index = ManualGenerator.KeypadSymbols.IndexOf(rules[j][i], StringComparison.Ordinal);
                    table += _keypadFiles[index].Name.Replace(Path.DirectorySeparatorChar, '/');
                    table += "\"></img>";
                    table += "                                    </td>\n";
                    if (j == (rules.Count - 1))
                    {
                        break;
                    }
                    table += "                                    <td class=\"keypad-table-spacer\"></td>\n";
                }
                table += "                                </tr>\n";
            }
            replacements.Add(new ReplaceText()
            {
                Original = "<!--KEYPADTABLE GOES HERE-->", Replacement = table
            });
            foreach (var imagefile in _keypadFiles)
            {
                imagefile.WriteFile(path);
            }

            file.WriteFile(path, replacements);
        }
Ejemplo n.º 2
0
        private void WriteButtonManual(string path, ManualFileName file, ref List <ReplaceText> replacements)
        {
            var initial   = string.Empty;
            var onhold    = string.Empty;
            var portsused = false;

            foreach (var press in _ruleManager.ButtonRuleSet.RuleList)
            {
                portsused = press.Queries.Aggregate(portsused, (current, query) => current | query.Property == QueryablePorts.EmptyPortPlate);
                portsused = press.Queries.Aggregate(portsused, (current, query) => current | QueryablePorts.PortList.Contains(query.Property));
            }

            initial = _ruleManager.ButtonRuleSet.RuleList.Aggregate(initial, (current, press) => current + $"<li>If {press.GetQueryString()}, {press.GetSolutionString()}.</li>\n");
            onhold  = _ruleManager.ButtonRuleSet.HoldRuleList.Aggregate(onhold, (current, hold) => current + $"<li><em>{hold.GetQueryString()}</em> {hold.GetSolutionString()}</li>\n");

            replacements.Add(new ReplaceText {
                Original = "APPENDIXCREFERENCE", Replacement = portsused ? "<br />See Appendix C for port identification reference." : ""
            });
            replacements.Add(new ReplaceText {
                Original = "INITIALBUTTONRULES", Replacement = initial
            });
            replacements.Add(new ReplaceText {
                Original = "ONBUTTONHOLDRULES", Replacement = onhold
            });
            file.WriteFile(path, replacements);
        }
Ejemplo n.º 3
0
        private void WriteWiresManual(string path, ManualFileName file, ref List <ReplaceText> replacements)
        {
            var wirecuttinginstructions = string.Empty;
            var wirerules = _ruleManager.WireRuleSet.RulesDictionary;

            foreach (var rules in wirerules)
            {
                var rule = new List <Rule>(rules.Value);

                wirecuttinginstructions += $"<tr><td><strong><em>{rules.Key} wires:</em></strong><br />\n";
                if (rule.Count == 1)
                {
                    wirecuttinginstructions += $"{rule[0].GetSolutionString()}.\n";
                }
                else
                {
                    wirecuttinginstructions += $"If {rule[0].GetQueryString()}, {rule[0].GetSolutionString()}.\n";
                    for (var i = 1; i < rule.Count - 1; i++)
                    {
                        wirecuttinginstructions += $"<br />Otherwise, If {rule[i].GetQueryString()}, {rule[i].GetSolutionString()}.\n";
                    }
                    wirecuttinginstructions += $"<br />Otherwise, {rule.Last().GetSolutionString()}.\n";
                }
            }


            replacements.Add(new ReplaceText {
                Original = "WIRECUTTINGINSTRUCTIONS", Replacement = wirecuttinginstructions
            });
            file.WriteFile(path, replacements);
        }
Ejemplo n.º 4
0
        private void WriteMorseCodeManaul(string path, ManualFileName file, ref List <ReplaceText> replacements)
        {
            var worddict       = _ruleManager.MorseCodeRuleSet.WordDict;
            var validFreqs     = _ruleManager.MorseCodeRuleSet.ValidFrequencies;
            var morsecodetable = validFreqs.Aggregate(string.Empty, (current, freq) => current + $"<tr><td>{worddict[freq]}</td><td>3.{freq} MHz</td></tr>\n");

            replacements.Add(new ReplaceText {
                Original = "MORSECODELOOKUP", Replacement = morsecodetable
            });
            file.WriteFile(path, replacements);
        }
Ejemplo n.º 5
0
        private void WriteMazesManual(string path, ManualFileName file, ref List <ReplaceText> replacements)
        {
            var mazes = _ruleManager.MazeRuleSet.GetMazes();

            for (var i = 0; i < mazes.Count; i++)
            {
                replacements.Add(new ReplaceText {
                    Original = $"MAZE{i}SVGDATA", Replacement = mazes[i].ToSVG().Replace("<svg ", "<svg class=\"maze\" ")
                });
            }
            file.WriteFile(path, replacements);
        }
Ejemplo n.º 6
0
        private void WritePasswordManual(string path, ManualFileName file, ref List <ReplaceText> replacements)
        {
            var passwordrules = _ruleManager.PasswordRuleSet.possibilities;

            for (var i = 0; i < passwordrules.Count; i++)
            {
                replacements.Add(new ReplaceText {
                    Original = $"PASSWORD{i:00}", Replacement = passwordrules[i]
                });
            }

            file.WriteFile(path, replacements);
        }
Ejemplo n.º 7
0
        private void WriteWireSequenceManual(string path, ManualFileName file, ref List <ReplaceText> replacements)
        {
            var wiresequencetable = string.Empty;
            var wireLetters       = new[] { "A", "B", "C" };

            for (var i = WireSequenceRuleSetGenerator.NUM_COLOURS - 1; i >= 0; i--)
            {
                var color = (WireColor)i;
                wiresequencetable += $"<table class=\'{color}'>";
                wiresequencetable += $"<tr><th colspan=\'2\' class=\'header\'>{color.ToString().Capitalize()} Wire Occurrences</th></tr>";
                wiresequencetable += "<tr><th class=\'first-col\'>Wire Occurrence</th><th class=\'second-col\'>Cut if connected to:</th></tr>";
                for (var j = 0; j < WireSequenceRuleSetGenerator.NumWiresPerColour; j++)
                {
                    wiresequencetable += $"<tr><td class=\'first-col\'>{Util.OrdinalWord(j + 1)}&nbsp;{color} occurrence</td><td class=\'second-col\'>";
                    var list = new List <string>();
                    for (var k = 0; k < WireSequenceRuleSetGenerator.NUM_PER_PAGE; k++)
                    {
                        if (_ruleManager.WireSequenceRuleSet.ShouldBeSnipped(color, j, k))
                        {
                            list.Add(wireLetters[k]);
                        }
                    }
                    for (var k = 0; k < list.Count; k++)
                    {
                        wiresequencetable += list[k];
                        if (k == list.Count - 2)
                        {
                            wiresequencetable += " or ";
                        }
                        else if (k < list.Count - 2 && list.Count > 2)
                        {
                            wiresequencetable += ", ";
                        }
                    }
                    if (list.Count == 0)
                    {
                        wiresequencetable += "Never Cut";
                    }
                    wiresequencetable += "</td></tr>";
                }
                wiresequencetable += "</table>\n";
            }

            replacements.Add(new ReplaceText {
                Original = "WIRESEQUENCETABLES", Replacement = wiresequencetable
            });
            file.WriteFile(path, replacements);
        }
Ejemplo n.º 8
0
        private void WriteMemoryManual(string path, ManualFileName file, ref List <ReplaceText> replacements)
        {
            var memoryinstructions = string.Empty;

            foreach (var stage in _ruleManager.MemoryRuleSet.RulesDictionary)
            {
                memoryinstructions += $"                        <h4>Stage {stage.Key + 1}:</h4><p>";
                for (var i = 0; i < stage.Value.Count; i++)
                {
                    memoryinstructions += $"If {stage.Value[i].GetQueryString()}, {stage.Value[i].GetSolutionString()}.<br />";
                }
                memoryinstructions += "</p>\n";
            }

            replacements.Add(new ReplaceText {
                Original = "MEMORYRULES", Replacement = memoryinstructions
            });
            file.WriteFile(path, replacements);
        }
Ejemplo n.º 9
0
        private void WriteNeedyKnobManual(string path, ManualFileName file, ref List <ReplaceText> replacements)
        {
            var replacement      = string.Empty;
            var currentDirection = string.Empty;

            foreach (var rule in _ruleManager.NeedyKnobRuleSet.Rules)
            {
                var direction = rule.Solution.Text;
                if (currentDirection != direction)
                {
                    replacement     += $"                            <h4>{direction}:</h4>\n";
                    currentDirection = direction;
                }
                foreach (var query in rule.Queries)
                {
                    var leds = (bool[])query.Args[NeedyKnobRuleSet.LED_CONFIG_ARG_KEY];
                    replacement += "                            <table style=\"display: inline-table\">\n";
                    for (var i = 0; i < NeedyKnobRuleSetGenerator.LED_ROWS; i++)
                    {
                        replacement += "                                <tr>\n";
                        for (var j = 0; j < NeedyKnobRuleSetGenerator.LED_COLS; j++)
                        {
                            if (leds[NeedyKnobRuleSetGenerator.LED_COLS * i + j])
                            {
                                replacement += "                                <td>X</td>\n";
                            }
                            else
                            {
                                replacement += "                                <td>&nbsp;</td>\n";
                            }
                        }
                        replacement += "                                </tr>\n";
                    }
                    replacement += "                            </table>\n";
                }
            }


            replacements.Add(new ReplaceText {
                Original = "NEEDYKNOBLIGHTCONFIGURATION", Replacement = replacement
            });
            file.WriteFile(path, replacements);
        }
Ejemplo n.º 10
0
        private void WriteSimonSaysManual(string path, ManualFileName file, ref List <ReplaceText> replacements)
        {
            var rules = _ruleManager.SimonRuleSet.RuleList;

            foreach (var keyValuePair in rules)
            {
                var colors = new[] { "RED", "BLUE", "GREEN", "YELLOW" };
                for (var i = 0; i < keyValuePair.Value.Count; i++)
                {
                    for (var j = 0; j < 4; j++)
                    {
                        replacements.Add(new ReplaceText()
                        {
                            Original = $"{keyValuePair.Key}{i}{colors[j]}", Replacement = keyValuePair.Value[i][j].ToString()
                        });
                    }
                }
            }
            file.WriteFile(path, replacements);
        }
Ejemplo n.º 11
0
        private void WriteHTML(string path, ManualFileName file, ref List <ReplaceText> replacements)
        {
            if (string.IsNullOrEmpty(file.Name))
            {
                return;
            }
            switch (file.Name)
            {
            case "The Button.html":
                WriteButtonManual(path, file, ref replacements);
                break;

            case "Memory.html":
                WriteMemoryManual(path, file, ref replacements);
                break;

            case "Wires.html":
                WriteWiresManual(path, file, ref replacements);
                break;

            case "Wire Sequences.html":
                WriteWireSequenceManual(path, file, ref replacements);
                break;

            case "Morse Code.html":
                WriteMorseCodeManaul(path, file, ref replacements);
                break;

            case "Who’s on First.html":
                WriteWhosOnFirstManual(path, file, ref replacements);
                break;

            case "Knobs.html":
                WriteNeedyKnobManual(path, file, ref replacements);
                break;

            case "Passwords.html":
                WritePasswordManual(path, file, ref replacements);
                break;

            case "Simon Says.html":
                WriteSimonSaysManual(path, file, ref replacements);
                break;

            case "Keypads.html":
                WriteKeypadsManual(path, file, ref replacements);
                break;

            case "Mazes.html":
                WriteMazesManual(path, file, ref replacements);
                break;

            case "Complicated Wires.html":
                WriteComplicatedWiresManual(path, file, ref replacements);
                break;

            case "index.html":
                file.WriteFile(path, replacements);
                break;

            default:
                file.WriteFile(path);
                break;
            }
        }
Ejemplo n.º 12
0
        private void WriteWhosOnFirstManual(string path, ManualFileName file, ref List <ReplaceText> replacements)
        {
            var step1Precedentlist = _ruleManager.WhosOnFirstRuleSet.displayWordToButtonIndexMap;

            var replace = string.Empty;

            for (var i = 0; i < 5; i++)
            {
                replace += "                                <tr>\n";
                if (i == 4)
                {
                    replace += "                                    <td></td>\n";
                }
                for (var j = 0; j < ((i == 4) ? 4 : 6); j++)
                {
                    var word  = WhosOnFirstRuleSet.DisplayWords[(i * 6) + j];
                    var index = step1Precedentlist[word].ToString();

                    replace += "                                    <td>\n";
                    replace += "                                        <table>\n";
                    replace += "                                            <tr>\n";
                    replace += "                                                <th class=\"whos-on-first-look-at-display\" colspan=\"2\">";
                    replace += word.Trim();
                    replace += "</th>\n";
                    replace += "                                            </tr>\n";
                    for (var k = 0; k < 3; k++)
                    {
                        replace += "                                            <tr>\n";
                        for (var l = 0; l < 2; l++)
                        {
                            if (index.Trim().Equals(((k * 2) + l).ToString()))
                            {
                                replace += "<td class=\"whos-on-first-look-at\"><img src=\"img/Who’s on First/eye-icon.png\" alt=\"Look At\" style=\"height: 1em;\" /></td>";
                            }
                            else
                            {
                                replace += "                                                <td><br /></td>\n";
                            }
                        }
                        replace += "                                            </tr>\n";
                    }

                    replace += "                                        </table>\n";
                    replace += "                                    </td>\n";
                }
                replace += "                                </tr>\n";
            }
            replacements.Add(new ReplaceText {
                Original = "LOOKATDISPLAYMAP", Replacement = replace
            });
            replace = string.Empty;

            foreach (var map in _ruleManager.WhosOnFirstRuleSet.precedenceMap)
            {
                replace += "                                <tr>\n";
                replace += "                                    <th>";
                replace += map.Key;
                replace += "</th>\n";
                replace += "                                    <td>";
                replace += string.Join(", ", map.Value.ToArray());
                replace += "</td>";
                replace += "                                </tr>\n";
            }
            replacements.Add(new ReplaceText {
                Original = "PRECEDENTMAP", Replacement = replace
            });

            file.WriteFile(path, replacements);
        }
Ejemplo n.º 13
0
        private void WriteComplicatedWiresManual(string path, ManualFileName file, ref List <ReplaceText> replacements)
        {
            var lineTypes = new List <string>
            {
                "15,40,4,10",
                string.Empty,
                "3",
                "8"
            };
            var labels = new List <string>
            {
                "Wire has red\ncoloring",
                "Wire has blue\ncoloring",
                "Has ★ symbol",
                "LED is on"
            };

            var ruleset            = _ruleManager.VennWireRuleSet;
            var cutInstructionList = new List <CutInstruction>
            {
                ruleset.RuleDict[new VennWireState(true, false, false, false)],
                ruleset.RuleDict[new VennWireState(false, true, false, false)],
                ruleset.RuleDict[new VennWireState(false, false, true, false)],
                ruleset.RuleDict[new VennWireState(false, false, false, true)],
                ruleset.RuleDict[new VennWireState(true, false, true, false)],
                ruleset.RuleDict[new VennWireState(true, true, false, false)],
                ruleset.RuleDict[new VennWireState(false, true, false, true)],
                ruleset.RuleDict[new VennWireState(false, false, true, true)],
                ruleset.RuleDict[new VennWireState(false, true, true, false)],
                ruleset.RuleDict[new VennWireState(true, false, false, true)],
                ruleset.RuleDict[new VennWireState(true, true, true, false)],
                ruleset.RuleDict[new VennWireState(true, true, false, true)],
                ruleset.RuleDict[new VennWireState(false, true, true, true)],
                ruleset.RuleDict[new VennWireState(true, false, true, true)],
                ruleset.RuleDict[new VennWireState(true, true, true, true)],
                ruleset.RuleDict[new VennWireState(false, false, false, false)]
            };

            var vennList = new List <string>();

            using (var enumerator = cutInstructionList.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    // ReSharper disable once SwitchStatementMissingSomeCases
                    switch (enumerator.Current)
                    {
                    case CutInstruction.Cut:
                        vennList.Add("C");
                        break;

                    case CutInstruction.DoNotCut:
                        vennList.Add("D");
                        break;

                    case CutInstruction.CutIfSerialEven:
                        vennList.Add("S");
                        break;

                    case CutInstruction.CutIfParallelPortPresent:
                        vennList.Add("P");
                        break;

                    case CutInstruction.CutIfTwoOrMoreBatteriesPresent:
                        vennList.Add("B");
                        break;
                    }
                }
            }

            var vennSVG   = new SVGGenerator(800, 650);
            var legendSVG = new SVGGenerator(275, 200);

            vennSVG.Draw4SetVennDiagram(vennList, lineTypes);
            legendSVG.DrawVennDiagramLegend(labels, lineTypes);
            replacements.Add(new ReplaceText {
                Original = "VENNDIAGRAMSVGDATA", Replacement = vennSVG.ToString()
            });
            replacements.Add(new ReplaceText {
                Original = "VENNLEGENDSVGDATA", Replacement = legendSVG.ToString()
            });
            file.WriteFile(path, replacements);
        }
Ejemplo n.º 14
0
        private void WriteComplicatedWiresManual(string path, ManualFileName file, ref List <ReplaceText> replacements)
        {
            var strokeDashArrays = new List <float[]>
            {
                new [] { 20f, 10f, 5f, 10f },
                new float[0],
                new [] { 4f, 7f },
                new [] { 10f, 4f }
            };
            var labels = new List <string>
            {
                "Manual/venn.legendred",
                "Manual/venn.legendblue",
                "Manual/venn.legendsymbol",
                "Manual/venn.legendled"
            };
            var strokeWidths = new List <float>
            {
                5f,
                6f,
                4f,
                10f
            };

            var ruleset            = _ruleManager.VennWireRuleSet;
            var cutInstructionList = new List <CutInstruction>
            {
                ruleset.RuleDict[new VennWireState(true, false, false, false)],
                ruleset.RuleDict[new VennWireState(false, true, false, false)],
                ruleset.RuleDict[new VennWireState(false, false, true, false)],
                ruleset.RuleDict[new VennWireState(false, false, false, true)],
                ruleset.RuleDict[new VennWireState(true, false, true, false)],
                ruleset.RuleDict[new VennWireState(true, true, false, false)],
                ruleset.RuleDict[new VennWireState(false, true, false, true)],
                ruleset.RuleDict[new VennWireState(false, false, true, true)],
                ruleset.RuleDict[new VennWireState(false, true, true, false)],
                ruleset.RuleDict[new VennWireState(true, false, false, true)],
                ruleset.RuleDict[new VennWireState(true, true, true, false)],
                ruleset.RuleDict[new VennWireState(true, true, false, true)],
                ruleset.RuleDict[new VennWireState(false, true, true, true)],
                ruleset.RuleDict[new VennWireState(true, false, true, true)],
                ruleset.RuleDict[new VennWireState(true, true, true, true)],
                ruleset.RuleDict[new VennWireState(false, false, false, false)]
            };

            var vennList = new List <string>();

            using (var enumerator = cutInstructionList.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    // ReSharper disable once SwitchStatementMissingSomeCases
                    switch (enumerator.Current)
                    {
                    case CutInstruction.Cut:
                        vennList.Add("Manual/venn.symbolcut");
                        break;

                    case CutInstruction.DoNotCut:
                        vennList.Add("Manual/venn.symboldonotcut");
                        break;

                    case CutInstruction.CutIfSerialEven:
                        vennList.Add("Manual/venn.symbolserial");
                        break;

                    case CutInstruction.CutIfParallelPortPresent:
                        vennList.Add("Manual/venn.symbolparallel");
                        break;

                    case CutInstruction.CutIfTwoOrMoreBatteriesPresent:
                        vennList.Add("Manual/venn.symbolbattery");
                        break;
                    }
                }
            }

            var vennSVG   = new SVGGenerator(800, 650);
            var legendSVG = new SVGGenerator(275, 200);

            vennSVG.Draw4SetVennDiagram(vennList, strokeDashArrays, strokeWidths);
            legendSVG.DrawVennDiagramLegend(labels, strokeDashArrays, strokeWidths);
            replacements.Add(new ReplaceText {
                Original = "VENNDIAGRAMSVGDATA", Replacement = vennSVG.ToString()
            });
            replacements.Add(new ReplaceText {
                Original = "VENNLEGENDSVGDATA", Replacement = legendSVG.ToString()
            });
            file.WriteFile(path, replacements);
        }