Skip to content

Commit

Permalink
improvements on defusing wires
Browse files Browse the repository at this point in the history
going back on a wire is now possible
  • Loading branch information
GeorgeMC2610 committed Jul 31, 2022
1 parent 1dc7646 commit 4a7283f
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 22 deletions.
29 changes: 18 additions & 11 deletions Bomb/Wires.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ namespace KTANE_Bot
public class Wires : KTANE_Module
{
private List<string> _wires;
private static readonly Dictionary<int, string> indexingDict = new Dictionary<int, string>
{
{ 1, "first" },
{ 2, "second" },
{ 3, "third" },
{ 4, "fourth" },
{ 5, "fifth" },
{ 6, "sixth"}
};

public int WireCount => _wires.Count;

Expand All @@ -19,12 +28,20 @@ public void AppendWire(string color)
_wires.Add(color);
}

public string DeletePreviousWire()
{
var deletedWire = _wires[_wires.Count - 1];
_wires.RemoveAt(_wires.Count - 1);

return $@"The {indexingDict[WireCount + 1]} wire is no longer {deletedWire}.";
}

public override string Solve()
{
if (_wires.Count > 6)
return $"Too many wires given. ({_wires.Count})";
if (_wires.Count < 3)
return $"You must give at least 3 wires. ({_wires.Count})";
return $"You must give at least 3 wires. ({_wires.Count} given)";

var redWires = (from wire in _wires where wire == "red" select wire).Count();
var whiteWires = (from wire in _wires where wire == "white" select wire).Count();
Expand Down Expand Up @@ -96,16 +113,6 @@ private string IndexToWords(int index)
if (index == _wires.Count)
return "last";

var indexingDict = new Dictionary<int, string>
{
{ 1, "first" },
{ 2, "second" },
{ 3, "third" },
{ 4, "fourth" },
{ 5, "fifth" },
{ 6, "sixth"}
};

return indexingDict[index];
}
}
Expand Down
2 changes: 1 addition & 1 deletion Grammar/DefuseGrammar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private static Grammar _MemoryGrammar()

private static Grammar _WiresGrammar()
{
return new Grammar(new GrammarBuilder(new Choices(new string[] {"yellow", "blue", "black", "white", "red", "done"}))) {Name = "Wires Grammar"};
return new Grammar(new GrammarBuilder(new Choices(new string[] {"yellow", "blue", "black", "white", "red", "done", "wrong"}))) {Name = "Wires Grammar"};
}

private static Grammar _KnobGrammar()
Expand Down
17 changes: 7 additions & 10 deletions Grammar/KTANE_Speech.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,16 +235,8 @@ public string AnalyzeSpeech(string command)
//WIRES SOLVER.
case Solvers.Wires:
if (_defusingModule == null)
{
if (command == "done") return "You must give a color";

var defusingModule = new Wires(_bomb);
defusingModule.AppendWire(command);
_defusingModule = defusingModule;

return $"{command}; next.";
}

_defusingModule = new Wires(_bomb);

var wires = (Wires)_defusingModule;

if (command == "done")
Expand All @@ -253,6 +245,11 @@ public string AnalyzeSpeech(string command)
return "Done; " + wires.Solve();
}

if (command == "wrong")
{
return wires.WireCount < 1 ? "To delete a wire, you must first give one." : wires.DeletePreviousWire();
}

wires.AppendWire(command);

if (wires.WireCount != 6) return $"{command}; next.";
Expand Down
Binary file modified bin/Debug/KTANE-Bot.exe
Binary file not shown.
Binary file modified bin/Debug/KTANE-Bot.pdb
Binary file not shown.
Binary file modified obj/Debug/KTANE-Bot.exe
Binary file not shown.
Binary file modified obj/Debug/KTANE-Bot.pdb
Binary file not shown.

0 comments on commit 4a7283f

Please sign in to comment.