//Generates a new premise as a result of the Addition rule. public Premise AddR(Premise a) { Console.Write("New Addition:"); var inString = Console.ReadLine(); var newAddition = problemConstructor.MakeCustom(inString); if (newAddition == null) { return(null); } else { var newPremise = new Premise(4, a, newAddition); return(newPremise); } }
public ProblemSet(int problemSet, string userID) { show = new Show(userID); WorkingWithConditionals: while (stillRunning) { var solved = saveCloud.GetSolved(problemSet, userID, saveCloud.GetArgumentListLength(problemSet)); Console.WriteLine("Choose an argument to derive:"); Loop1: var argumentDisplay = saveCloud.GetArgumentDisplay(problemSet); var upTo = argumentDisplay.Length - 1; for (var i = 0; i <= upTo; i++) { if (problemSet == 2 && i == 1) { Console.WriteLine("Material Conditional 1: Solve the following derivation to unlock the MC1 rule."); } if (problemSet == 2 && i == 17) { Console.WriteLine("Material Conditional 2: Solve the following derivation to unlock the MC2 rule."); } if (solved[i] == true) { Console.WriteLine(i + ": " + argumentDisplay[i] + " (Solved)"); } else { Console.WriteLine(i + ": " + argumentDisplay[i]); } } Console.Write("Choice:"); var choice = Console.ReadLine(); var choiceInt = 0; try { choiceInt = Convert.ToInt32(choice); } catch (Exception) { switch (choice) { case "help": writer.ReadWholeFile("textFiles/helpShow.txt"); goto Loop1; case "exit": stillRunning = false; goto Done; //For constructing levels during development case "make-argument": Console.WriteLine("Into which problem Set?"); Console.Write("Choice:"); saveCloud.InsertArgument(Convert.ToInt32(Console.ReadLine())); goto WorkingWithConditionals; default: Console.WriteLine("That is not a valid choice. Try again."); //Console.WriteLine(e); //testing goto Loop1; } } problemConstructor = new ProblemConstructor(problemSet, choiceInt); currentArgument = problemConstructor.argument; Console.WriteLine("Type 'help' at any time to read about commands."); Console.WriteLine("Type 'redo' to restart the derivation at any time."); Console.WriteLine("Type 'exit' at any time to exit."); Console.WriteLine(currentArgument.GetArgument()); Console.Write("Command: "); string[] tokens = Console.ReadLine().Split(' '); var command = tokens[0]; switch (command) { case "help": writer.ReadWholeFile("textFiles/helpShow.txt"); break; case "exit": break; case "Show": Show: if (!show.CheckTokenLength(tokens, 2)) { Console.WriteLine("Show statement must be followed by one command."); break; } switch (tokens[1]) { case "C": case "c": Redo: if (show.ShowPremise(currentArgument, currentArgument.conclusion, mainInventory)) { Console.WriteLine("Solved!"); solved[Convert.ToInt32(choice)] = true; saveCloud.MakeSolvedTrue(problemSet, userID, Convert.ToInt32(choice)); show.CheckRuleLocks(); mainInventory.Clear(); break; } else if (show.GetRedo()) { goto Redo; } else { stillRunning = false; break; } default: Premise custom = problemConstructor.MakeCustom(tokens[1]); if (custom == null) { Console.WriteLine("Bad Premise. Try again."); break; } if (show.ShowPremise(currentArgument, custom, mainInventory)) { if (custom._Equals(currentArgument.conclusion)) { Console.WriteLine("Solved!"); solved[Convert.ToInt32(choice)] = true; saveCloud.MakeSolvedTrue(problemSet, userID, Convert.ToInt32(choice)); show.CheckRuleLocks(); mainInventory.Clear(); break; } else { mainInventory.Add(custom); Console.WriteLine(custom.GetPremise() + " " + currentArgument.conclusion.GetPremise()); break; } } break; } break; default: if (command.Equals("show", StringComparison.CurrentCultureIgnoreCase)) { goto Show; } Console.WriteLine("Unrecognized input. type 'help' for more information."); break; } } Done :; }
public Tutorial(int part, string userID) { switch (part) { case 1: var DDSHow = new Show(userID); writer.AddTenBlankLines(); writer.Read(0, 18, "textFiles/tutorial.txt"); var problem = new ProblemConstructor(1, 0); var argument1 = problem.argument; Console.WriteLine("*Note that PR1, PR2, etc. indicate available premises."); Console.WriteLine(argument1.GetArgument()); Loop1: Console.Write("Command:"); var tokens1 = Console.ReadLine().Split(' '); if (tokens1.Length != 2 || (tokens1[0] != "Show" && (tokens1[1] != "P" || tokens1[1] != "C"))) { if (tokens1[0] == "exit") { break; } else { Console.WriteLine("Invalid input, please follow the tutorial or type 'exit'"); goto Loop1; } } else { writer.Read(21, 42, "textFiles/tutorial.txt"); Loop2: Console.Write("Command:"); var tokens2 = Console.ReadLine().Split(' '); if (tokens2.Length != 3 || (tokens2[0] != "MP" && (tokens2[1] != "PR1" || tokens2[1] != "PR2"))) { if (tokens2[0] == "exit") { break; } else { Console.WriteLine("Invalid input, please follow the tutorial or type 'exit'"); goto Loop2; } } else { writer.Read(43, 55, "textFiles/tutorial.txt"); Loop3: Console.Write("Command:"); var tokens3 = Console.ReadLine().Split(' '); if (tokens3.Length != 2 || (tokens3[0] != "DD" && (tokens3[1] != "0"))) { if (tokens3[0] == "exit") { break; } else { Console.WriteLine("Invalid input, please follow the tutorial or type 'exit'"); goto Loop3; } } else { Console.WriteLine("Solved!"); writer.Read(57, 66, "textFiles/tutorial.txt"); } } } break; //End of Tutorial 1 case 2: Tut2Loop1: writer.AddTenBlankLines(); writer.Read(67, 76, "textFiles/tutorial.txt"); var problem2 = new ProblemConstructor(1, 7); Console.WriteLine(problem2.argument.GetArgument()); Console.Write("Command:"); var tokens4 = Console.ReadLine().Split(' '); if (tokens4.Length != 2 || (tokens4[0] != "Show" && (tokens4[1] != "~R" || tokens4[1] != "C"))) { if (tokens4[0] == "exit") { break; } else { Console.WriteLine("Invalid input, please follow the tutorial or type 'exit'"); goto Tut2Loop1; } } else { Tut2Loop2: writer.Read(76, 94, "textFiles/tutorial.txt"); Console.WriteLine(problem2.argument.GetArgument()); Console.WriteLine("Show ~R"); Console.Write("Command:"); var tokens5 = Console.ReadLine().Split(' '); if (tokens5.Length != 2 || tokens5[0] != "ASS" || tokens5[1] != "ID") { if (tokens5[0] == "exit") { break; } else { Console.WriteLine("Invalid input, please follow the tutorial or type 'exit'"); goto Tut2Loop2; } } else { writer.Read(94, 102, "textFiles/tutorial.txt"); var IDShow = new Show(userID); IDShow.SetAssumeCounter(1); var IDInv = new List <Premise>(); IDInv.Add(problem2.MakeCustom("R")); if (IDShow.ShowPremise(problem2.argument, problem2.argument.conclusion, IDInv)) { writer.Read(104, 111, "textFiles/tutorial.txt"); break; } else { break; } } } //End of Tutorial 2 case 3: Tut3Loop1: var problem3 = new ProblemConstructor(1, 1); writer.AddTenBlankLines(); writer.Read(112, 133, "textFiles/tutorial.txt"); Console.WriteLine(problem3.argument.GetArgument()); Console.Write("Command:"); var tokens6 = Console.ReadLine().Split(' '); if (tokens6.Length != 2 || (tokens6[0] != "Show" && (tokens6[1] != "P->Q" || tokens6[1] != "C"))) { if (tokens6[0] == "exit") { break; } else { Console.WriteLine("Invalid input, please follow the tutorial or type 'exit'"); goto Tut3Loop1; } } else { Tut3Loop2: writer.AddTenBlankLines(); writer.Read(134, 136, "textFiles/tutorial.txt"); Console.WriteLine(problem3.argument.GetArgument()); Console.WriteLine("Show P->Q"); Console.Write("Command:"); var tokens5 = Console.ReadLine().Split(' '); if (tokens5.Length != 2 || tokens5[0] != "ASS" || tokens5[1] != "CD") { if (tokens5[0] == "exit") { break; } else { Console.WriteLine("Invalid input, please follow the tutorial or type 'exit'"); goto Tut3Loop2; } } else { writer.AddTenBlankLines(); writer.Read(137, 141, "textFiles/tutorial.txt"); var IDShow = new Show(userID); IDShow.SetAssumeCounter(1); var IDInv = new List <Premise>(); IDInv.Add(problem3.MakeCustom("P")); if (IDShow.ShowPremise(problem3.argument, problem3.argument.conclusion, IDInv)) { writer.Read(141, 166, "textFiles/tutorial.txt"); var problem3_2 = new ProblemConstructor(1, 13); IDInv.Clear(); IDShow.ClearInventory(); IDInv.Add(problem3_2.MakeCustom("P")); if (IDShow.ShowPremise(problem3_2.argument, problem3_2.argument.conclusion, IDInv)) { writer.Read(166, 180, "textFiles/tutorial.txt"); break; } else { break; } } else { break; } } } //End of Tutorial 3 } }
//Main loop for derivation of the argument's conclusion. public bool ShowPremise(Argument argument, Premise toShow, List <Premise> mainInv) { redo = false; for (var j = 0; j < mainInv.Count; j++) { inventory.Add(mainInv[j]); } for (var i = 0; i < argument.premises.Count; i++) { argumentPremises.Add(argument.premises[i]); } MainShow: Console.WriteLine(argument.GetArgument()); this.ListSheet(toShow); var notSolved = true; string command; while (notSolved) { Console.Write("Command: "); string[] tokens = Console.ReadLine().Split(' '); command = tokens[0]; switch (command) { case "help": writer.ReadWholeFile("textFiles/helpShow.txt"); goto MainShow; case "exit": inventory.Clear(); assumeCounter = 0; return(false); case "redo": inventory.Clear(); assumeCounter = 0; redo = true; return(false); //Modus Ponens case "MP": case "mp": var inMP = new Premise[tokens.Length - 1]; if (!this.CheckTokenLength(tokens, 3)) { break; } inMP = this.SetInputPremises(tokens, argument); if (inMP == null) { break; } if (!rules.MPCheck(inMP[0], inMP[1])) { Console.WriteLine("Cannot perform this rule on these premises"); break; } var resultPremise = rules.ModusPonens(inMP[0], inMP[1]); if (resultPremise == null) { break; } inventory.Add(resultPremise); Console.WriteLine(argument.GetArgument()); this.ListSheet(toShow); break; //Modus Tolens case "MT": case "mt": var inMT = new Premise[tokens.Length - 1]; if (!this.CheckTokenLength(tokens, 3)) { break; } inMT = this.SetInputPremises(tokens, argument); if (inMT == null) { break; } if (!rules.MTCheck(inMT[0], inMT[1])) { Console.WriteLine("Cannot perform this rule on these premises"); break; } var MTresultPremise = rules.ModusTolens(inMT[0], inMT[1]); if (MTresultPremise == null) { break; } inventory.Add(MTresultPremise); Console.WriteLine(argument.GetArgument()); this.ListSheet(toShow); break; //Double Negation generic case "DN": case "dn": var inDN = new Premise[tokens.Length - 1]; if (!this.CheckTokenLength(tokens, 2)) { break; } inDN = this.SetInputPremises(tokens, argument); if (inDN == null) { break; } if (rules.DNECheck(inDN[0])) { inventory.Add(rules.DNE(inDN[0])); Console.WriteLine(argument.GetArgument()); this.ListSheet(toShow); break; } else { inventory.Add(rules.DNI(inDN[0])); Console.WriteLine(argument.GetArgument()); this.ListSheet(toShow); break; } //DNE specific case "DNE": case "dne": var inDNE = new Premise[tokens.Length - 1]; if (!this.CheckTokenLength(tokens, 2)) { break; } inDNE = this.SetInputPremises(tokens, argument); if (inDNE == null) { break; } if (rules.DNECheck(inDNE[0])) { inventory.Add(rules.DNE(inDNE[0])); Console.WriteLine(argument.GetArgument()); this.ListSheet(toShow); break; } else { Console.WriteLine("DNE cannot be performed on that premise. Type 'help' for rule info."); break; } //DNI specific case "DNI": case "dni": var inDNI = new Premise[tokens.Length - 1]; if (!this.CheckTokenLength(tokens, 2)) { break; } inDNI = this.SetInputPremises(tokens, argument); if (inDNI == null) { break; } inventory.Add(rules.DNI(inDNI[0])); Console.WriteLine(argument.GetArgument()); this.ListSheet(toShow); break; case "SR": case "sr": var inSR = new Premise[tokens.Length - 1]; if (!this.CheckTokenLength(tokens, 2)) { break; } inSR = this.SetInputPremises(tokens, argument); if (inSR == null) { break; } inventory.Add(inSR[0].child2); Console.WriteLine(argument.GetArgument()); this.ListSheet(toShow); break; case "SL": case "sl": var inSL = new Premise[tokens.Length - 1]; if (!this.CheckTokenLength(tokens, 2)) { break; } inSL = this.SetInputPremises(tokens, argument); if (inSL == null) { break; } inventory.Add(inSL[0].child1); Console.WriteLine(argument.GetArgument()); this.ListSheet(toShow); break; case "S": case "s": var inS = new Premise[tokens.Length - 1]; if (!this.CheckTokenLength(tokens, 2)) { break; } inS = this.SetInputPremises(tokens, argument); if (inS == null) { break; } inventory.Add(inS[0].child2); inventory.Add(inS[0].child1); Console.WriteLine(argument.GetArgument()); this.ListSheet(toShow); break; case "AddR": case "addr": AddR: var inAddR = new Premise[tokens.Length - 1]; if (!this.CheckTokenLength(tokens, 2)) { break; } inAddR = this.SetInputPremises(tokens, argument); if (inAddR == null) { break; } var AddRPremise = rules.AddR(inAddR[0]); if (AddRPremise == null) { Console.WriteLine("That is not a valid addition."); break; } else { inventory.Add(AddRPremise); Console.WriteLine(argument.GetArgument()); this.ListSheet(toShow); break; } case "AddL": case "addl": var inAddL = new Premise[tokens.Length - 1]; if (!this.CheckTokenLength(tokens, 2)) { break; } inAddL = this.SetInputPremises(tokens, argument); if (inAddL == null) { break; } var AddLPremise = rules.AddL(inAddL[0]); if (AddLPremise == null) { Console.WriteLine("That is not a valid addition."); break; } else { inventory.Add(AddLPremise); Console.WriteLine(argument.GetArgument()); this.ListSheet(toShow); break; } case "Add": case "add": goto AddR; case "Adj": case "adj": var inAdj = new Premise[tokens.Length - 1]; if (!this.CheckTokenLength(tokens, 3)) { break; } inAdj = this.SetInputPremises(tokens, argument); if (inAdj == null) { break; } inventory.Add(rules.Adj(inAdj[0], inAdj[1])); Console.WriteLine(argument.GetArgument()); this.ListSheet(toShow); break; case "MTP": case "mtp": var inMTP = new Premise[tokens.Length - 1]; if (!this.CheckTokenLength(tokens, 3)) { break; } inMTP = this.SetInputPremises(tokens, argument); if (inMTP == null) { break; } var MTPPremise = rules.MTP(inMTP[0], inMTP[1]); if (MTPPremise == null) { Console.WriteLine("Cannot perform this rule on these premises."); break; } else { inventory.Add(MTPPremise); Console.WriteLine(argument.GetArgument()); this.ListSheet(toShow); break; } case "BCL": case "bcl": var inBCL = new Premise[tokens.Length - 1]; if (!this.CheckTokenLength(tokens, 2)) { break; } inBCL = this.SetInputPremises(tokens, argument); if (inBCL == null) { break; } var BCLPremise = rules.BCL(inBCL[0]); if (BCLPremise == null) { Console.WriteLine("This rule cannot be performed on that premise."); break; } else { inventory.Add(BCLPremise); Console.WriteLine(argument.GetArgument()); this.ListSheet(toShow); break; } case "BCR": case "bcr": var inBCR = new Premise[tokens.Length - 1]; if (!this.CheckTokenLength(tokens, 2)) { break; } inBCR = this.SetInputPremises(tokens, argument); if (inBCR == null) { break; } var BCRPremise = rules.BCR(inBCR[0]); if (BCRPremise == null) { Console.WriteLine("This rule cannot be performed on that premise."); break; } else { inventory.Add(BCRPremise); Console.WriteLine(argument.GetArgument()); this.ListSheet(toShow); break; } case "BC": case "bc": var inBC = new Premise[tokens.Length - 1]; if (!this.CheckTokenLength(tokens, 2)) { break; } inBC = this.SetInputPremises(tokens, argument); if (inBC == null) { break; } var BCPremise1 = rules.BCL(inBC[0]); var BCPremise2 = rules.BCR(inBC[0]); if (BCPremise1 == null || BCPremise2 == null) { Console.WriteLine("This rule cannot be performed on that premise."); break; } else { inventory.Add(BCPremise1); inventory.Add(BCPremise2); Console.WriteLine(argument.GetArgument()); this.ListSheet(toShow); break; } case "CB": case "cb": var inCB = new Premise[tokens.Length - 1]; if (!this.CheckTokenLength(tokens, 3)) { break; } inCB = this.SetInputPremises(tokens, argument); if (inCB == null) { break; } var CBPremise = rules.CB(inCB[0], inCB[1]); if (CBPremise == null) { Console.WriteLine("This rule cannot be performed on that premise."); break; } else { inventory.Add(CBPremise); Console.WriteLine(argument.GetArgument()); this.ListSheet(toShow); break; } case "MC1": case "mc1": MC1: if (!MC1Unlocked) { Console.WriteLine("Solve derivation 1 of problem set 2 to unlock this rule."); break; } if (!this.CheckTokenLength(tokens, 2)) { break; } var inMC1 = this.SetInputPremises(tokens, argument); if (inMC1 == null) { break; } Console.Write("New Anticedent:"); var MC1String = Console.ReadLine(); inventory.Add(rules.MC1(inMC1[0], MC1String)); Console.WriteLine(argument.GetArgument()); this.ListSheet(toShow); break; case "MC2": case "mc2": MC2: if (!MC2Unlocked) { Console.WriteLine("Solve derivation 17 of problem set 2 to unlock this rule."); break; } if (!this.CheckTokenLength(tokens, 2)) { break; } var inMC2 = this.SetInputPremises(tokens, argument); if (inMC2 == null) { break; } Console.Write("New Consequent:"); var MC2String = Console.ReadLine(); inventory.Add(rules.MC2(inMC2[0], MC2String)); Console.WriteLine(argument.GetArgument()); this.ListSheet(toShow); break; case "MC": case "mc": if (!this.CheckTokenLength(tokens, 2)) { break; } var inMC = this.SetInputPremises(tokens, argument); if (inMC == null) { break; } if (inMC[0].type == 5) { goto MC2; } else { goto MC1; } case "Show": Show: if (!this.CheckTokenLength(tokens, 2)) { break; } var problemConstructor = new ProblemConstructor(); var newPremise = problemConstructor.MakeCustom(tokens[1]); if (newPremise == null) { Console.WriteLine("Invalid premise"); break; } var newShow = new Show(userID); if (newShow.ShowPremise(argument, newPremise, inventory)) { inventory.Add(newPremise); Console.WriteLine(argument.GetArgument()); this.ListSheet(toShow); break; } else if (newShow.GetRedo()) { inventory.Clear(); assumeCounter = 0; redo = true; return(false); } break; //Assume CD or ID case "ASS": case "ass": if (!this.CheckTokenLength(tokens, 2)) { break; } if (assumeCounter > 0) { Console.WriteLine("Only 1 assume statement can be made per Show statement."); break; } if (tokens[1].Equals("ID", StringComparison.CurrentCultureIgnoreCase)) { inventory.Add(new Premise(toShow)); Console.WriteLine(argument.GetArgument()); this.ListSheet(toShow); assumeCounter++; break; } else if (tokens[1].Equals("CD", StringComparison.CurrentCultureIgnoreCase)) { if (toShow.type == 1) { inventory.Add(toShow.anti); Console.WriteLine(argument.GetArgument()); this.ListSheet(toShow); assumeCounter++; break; } else { Console.WriteLine("Argument's conlusion must be conditional in order to perform a conditional derivation"); break; } } else { Console.WriteLine("ASS must be followed by CD or ID only."); break; } //closing the ID case "ID": case "id": //decides whether input is from lines or argument var inID = new Premise[tokens.Length - 1]; if (!this.CheckTokenLength(tokens, 3)) { break; } inID = this.SetInputPremises(tokens, argument); if (inID == null) { break; } if (rules.IDCheck(inID[0], inID[1])) { assumeCounter--; inventory.Clear(); return(true); } else { Console.WriteLine("Nope! Try again."); break; } //direct derivation case "DD": case "dd": if (!this.CheckTokenLength(tokens, 2)) { break; } try { var temp = Convert.ToInt32(tokens[1]); if (inventory[temp]._Equals(toShow)) { inventory.Clear(); return(true); } else { Console.WriteLine("Nope! Try again."); break; } } catch (Exception) { Console.WriteLine("Error: Premise must be a reference to a line"); break; } case "CD": case "cd": if (!this.CheckTokenLength(tokens, 2)) { break; } try { var temp = Convert.ToInt32(tokens[1]); if (inventory[temp]._Equals(toShow.cons)) { assumeCounter--; inventory.Clear(); return(true); } else { Console.WriteLine("Nope! Try again."); break; } } catch (Exception) { if (tokens[1].Contains("PR")) { try { if (argument.premises[Convert.ToInt32(tokens[1].Substring(2)) - 1]._Equals(toShow.cons)) { return(true); } } catch (Exception e) { Console.WriteLine("That is not a premise."); Console.WriteLine(e); break; } } Console.WriteLine("Error: Premise must be a reference to a line"); break; } default: if (command.Equals("show", StringComparison.CurrentCultureIgnoreCase)) { goto Show; } Console.WriteLine("bad input: enter 'help' for more information."); break; } } return(true); }