/// <summary> /// Gets distractors. /// These are wrong answers which can be presented as options to the player. /// </summary> /// <returns>The distractors.</returns> /// <param name="howManyDistractors">How many random distractors to return.</param> public ProblemPart[] GetDistractors(int howManyDistractors) { int availableDistractors = protobufsProblemData.distractor.distractors.Count; if (availableDistractors < howManyDistractors) { throw new Exception("There aren't enough distractors! There are only " + availableDistractors + " distractors."); } ArrayList allDistractors = new ArrayList(); for (int i = 0; i < availableDistractors; i++) { Senseix.Message.Atom.Atom distractorAtom = protobufsProblemData.distractor.distractors[i]; ProblemPart distractor = ProblemPart.CreateProblemPart(distractorAtom); allDistractors.Add(distractor); } //find all the distractors ProblemPart[] resultDistractors = new ProblemPart[howManyDistractors]; for (int i = 0; i < howManyDistractors; i++) { int randomDistractorIndex = UnityEngine.Random.Range(0, allDistractors.Count); resultDistractors[i] = (ProblemPart)allDistractors[randomDistractorIndex]; allDistractors.RemoveAt(randomDistractorIndex); } //take random ones return(resultDistractors); }
public System.Collections.IEnumerator GetEnumerator() { foreach (Senseix.Message.Atom.Atom atom in atomList) { yield return(ProblemPart.CreateProblemPart(atom)); } }
/// <summary> /// Build an answer from a message received from the Thinksy server. For internal use within the Thinksy plugin. /// </summary> public Answer(Senseix.Message.Problem.Answer protoAnswer) { foreach (Senseix.Message.Atom.Atom atom in protoAnswer.answers) { answerParts.Add(ProblemPart.CreateProblemPart(atom)); } }
private void UpdateAnswers() { availableAnswers.Clear(); ProblemPart[] wrongAnswers = new ProblemPart[answerButtonTexts.Length - 1]; if (ThinksyPlugin.GetMostRecentProblem().CountDistractors() >= wrongAnswers.Length) { wrongAnswers = ThinksyPlugin.GetMostRecentProblem().GetDistractors(wrongAnswers.Length); } else { for (int i = 0; i < wrongAnswers.Length; i++) { wrongAnswers [i] = ThinksyPlugin.GetMostRecentProblem().GetDistractor(); } } foreach (ProblemPart wrongAnswer in wrongAnswers) { //add the number of buttons minus one wrong answers availableAnswers.Add(wrongAnswer); } availableAnswers.Add(ThinksyPlugin.GetMostRecentProblem().GetCurrentCorrectAnswerPart()); //add the one right answer Shuffle(availableAnswers); }
static public bool ParseGetEncouragementsResponse(byte[] responseBytes) { Encouragement.EncouragementGetResponse getEncouragementResponse = Deserialize(responseBytes, typeof(Encouragement.EncouragementGetResponse)) as Encouragement.EncouragementGetResponse; Logger.BasicLog("I got an encouragement get response with " + getEncouragementResponse.encouragement_data.Count + " encouragements."); foreach (Encouragement.EncouragementData encouragementData in getEncouragementResponse.encouragement_data) { ProblemPart[] encouragementParts = new ProblemPart[encouragementData.encouragement_atoms.Count]; for (int i = 0; i < encouragementParts.Length; i++) { encouragementParts[i] = ProblemPart.CreateProblemPart(encouragementData.encouragement_atoms[i]); } ThinksyEvents.InvokeEncouragementReceived(encouragementParts); } ThinksyPlugin.NewHeartbeatTiming(getEncouragementResponse.frames_per_heartbeat); if (getEncouragementResponse.force_pull) { ProblemKeeper.PullNewProblems(); } return(true); }
public ProblemPart GetLearningActionPartByIndex(int index) { if (index < 0 || index > GetProto().atoms.Count) { throw new Exception("That is out of range. There are " + GetProto().atoms.Count + " problem parts."); } return(ProblemPart.CreateProblemPart(GetProto().atoms[index])); }
public void InstanceSetItemsToDisplay(ProblemPart[] items) { itemSpritesToDisplay = new Sprite[items.Length]; for (int i = 0; i < items.Length; i++) { itemSpritesToDisplay[i] = items[i].GetSprite(); } currentPageNumber = 0; UpdateDisplay (); }
/// <summary> /// Questions can be represented as a series of ProblemParts /// which contain information to communicate the problem. /// This gets the question part at the given index. /// You can also iterate through a question using foreach /// </summary> public ProblemPart GetQuestionPart(int index) { try { return(ProblemPart.CreateProblemPart(atomList[index])); } catch { throw new Exception("Question part index out of range"); } }
private void EnqueueEmoticons(ProblemPart[] possibleEmoticons) { Debug.Log ("I received " + possibleEmoticons.Length + " possible emoticons."); foreach(ProblemPart possibleEmoticon in possibleEmoticons) { if (possibleEmoticon.HasSprite()) { spritesToShowOff.Enqueue (possibleEmoticon.GetSprite()); } } Debug.Log ("Emoticon Queue length now " + CountEmoticonsWaiting ().ToString ()); }
/// <summary> /// Gets the next correct answer part based on how many answer parts have been /// given so far. /// </summary> /// <returns>The next correct answer part.</returns> public ProblemPart GetCurrentCorrectAnswerPart() { int answersGivenSoFar = givenAnswer.AnswerPartsCount(); if (answersGivenSoFar >= GetCorrectAnswer().AnswerPartsCount()) { throw new Exception("There is no next correct answer part- all answer parts have already been given!"); } ProblemPart nextCorrectAnswer = GetCorrectAnswer().GetAnswerPart(answersGivenSoFar); return(nextCorrectAnswer); }
private void EnqueueMessages(ProblemPart[] possibleMessages) { Debug.Log ("I received " + possibleMessages.Length + " possible messages."); foreach(ProblemPart possibleMessage in possibleMessages) { if (possibleMessage.HasString()) { messagesToShowOff.Enqueue (possibleMessage.GetString()); } } Debug.Log ("Queue length now " + CountMessagesWaiting ().ToString ()); }
private void UpdateButtons() { //char[] letters = new char[]{'A', 'B', 'C', 'D', 'E'}; for (int i = 0; i < answerButtonTexts.Length; i++) { //set button text if (i >= availableAnswers.Count) { Debug.LogWarning("Not enough distractors"); return; } ProblemPart part = (ProblemPart)availableAnswers[i]; answerButtonTexts[i].text = part.GetString(); //"(" + letters[i] + ") " + } }
private void EncouragementsReceived(ProblemPart[] encouragements) { foreach(ProblemPart encouragement in encouragements) { if (encouragement.HasSprite()) { spriteEncouragementsToDisplay.Enqueue(encouragement.GetSprite()); } if (encouragement.HasString()) { stringEncouragementsToDisplay.Enqueue(encouragement.GetString()); } } ShowAllEncouragements (); }
static public bool ParseListItemsResponse(byte[] responseBytes) { Player.ListPlayerItemsResponse listItemsResponse = Deserialize(responseBytes, typeof(Player.ListPlayerItemsResponse)) as Player.ListPlayerItemsResponse; Logger.BasicLog("I got an items list response with " + listItemsResponse.item_atoms.Count + " items"); //foreach(Message.Atom.Atom atom in listItemsResponse.item_atoms) //{ //UnityEngine.Debug.Log(atom.filename); //} ProblemPart[] items = new ProblemPart[listItemsResponse.item_atoms.Count]; for (int i = 0; i < listItemsResponse.item_atoms.Count; i++) { items[i] = ProblemPart.CreateProblemPart(listItemsResponse.item_atoms[i]); } ItemsDisplay.SetItemsToDisplay(items); return(true); }
public static bool ParseGetEncouragementsResponse(byte[] responseBytes) { Encouragement.EncouragementGetResponse getEncouragementResponse = Deserialize (responseBytes, typeof(Encouragement.EncouragementGetResponse)) as Encouragement.EncouragementGetResponse; Logger.BasicLog ("I got an encouragement get response with " + getEncouragementResponse.encouragement_data.Count + " encouragements."); foreach (Encouragement.EncouragementData encouragementData in getEncouragementResponse.encouragement_data) { ProblemPart[] encouragementParts = new ProblemPart[encouragementData.encouragement_atoms.Count]; for (int i = 0; i < encouragementParts.Length; i++) { encouragementParts[i] = ProblemPart.CreateProblemPart(encouragementData.encouragement_atoms[i]); } ThinksyEvents.InvokeEncouragementReceived(encouragementParts); } ThinksyPlugin.NewHeartbeatTiming (getEncouragementResponse.frames_per_heartbeat); if (getEncouragementResponse.force_pull) ProblemKeeper.PullNewProblems (); return true; }
/// <summary> /// Sets the given answer. This can then be checked for correctness through CheckAnswer. /// </summary> public void AddGivenAnswerPart(ProblemPart newGivenAnswerPart) { GetGivenAnswer().AddAnswerPart(newGivenAnswerPart); }
/// <summary> /// Adds a part to this answer. /// </summary> /// <param name="part">Added Part.</param> public void AddAnswerPart(ProblemPart part) { answerParts.Add(part); ThinksyQuestionDisplay.DisplayCurrentQuestion(); }
/// <summary> /// Gets distractors. /// These are wrong answers which can be presented as options to the player. /// </summary> /// <returns>The distractors.</returns> /// <param name="howManyDistractors">How many random distractors to return.</param> public ProblemPart[] GetDistractors(int howManyDistractors) { int availableDistractors = protobufsProblemData.distractor.distractors.Count; if (availableDistractors < howManyDistractors) { throw new Exception("There aren't enough distractors! There are only " + availableDistractors + " distractors."); } ArrayList allDistractors = new ArrayList(); for (int i = 0; i < availableDistractors; i++) { Senseix.Message.Atom.Atom distractorAtom = protobufsProblemData.distractor.distractors[i]; ProblemPart distractor = ProblemPart.CreateProblemPart(distractorAtom); allDistractors.Add(distractor); } //find all the distractors ProblemPart[] resultDistractors = new ProblemPart[howManyDistractors]; for (int i = 0; i < howManyDistractors; i++) { int randomDistractorIndex = UnityEngine.Random.Range (0, allDistractors.Count); resultDistractors[i] = (ProblemPart)allDistractors[randomDistractorIndex]; allDistractors.RemoveAt(randomDistractorIndex); } //take random ones return resultDistractors; }
/// <summary> /// Invokes the encouragement received event. /// </summary> /// <param name="encouragementParts">the text/image pieces which make up /// the encouragement.</param> public static void InvokeEncouragementReceived(ProblemPart[] encouragementParts) { if (onEncouragementReceived != null) onEncouragementReceived (encouragementParts); }
/// <summary> /// Sets the given answer. This can then be checked for correctness through CheckAnswer. /// </summary> public void AddGivenAnswerPart(ProblemPart newGivenAnswerPart) { GetGivenAnswer().AddAnswerPart(newGivenAnswerPart); }
public static void SetItemsToDisplay(ProblemPart[] items) { GetSingletonInstance ().InstanceSetItemsToDisplay (items); }
public static bool ParseListItemsResponse(byte[] responseBytes) { Player.ListPlayerItemsResponse listItemsResponse = Deserialize (responseBytes, typeof(Player.ListPlayerItemsResponse)) as Player.ListPlayerItemsResponse; Logger.BasicLog ("I got an items list response with " + listItemsResponse.item_atoms.Count + " items"); //foreach(Message.Atom.Atom atom in listItemsResponse.item_atoms) //{ //UnityEngine.Debug.Log(atom.filename); //} ProblemPart[] items = new ProblemPart[listItemsResponse.item_atoms.Count]; for (int i = 0; i < listItemsResponse.item_atoms.Count; i++) { items[i] = ProblemPart.CreateProblemPart(listItemsResponse.item_atoms[i]); } ItemsDisplay.SetItemsToDisplay (items); return true; }
private void PopulateRichTextAreas(Problem problemToDisplay) { Question question = problemToDisplay.GetQuestion(); int textAreaCount = question.GetQuestionPartCount(); float ySpacePerArea = 1f / (float)(textAreaCount - question.GetMultipleChoiceLetterCount()); float xSpacePerImage = (float)1 / Mathf.Clamp((float)question.GetMaximumQuestionPartRepeated(), 1, imagesPerRow); float ySpacePerImage = (float)1 / Mathf.Ceil((float)question.GetMaximumQuestionPartRepeated() / (float)imagesPerRow); int row = 0; bool previousAreaWasMultipleChoice = false; if (textAreaCount == 0) { Senseix.Logger.BasicLog("I got a problem with no question atoms."); return; //throw new UnityException ("I got a problem with no question atoms."); } richTextAreas = new GameObject[textAreaCount]; for (int i = 0; i < textAreaCount; i++) { GameObject newArea = Instantiate(questionTextPrefab) as GameObject; ProblemPart problemPart = problemToDisplay.GetQuestion().GetQuestionPart(i); if (newArea.GetComponent <RectTransform>() == null || newArea.GetComponent <Text>() == null) { throw new UnityException("richTextArea must have a rect transform and Text"); } if (problemPart.HasString()) { newArea.GetComponent <Text>().text += problemPart.GetString(); } float indentedX = 0f; if (previousAreaWasMultipleChoice) { indentedX = indentMultipleChoices; } newArea.GetComponent <RectTransform>().SetParent(questionParent); PositionRectTransform(newArea.GetComponent <RectTransform>(), indentedX, 1 - (row + 1) * ySpacePerArea, 1, 1 - row * ySpacePerArea); if (problemPart.HasSprite()) { //squish this a little bit to provide space between image groups newArea.GetComponent <RectTransform>().anchorMin += new Vector2(0f, spaceImageAreas); newArea.GetComponent <RectTransform>().anchorMax -= new Vector2(0f, spaceImageAreas); for (int j = 0; j < problemPart.TimesRepeated(); j++) { GameObject newImage = Instantiate(questionImagePrefab) as GameObject; newImage.GetComponent <RectTransform>().SetParent(newArea.transform); int imageColumn = j % imagesPerRow; int imageRow = Mathf.FloorToInt((float)j / (float)imagesPerRow); PositionRectTransform(newImage.GetComponent <RectTransform>(), (imageColumn * xSpacePerImage), 1 - (imageRow + 1) * ySpacePerImage, ((imageColumn + 1) * xSpacePerImage), 1 - imageRow * ySpacePerImage); newImage.GetComponent <Image>().sprite = problemPart.GetSprite(); } } richTextAreas[i] = newArea; if (!problemPart.IsMultipleChoiceLetter()) { row++; previousAreaWasMultipleChoice = false; } else { previousAreaWasMultipleChoice = true; } } }
/// <summary> /// Adds a part to this answer. /// </summary> /// <param name="part">Added Part.</param> public void AddAnswerPart(ProblemPart part) { answerParts.Add(part); ThinksyQuestionDisplay.DisplayCurrentQuestion (); }