//--------------------------------------------------------------------------------------------------------------------------------------------------- // Challenge0 class, inherits from ChallengeAbstract // Inits with an XML node to add the dialogue for the level, returns scaffolding code to main code display in CompilerControl, // Validates the student code to be in acceptable format (parses), and runs the vis for the level. //--------------------------------------------------------------------------------------------------------------------------------------------------- // Engineered by: Amanda Chaffin //--------------------------------------------------------------------------------------------------------------------------------------------------- namespace DarkWynter.App.ChallengeSet { #region Using Statements using System; using System.Collections.Generic; using System.Text; using System.ComponentModel; using System.Data; using System.Drawing; using System.Windows.Forms; using System.Xml; using DarkWynter.Engine.Globals; using DarkWynter.Engine.Utilities; using Microsoft.Xna.Framework; using DarkWynter.Engine.GameObjects; using DarkWynter.Engine.EventControl; using DarkWynter.Engine.Compiler; #endregion /// /// The first challenge the player must completee /// Located in level 0 - Cortex /// Non-Recursive Depth First Traversal /// public class Challenge0 : ChallengeAbstract { string stringCheck1 = "node.returnLeft()"; string stringCheck2 = "depthFirstSearch(node.returnLeft());"; string outCheck = "1 2 3 4 3 5 3 2 6 7 6 8 6 2 1 9 10 11 10 12 10 9 13 14 13 15 13 9 1 "; string secretCheck = "1234353267686219ABACA9DEDFD91"; /// /// Constructor for the second challenge, calls base (challengeAbstract) /// /// XML Node public Challenge0(XmlNode problemNode) : base(problemNode) { this.id = 0; foreach (XmlNode instrNode in problemNode) { challengeDialogue.Add(instrNode.Attributes["text"].Value); } } /// /// Scaffolding code for the challenge /// /// The String holding the scaffolding code (challengeSource) public override string GetScaffolding() { #region Challenge 0 Scaffolding code challengeSource = @"using System; using DarkWynter.Engine.Compiler; class Test { public void TreeTraversal() { Tree myTree = new Tree(); depthFirstSearch(myTree.root); } // Causes the AI to traverse the tree in Depth First Mode public void depthFirstSearch(Node node) { Thought.moveTo(node); // Check for Base Case (or leaf node) if ((node.returnRight() == null) && (node.returnLeft() == null)) { return; } // Recurisve calls to be made if base case is not reached else { //Recursive call to travel to the right child of a node. if (node.returnRight() != null) { depthFirstSearch(node.returnRight()); Thought.moveTo(node); } // Use the above if statment to complete the one below // This if statement should let you travel to a node's left child if ([INSERT_YOUR_CODE] != null) { [INSERT_YOUR_CODE] } } return; } }"; #endregion return challengeSource; } /// /// Parses the student code for validity /// /// Student's Code /// Output from the compiler /// bool public override bool ValidateStudentCode(string studentCode, string studentOutput) { // If base fails, return if (!base.ValidateStudentCode(studentCode, studentOutput)) { return false; } // Clean up the output first because forms add chars studentOutput = studentOutput.Replace('\r', ' '); studentOutput = studentOutput.Replace('\n', ' '); studentOutput = studentOutput.Trim(); #region Code parsing // Check Input if (studentCode.Contains(stringCheck1) && studentCode.Contains(stringCheck2)) { // Check Output if (Thought.secretCode.Equals(secretCheck)) { Statics_Engine.GameSettings.triesNumber++; Logging.G2LLogList.Add(DateTime.Now.ToString() + " - [Success Message] Student input and output correct [End Success Message]"); App.CompilerControl.customErrorMessage = null; base.setExpPoints(); if ((studentOutput.Equals(outCheck))) { Statics_Engine.GameSettings.triesNumber++; Logging.G2LLogList.Add(DateTime.Now.ToString() + " - [Success Message] Student input and output correct [End Success Message]"); App.CompilerControl.customErrorMessage = null; base.setExpPoints(); return true; } else Logging.G2LLogList.Add(DateTime.Now.ToString() + " - [Error Message] Student did not have correct output. [End Error Message]"); App.CompilerControl.customErrorMessage = "Check your traversal and try again."; Statics_Engine.GameSettings.triesNumber++; Thought.secretCode = ""; return false; } else Logging.G2LLogList.Add(DateTime.Now.ToString() + " - [Error Message] Student did not actually complete challenge. [End Error Message]"); App.CompilerControl.customErrorMessage = "Make sure you're following the instructions and try again."; Statics_Engine.GameSettings.triesNumber++; Thought.secretCode = ""; return false; } else Logging.G2LLogList.Add(DateTime.Now.ToString() + " - [Error Message] Student did not use a string for the name [End Error Message]"); App.CompilerControl.customErrorMessage = "Look at the other if statement, complete the second statement the same way, but for the left child!"; Statics_Engine.GameSettings.triesNumber++; Thought.secretCode = ""; return false; #endregion } /// /// Run the set visualization /// /// bool public override bool RunVizualization() { // Go Fullscreen so they don't miss the viz... DarkWynter.Shell.UCAD.UCAD_Left_SplitContainer.Panel1Collapsed = true; DarkWynter.Shell.UCAD.UCAD_Right_SplitContainer.Panel2Collapsed = true; DarkWynter.Shell.UCAD.UCAD_Bottom_SplitContainer.Panel2Collapsed = true; Statics_Engine.GameSettings.isProblemFinished = true; // Increment AIEvent Index GameEventHandler.CurrentGameConditions._trigger_ID = 0; GameEventHandler.CurrentGameConditions.triggerSanity = -1; GameEventHandler.CurrentGameConditions._lastNodeVisited = 1; return true; } } }