//--------------------------------------------------------------------------------------------------------------------------------------------------- // // Copyright (C)2007 DarkWynter Studios. All rights reserved. // //--------------------------------------------------------------------------------------------------------------------------------------------------- // {Contact : darkwynter.com for licensing information //--------------------------------------------------------------------------------------------------------------------------------------------------- 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 third challenge the player must complete /// Located in level 3 - Hippocampus /// Recursive Depth First Traversal /// public class Challenge2 : ChallengeAbstract { string stringCheck1 = "node.returnLeft()"; string stringCheck2 = "depthFirstSearch(node.returnLeft());"; string stringCheck3 = "node.returnRight() != null"; string stringCheck4 = "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 /// /// XML Node public Challenge2(XmlNode problemNode) : base(problemNode) { this.id = 0; foreach (XmlNode instrNode in problemNode) { challengeDialogue.Add(instrNode.Attributes["text"].Value); } } /// /// Scaffolding for the challenge /// /// challengeSource public override string GetScaffolding() { challengeSource = @"using System; using DarkWynter.Engine.Compiler; class Test { public void TreeTraversal() { Tree myTree = new Tree(); depthFirstSearch(myTree.root); } public void depthFirstSearch(Node node) { Thought.moveTo(node); //BASE CASE if ((node.returnRight() == null) && (node.returnLeft() == null)) { return; } //RECURSIVE CALLS //Using the provided instructions and your knowledge from the previous //challenge, complete both recursive calls. else { if ([INSERT_YOUR_CODE]) { depthFirstSearch(node.returnRight()); [INSERT_YOUR_CODE] } //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] Thought.moveTo(node); } } return; } } "; 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; } //return true; // Clean up the output first because forms are dumb shits studentOutput = studentOutput.Replace('\r', ' '); studentOutput = studentOutput.Replace('\n', ' '); studentOutput = studentOutput.Trim(); // Check Input if (studentCode.Contains(stringCheck1)) { if(studentCode.Contains(stringCheck2)) { if (studentCode.Contains(stringCheck3)) { if (studentCode.Contains(stringCheck4)) { // 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(); return true; 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 correctly complete the second call. [End Error Message]"); App.CompilerControl.customErrorMessage = "Make sure you're calling depthFirstSearch twice. You need to call it within each if-statement for the right-child and the left-child respectively."; 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 correctly set up the if-statement for the first call. [End Error Message]"); App.CompilerControl.customErrorMessage = "Make sure you've set up the if-statement for the first recursive call correctly. You need to check if a right-child exists for the current node."; Statics_Engine.GameSettings.triesNumber++; Thought.secretCode = ""; return false; } else Logging.G2LLogList.Add(DateTime.Now.ToString() + " - [Error Message] Student did not include an aspect of the second recursive call [End Error Message]"); App.CompilerControl.customErrorMessage = "Make sure you are correctly calling depthFirstSearch two times. You need to call depthFirstSearch within each if-statement for left and right children respectively."; Statics_Engine.GameSettings.triesNumber++; Thought.secretCode = ""; return false; } else Logging.G2LLogList.Add(DateTime.Now.ToString() + " - [Error Message] Student did not include an aspect of the second recursive call [End Error Message]"); App.CompilerControl.customErrorMessage = "Make sure that you have correctly completed the if-statements for both calls. The second if-statement should check if a left-child exists for the current node."; Statics_Engine.GameSettings.triesNumber++; Thought.secretCode = ""; return false; } /// /// Run the set visualization /// /// bool public override bool RunVizualization() { Statics_Engine.GameSettings.isProblemFinished = true; GameEventHandler.CurrentGameConditions.lastNodeVisited = 1; GameEventHandler.CurrentGameConditions.triggerSanity = -1; // DEBUG HACK : Increment AIEvent Index GameEventHandler.CurrentGameConditions._trigger_ID = 0; return true; } } }