// place the currently held value in the specified Card IEnumerator MOVE_TO() { // grab card reference CurrentArg = current.Arg; CardLogic card = cardContainer.GetCard((int)CurrentArg); HideDataCube(); // trying to store null causes a runtime error if (CurrentValue == null) { error = true; currentState = ACTOR_STATE.REPORTING; yield return(StartCoroutine(currentState.ToString())); } else { // put down the value held, and hands are now empty card.MoveTo((int)CurrentValue); CurrentValue = null; yield return(new WaitForSeconds(InstructionDelay)); } currentState = ACTOR_STATE.REPORTING; }
// place the currently held data in Output IEnumerator OUTPUT() { // detect possible errors first if (CurrentValue == null) { // cannot output null error = true; currentState = ACTOR_STATE.REPORTING; yield return(StartCoroutine(currentState.ToString())); } else if (!OutputBox.GetComponent <OutputBox>().Output(CurrentValue.Value)) { // current value is not correct for this solution error = true; currentState = ACTOR_STATE.REPORTING; yield return(StartCoroutine(currentState.ToString())); } // current value is correct HideDataCube(); CurrentValue = null; yield return(new WaitForSeconds(InstructionDelay)); currentState = ACTOR_STATE.REPORTING; }
// simulates the current command being carried out IEnumerator PROCESSING() { while (currentState == ACTOR_STATE.PROCESSING) { // grab the next instruction FetchCommand(); // need to ensure current position is accurate if (!(current.Instruction == OpCode.JUMP) && !(current.Instruction == OpCode.JUMP_IF_NULL) && !(current.Instruction == OpCode.NO_OP) && !(current.Instruction == OpCode.SUBMIT)) { currentState = ACTOR_STATE.MOVING; yield return(StartCoroutine(currentState.ToString())); } if (current == null) { Debug.Log("Processing aborted"); break; } // execute the instruction yield return(StartCoroutine(current.Instruction.ToString())); } }
//*** BEGINNING OF STATE MACHINE ***// IEnumerator ActorStateMachine() { while (true) { yield return(StartCoroutine(currentState.ToString())); } }
// if current value is less than value at destination, jump; else, continue sequential execution IEnumerator JUMP_IF_LESS() { // grab card reference CurrentArg = current.Arg; CardLogic card = cardContainer.GetCard((int)CurrentArg); // Computron gets a copy of the top item from the specified Card SecondValue = card.CopyFrom(); // ensure neither value is null if (CurrentValue == null || SecondValue == null) { error = true; currentState = ACTOR_STATE.REPORTING; yield return(StartCoroutine(currentState.ToString())); } yield return(new WaitForSeconds(InstructionDelay)); conditionalResult = (CurrentValue < SecondValue); // show the two values being compared DisplayMessage(CurrentValue.ToString()); yield return(new WaitForSeconds(InstructionDelay)); DisplayMessage(DisplayText.text + " < "); yield return(new WaitForSeconds(InstructionDelay)); DisplayMessage(DisplayText.text + SecondValue.ToString()); yield return(new WaitForSeconds(InstructionDelay)); DisplayMessage(DisplayText.text + " ?"); yield return(new WaitForSeconds(InstructionDelay)); DisplayMessage(conditionalResult.ToString()); yield return(new WaitForSeconds(InstructionDelay)); ShowDataCube(CurrentValue); HideTextBox(); currentState = ACTOR_STATE.REPORTING; }
// place a copy of the currently held value in the specified Card // Computron still keeps the held value IEnumerator COPY_TO() { // get card reference CurrentArg = current.Arg; CardLogic card = cardContainer.GetCard((int)CurrentArg); // trying to store null causes a runtime error if (CurrentValue == null) { error = true; currentState = ACTOR_STATE.REPORTING; yield return(StartCoroutine(currentState.ToString())); } else { // put down a copy of the value held card.CopyTo((int)CurrentValue); yield return(new WaitForSeconds(InstructionDelay)); } currentState = ACTOR_STATE.REPORTING; }
// generates a report for the instruction that was executed IEnumerator REPORTING() { if (error) { // halt the simulation if an error was encountered in processing CompleteExecution(new ExecutionReport(error, conditionalResult)); currentState = ACTOR_STATE.HALTED; yield return(StartCoroutine(currentState.ToString())); } // if the player is stepping through a solution, we need to hold here while (stepping) { stepCount++; // if we have a Jump or Conditional Jump command, we need to adjust the stepCount accordingly if (current.Instruction == OpCode.JUMP || conditionalResult == true) { // update stepCount stepCount = (int)current.Target; // if this puts us on the second to last command, we need to implicitly submit the solution if (stepCount + 1 == commandStream.GetInstructionCount()) { implicitSubmit = true; } // otherwise, assert false else { implicitSubmit = false; } } // moves to the SUBMIT command without requiring the player to click step again if (implicitSubmit) { BeginProcessing(); } // wait for the player to click step again stepping = false; StepButton.GetComponent <UIControl>().Enable(); while (currentState == ACTOR_STATE.REPORTING) { yield return(null); } break; } // generate a report based on the current values CompleteExecution(new ExecutionReport(error, conditionalResult)); // reset values conditionalResult = null; error = false; // if the simulation is complete while (current.Instruction == OpCode.SUBMIT) { yield return(null); } // else, continue processing currentState = ACTOR_STATE.PROCESSING; }