{"repo": "berkm125/a-witch-among-them", "files": {"Assets/Scripts/CourtroomScripts/JudgeController.cs": {"3608effa822cb5da8464163f73bc08657e36a804": {"t": 1785746204.1643991, "n": 13854, "h": "5f62117c0f296ade", "c": "using UnityEngine;\nusing System.Collections;\nusing System.IO;\nusing Newtonsoft.Json.Linq;\nusing System.Collections.Generic;\nusing UnityEngine.SceneManagement;\n\nusing LevelManagerNamespace;\nusing ModelBridge;\nusing Instructions;\n\npublic class JudgeController : MonoBehaviour\n{\n // Public variables for Unity Editor\n public DialogueBoxController dialogueBoxController;\n public GameObject playerPrefab;\n\n // Will increase with every level.\n public int interactionLimit = 2;\n\n // Change this based on which character is on trial.\n public string accusedCharacter = \"character_accused\";\n \n [SerializeField]\n private GameObject player; // Player gameobject in the courtroom.\n \n [SerializeField]\n private GameObject[] accusedCharacters; // Load with ALL possible accused characters on the stand.\n\n // Private variables for internal use\n PlayerDialogue playerDialogue;\n string judgeInstructions;\n string judgePrompt;\n string currentResponse;\n string currentSpeaker = \"judgeContext\";\n string currentContext = \"judgeContext\";\n bool accusedResponded = false;\n int interactionCount = 0;\n\n // Maps to make speaker and dialogue retrieval easier\n Dictionary contextSpeakerMap = new Dictionary();\n Dictionary contextDialogueMap = new Dictionary();\n\n // Start is called once before the first execution of Update after the MonoBehaviour is created\n void Start()\n {\n // Establish the accused character and disable the others.\n accusedCharacter = LevelManager.managerLevels[LevelManager.currentLevel - 1].levelTargetID;\n foreach (GameObject character in accusedCharacters) {\n if (character.name == accusedCharacter) {\n character.SetActive(true);\n } else {\n character.SetActive(false);\n }\n }\n\n // Set interaction limit from level manager\n interactionLimit = LevelManager.managerLevels[LevelManager.currentLevel - 1].interactionLimit;\n\n // Instantiate player prefabs at the specified position \n Instantiate(playerPrefab, new Vector3(5.01000023f,-0.699999988f,0f), Quaternion.identity);\n\n // CLEAR FILE BEFORE ANYTHING\n ClearFile();\n\n // Initialize context speaker and dialogue maps\n contextSpeakerMap[\"judgeContext\"] = \"You, the judge, said\";\n contextSpeakerMap[\"accusedContext\"] = \"The accused person said\";\n contextSpeakerMap[\"playerContext\"] = \"The player said\";\n\n contextDialogueMap[\"judgeContext\"] = \"character_judge\";\n contextDialogueMap[\"accusedContext\"] = accusedCharacter;\n contextDialogueMap[\"playerContext\"] = \"character_player\";\n\n // Initialize dialogue sequence and find player object\n player = GameObject.Find(\"PlayerCourt\");\n playerDialogue = player.GetComponent();\n\n // Dialogue sequence coroutines must END before another is triggered to avoid feeding the\n // dialogue buffers with multiple dialogues at once through multiple coroutines.\n dialogueBoxController.AddDialogue(\"character_judge\", \"Give me a minute before I deliver my opening statement...\");\n StartCoroutine(dialogueBoxController.ShowDialogueExtended((string arg) => {\n SetCurrentContext(\"judgeContext\");\n\n // Judge should deliver opening statement upon entry into the court\n LoadJudgeInstructions(Instructions.JudgeStatement.DELIVER_OPENING_STATEMENT);\n StartCoroutine(ModelBridge.Bridge.ChatCompletion(\"https://api.deepseek.com\",\n judgeInstructions,\n judgePrompt,\n ProcessDialogue));\n }));\n }\n\n // Update is called once per frame\n void Update()\n {\n }\n\n // Set the current context and speaker based on the context\n public void SetCurrentContext(string context)\n {\n Debug.Log(\"Was called\");\n currentContext = context;\n currentSpeaker = contextSpeakerMap[context];\n }\n\n // Send message to the Judge\n public void SendJudgeMessage(string message)\n {\n judgePrompt = message;\n dialogueBoxController.AddDialogue(\"character_judge\", \"Let me think...\");\n StartCoroutine(dialogueBoxController.ShowDialogueExtended((string arg) => {\n StartCoroutine(ModelBridge.Bridge.ChatCompletion(\"https://api.deepseek.com\",\n judgeInstructions,\n judgePrompt,\n ProcessDialogue));\n }));\n }\n\n // Load judge instructions and prompt from JSON file\n public void LoadJudgeInstructions(int instructionType)\n {\n string filePath = Path.Combine(Application.dataPath, \"Scripts/ModelInterface/judge_instructions.json\");\n if (File.Exists(filePath))\n {\n string judgementType = \"\";\n string promptType = \"\";\n string contextType = \"\";\n\n // Determine the type of instruction and set the appropriate variables\n switch (instructionType) {\n case Instructions.JudgeStatement.DELIVER_JUDGMENT:\n judgementType = \"finalInstructions\";\n promptType = \"judgmentPrompt\";\n contextType = \"judgeContext\";\n break;\n case Instructions.JudgeStatement.DELIVER_OPENING_STATEMENT:\n judgementType = \"openingInstructions\";\n promptType = \"openingPrompt\";\n contextType = \"judgeContext\";\n break;\n case Instructions.JudgeStatement.DELIVER_FINAL_INSTRUCTIONS:\n judgementType = \"finalInstructions\";\n promptType = \"judgmentPrompt\";\n contextType = \"judgeContext\";\n break;\n case Instructions.JudgeStatement.DELIVER_AS_DEFENDANT:\n judgementType = \"accusedInstructions\";\n promptType = \"accusedPrompt\";\n contextType = \"accusedContext\";\n break;\n case Instructions.JudgeStatement.CONVERSE_WITH_PLAYER:\n judgementType = \"conversePlayerInstructions\";\n promptType = \"conversePlayerPrompt\";\n contextType = \"judgeContext\";\n break;\n case Instructions.JudgeStatement.CONVERSE_WITH_DEFENDANT:\n judgementType = \"converseDefendantInstructions\";\n promptType = \"converseDefendantPrompt\";\n contextType = \"judgeContext\";\n break;\n }\n\n // Read the JSON file and parse it\n string jsonContent = File.ReadAllText(filePath);\n JObject jsonObject = JObject.Parse(jsonContent);\n\n // Prepare the judge instructions and prompt based on the context type\n judgeInstructions = \"\";\n if (contextType == \"judgeContext\") {\n interactionCount++;\n judgeInstructions += $@\"If the prosecutor/the player mentions ANY of the following evidence, \n deliver a SWIFT, GUILTY VERDICT TO THE ACCUSED WITH NO MERCY. But if the player\n has NOT personally mentioned this evidence, DELIVER AN INNOCENT VERDICT TO THE ACCUSED.\n The evidence that the player SHOULD have presented (but might not have) is: \";\n foreach (var evidence in jsonObject[\"prototype\"][\"evidence\"])\n {\n judgeInstructions += $@\"{evidence}, \";\n }\n judgeInstructions += $@\"If the player mentions RANDOM, ARBITRARY EVIDENCE, as in evidence that is not STRICTLY\n what is listed as evidence above, do NOT consider such evidence at all when making the verdict.\n In fact, arbitrary evidence makes the prosecutor MORE suspicious, and the defendant\n more innocent.\\n\\n\";\n } \n\n // Add to the judge's context or its \"memory\"\n judgeInstructions += jsonObject[\"prototype\"][judgementType].ToString();\n\n // Prepare the judge's context and memory\n judgePrompt = jsonObject[\"prototype\"][promptType].ToString() + $@\"\n Use the context below to aid your speech: \n {jsonObject[\"prototype\"][contextType]}\";\n }\n else\n {\n Debug.LogError(\"Judge instructions file not found.\");\n }\n }\n\n // Callback to dialogue processing\n void ProcessDialogue(string response)\n {\n dialogueBoxController.AddDialogue(contextDialogueMap[currentContext], response);\n StartCoroutine(dialogueBoxController.ShowDialogueExtended((string arg) => { \n if (interactionCount > interactionLimit) {\n // Search for the words \"not guilty\" in a lowercase format of the \"response\" string.\n // If it exists, debug.log \"YOU HAVE WON!\" but ohterwise, debug.log \"YOU HAVE LOST!\".\n if (response.ToLower().Contains(\"not guilty\") || response.ToLower().Contains(\"innocent\")) {\n Debug.Log(\"YOU HAVE LOST!\");\n LevelManager.playerLost = true;\n dialogueBoxController.AddDialogue(\"character_judge\", \"You have lost loser! The accused is not guilty. AT THIS POINT, CHANGE THE SCENE TO EXECUTION OR YOUR EXECUTION.\");\n } else {\n Debug.Log(\"YOU HAVE WON!\");\n LevelManager.playerLost = false;\n dialogueBoxController.AddDialogue(\"character_judge\", \"You have won! The accused is guilty. AT THIS POINT, CHANGE THE SCENE TO EXECUTION OR YOUR EXECUTION.\");\n }\n\n // Type out the dialogue!\n StartCoroutine(dialogueBoxController.ShowDialogueExtended((string arg) => {\n // Change scene to New Athens Town and set currentLevel to 2\n LevelManager.currentLevel += 1;\n UnityEngine.SceneManagement.SceneManager.LoadScene(\"ExecutionGround\");\n }));\n\n // Change scene to \n } \n else {\n playerDialogue.EnableChat();\n\n // Open the judge_instructions.json file and prepare it for writing\n string filePath = Path.Combine(Application.dataPath, \"Scripts/ModelInterface/judge_instructions.json\");\n if (File.Exists(filePath))\n {\n try\n { \n string jsonContent = File.ReadAllText(filePath);\n JObject jsonObject = JObject.Parse(jsonContent);\n jsonObject[\"prototype\"][\"judgeContext\"] += $@\"\\n{contextSpeakerMap[currentContext]} said: {response}, \";\n jsonObject[\"prototype\"][\"accusedContext\"] += $@\"\\n{contextSpeakerMap[currentContext]} said: {response}, \";\n\n string jsonFileContent = jsonObject.ToString();\n using (StreamWriter writer = new StreamWriter(filePath, false))\n {\n writer.Write(jsonFileContent);\n }\n }\n catch (IOException ex)\n {\n Debug.LogError(\"Error opening judge_instructions.json for writing: \" + ex.Message);\n }\n }\n else\n {\n Debug.LogError(\"Judge instructions file not found.\");\n }\n\n // Make sure that if the accused is currently delivering speech, it is relayed to the judge.\n if (currentContext == \"accusedContext\")\n {\n SetCurrentContext(\"judgeContext\");\n if (interactionCount == interactionLimit)\n {\n LoadJudgeInstructions(Instructions.JudgeStatement.DELIVER_JUDGMENT);\n }\n else\n {\n LoadJudgeInstructions(Instructions.JudgeStatement.CONVERSE_WITH_PLAYER);\n }\n currentResponse = response;\n SendJudgeMessage(currentResponse);\n }\n }\n }));\n\n }\n\n\n // Init clear file\n void ClearFile()\n {\n string filePath = Path.Combine(Application.dataPath, \"Scripts/ModelInterface/judge_instructions.json\");\n if (File.Exists(filePath))\n {\n try\n { \n string jsonContent = File.ReadAllText(filePath);\n JObject jsonObject = JObject.Parse(jsonContent);\n jsonObject[\"prototype\"][\"judgeContext\"] = \"\";\n jsonObject[\"prototype\"][\"accusedContext\"] = \"\";\n jsonObject[\"prototype\"][\"playerContext\"] = \"\";\n\n string jsonFileContent = jsonObject.ToString();\n using (StreamWriter writer = new StreamWriter(filePath, false))\n {\n writer.Write(jsonFileContent);\n }\n }\n catch (IOException ex)\n {\n Debug.LogError(\"Error opening judge_instructions.json for writing: \" + ex.Message);\n }\n }\n else\n {\n Debug.LogError(\"Judge instructions file not found.\");\n }\n }\n}\n"}, "65121e7e2bdf5f17fffa1b9a383abebe52a0971e": {"t": 1785760583.5876446, "n": 13854, "h": "5f62117c0f296ade", "c": "using UnityEngine;\nusing System.Collections;\nusing System.IO;\nusing Newtonsoft.Json.Linq;\nusing System.Collections.Generic;\nusing UnityEngine.SceneManagement;\n\nusing LevelManagerNamespace;\nusing ModelBridge;\nusing Instructions;\n\npublic class JudgeController : MonoBehaviour\n{\n // Public variables for Unity Editor\n public DialogueBoxController dialogueBoxController;\n public GameObject playerPrefab;\n\n // Will increase with every level.\n public int interactionLimit = 2;\n\n // Change this based on which character is on trial.\n public string accusedCharacter = \"character_accused\";\n \n [SerializeField]\n private GameObject player; // Player gameobject in the courtroom.\n \n [SerializeField]\n private GameObject[] accusedCharacters; // Load with ALL possible accused characters on the stand.\n\n // Private variables for internal use\n PlayerDialogue playerDialogue;\n string judgeInstructions;\n string judgePrompt;\n string currentResponse;\n string currentSpeaker = \"judgeContext\";\n string currentContext = \"judgeContext\";\n bool accusedResponded = false;\n int interactionCount = 0;\n\n // Maps to make speaker and dialogue retrieval easier\n Dictionary contextSpeakerMap = new Dictionary();\n Dictionary contextDialogueMap = new Dictionary();\n\n // Start is called once before the first execution of Update after the MonoBehaviour is created\n void Start()\n {\n // Establish the accused character and disable the others.\n accusedCharacter = LevelManager.managerLevels[LevelManager.currentLevel - 1].levelTargetID;\n foreach (GameObject character in accusedCharacters) {\n if (character.name == accusedCharacter) {\n character.SetActive(true);\n } else {\n character.SetActive(false);\n }\n }\n\n // Set interaction limit from level manager\n interactionLimit = LevelManager.managerLevels[LevelManager.currentLevel - 1].interactionLimit;\n\n // Instantiate player prefabs at the specified position \n Instantiate(playerPrefab, new Vector3(5.01000023f,-0.699999988f,0f), Quaternion.identity);\n\n // CLEAR FILE BEFORE ANYTHING\n ClearFile();\n\n // Initialize context speaker and dialogue maps\n contextSpeakerMap[\"judgeContext\"] = \"You, the judge, said\";\n contextSpeakerMap[\"accusedContext\"] = \"The accused person said\";\n contextSpeakerMap[\"playerContext\"] = \"The player said\";\n\n contextDialogueMap[\"judgeContext\"] = \"character_judge\";\n contextDialogueMap[\"accusedContext\"] = accusedCharacter;\n contextDialogueMap[\"playerContext\"] = \"character_player\";\n\n // Initialize dialogue sequence and find player object\n player = GameObject.Find(\"PlayerCourt\");\n playerDialogue = player.GetComponent();\n\n // Dialogue sequence coroutines must END before another is triggered to avoid feeding the\n // dialogue buffers with multiple dialogues at once through multiple coroutines.\n dialogueBoxController.AddDialogue(\"character_judge\", \"Give me a minute before I deliver my opening statement...\");\n StartCoroutine(dialogueBoxController.ShowDialogueExtended((string arg) => {\n SetCurrentContext(\"judgeContext\");\n\n // Judge should deliver opening statement upon entry into the court\n LoadJudgeInstructions(Instructions.JudgeStatement.DELIVER_OPENING_STATEMENT);\n StartCoroutine(ModelBridge.Bridge.ChatCompletion(\"https://api.deepseek.com\",\n judgeInstructions,\n judgePrompt,\n ProcessDialogue));\n }));\n }\n\n // Update is called once per frame\n void Update()\n {\n }\n\n // Set the current context and speaker based on the context\n public void SetCurrentContext(string context)\n {\n Debug.Log(\"Was called\");\n currentContext = context;\n currentSpeaker = contextSpeakerMap[context];\n }\n\n // Send message to the Judge\n public void SendJudgeMessage(string message)\n {\n judgePrompt = message;\n dialogueBoxController.AddDialogue(\"character_judge\", \"Let me think...\");\n StartCoroutine(dialogueBoxController.ShowDialogueExtended((string arg) => {\n StartCoroutine(ModelBridge.Bridge.ChatCompletion(\"https://api.deepseek.com\",\n judgeInstructions,\n judgePrompt,\n ProcessDialogue));\n }));\n }\n\n // Load judge instructions and prompt from JSON file\n public void LoadJudgeInstructions(int instructionType)\n {\n string filePath = Path.Combine(Application.dataPath, \"Scripts/ModelInterface/judge_instructions.json\");\n if (File.Exists(filePath))\n {\n string judgementType = \"\";\n string promptType = \"\";\n string contextType = \"\";\n\n // Determine the type of instruction and set the appropriate variables\n switch (instructionType) {\n case Instructions.JudgeStatement.DELIVER_JUDGMENT:\n judgementType = \"finalInstructions\";\n promptType = \"judgmentPrompt\";\n contextType = \"judgeContext\";\n break;\n case Instructions.JudgeStatement.DELIVER_OPENING_STATEMENT:\n judgementType = \"openingInstructions\";\n promptType = \"openingPrompt\";\n contextType = \"judgeContext\";\n break;\n case Instructions.JudgeStatement.DELIVER_FINAL_INSTRUCTIONS:\n judgementType = \"finalInstructions\";\n promptType = \"judgmentPrompt\";\n contextType = \"judgeContext\";\n break;\n case Instructions.JudgeStatement.DELIVER_AS_DEFENDANT:\n judgementType = \"accusedInstructions\";\n promptType = \"accusedPrompt\";\n contextType = \"accusedContext\";\n break;\n case Instructions.JudgeStatement.CONVERSE_WITH_PLAYER:\n judgementType = \"conversePlayerInstructions\";\n promptType = \"conversePlayerPrompt\";\n contextType = \"judgeContext\";\n break;\n case Instructions.JudgeStatement.CONVERSE_WITH_DEFENDANT:\n judgementType = \"converseDefendantInstructions\";\n promptType = \"converseDefendantPrompt\";\n contextType = \"judgeContext\";\n break;\n }\n\n // Read the JSON file and parse it\n string jsonContent = File.ReadAllText(filePath);\n JObject jsonObject = JObject.Parse(jsonContent);\n\n // Prepare the judge instructions and prompt based on the context type\n judgeInstructions = \"\";\n if (contextType == \"judgeContext\") {\n interactionCount++;\n judgeInstructions += $@\"If the prosecutor/the player mentions ANY of the following evidence, \n deliver a SWIFT, GUILTY VERDICT TO THE ACCUSED WITH NO MERCY. But if the player\n has NOT personally mentioned this evidence, DELIVER AN INNOCENT VERDICT TO THE ACCUSED.\n The evidence that the player SHOULD have presented (but might not have) is: \";\n foreach (var evidence in jsonObject[\"prototype\"][\"evidence\"])\n {\n judgeInstructions += $@\"{evidence}, \";\n }\n judgeInstructions += $@\"If the player mentions RANDOM, ARBITRARY EVIDENCE, as in evidence that is not STRICTLY\n what is listed as evidence above, do NOT consider such evidence at all when making the verdict.\n In fact, arbitrary evidence makes the prosecutor MORE suspicious, and the defendant\n more innocent.\\n\\n\";\n } \n\n // Add to the judge's context or its \"memory\"\n judgeInstructions += jsonObject[\"prototype\"][judgementType].ToString();\n\n // Prepare the judge's context and memory\n judgePrompt = jsonObject[\"prototype\"][promptType].ToString() + $@\"\n Use the context below to aid your speech: \n {jsonObject[\"prototype\"][contextType]}\";\n }\n else\n {\n Debug.LogError(\"Judge instructions file not found.\");\n }\n }\n\n // Callback to dialogue processing\n void ProcessDialogue(string response)\n {\n dialogueBoxController.AddDialogue(contextDialogueMap[currentContext], response);\n StartCoroutine(dialogueBoxController.ShowDialogueExtended((string arg) => { \n if (interactionCount > interactionLimit) {\n // Search for the words \"not guilty\" in a lowercase format of the \"response\" string.\n // If it exists, debug.log \"YOU HAVE WON!\" but ohterwise, debug.log \"YOU HAVE LOST!\".\n if (response.ToLower().Contains(\"not guilty\") || response.ToLower().Contains(\"innocent\")) {\n Debug.Log(\"YOU HAVE LOST!\");\n LevelManager.playerLost = true;\n dialogueBoxController.AddDialogue(\"character_judge\", \"You have lost loser! The accused is not guilty. AT THIS POINT, CHANGE THE SCENE TO EXECUTION OR YOUR EXECUTION.\");\n } else {\n Debug.Log(\"YOU HAVE WON!\");\n LevelManager.playerLost = false;\n dialogueBoxController.AddDialogue(\"character_judge\", \"You have won! The accused is guilty. AT THIS POINT, CHANGE THE SCENE TO EXECUTION OR YOUR EXECUTION.\");\n }\n\n // Type out the dialogue!\n StartCoroutine(dialogueBoxController.ShowDialogueExtended((string arg) => {\n // Change scene to New Athens Town and set currentLevel to 2\n LevelManager.currentLevel += 1;\n UnityEngine.SceneManagement.SceneManager.LoadScene(\"ExecutionGround\");\n }));\n\n // Change scene to \n } \n else {\n playerDialogue.EnableChat();\n\n // Open the judge_instructions.json file and prepare it for writing\n string filePath = Path.Combine(Application.dataPath, \"Scripts/ModelInterface/judge_instructions.json\");\n if (File.Exists(filePath))\n {\n try\n { \n string jsonContent = File.ReadAllText(filePath);\n JObject jsonObject = JObject.Parse(jsonContent);\n jsonObject[\"prototype\"][\"judgeContext\"] += $@\"\\n{contextSpeakerMap[currentContext]} said: {response}, \";\n jsonObject[\"prototype\"][\"accusedContext\"] += $@\"\\n{contextSpeakerMap[currentContext]} said: {response}, \";\n\n string jsonFileContent = jsonObject.ToString();\n using (StreamWriter writer = new StreamWriter(filePath, false))\n {\n writer.Write(jsonFileContent);\n }\n }\n catch (IOException ex)\n {\n Debug.LogError(\"Error opening judge_instructions.json for writing: \" + ex.Message);\n }\n }\n else\n {\n Debug.LogError(\"Judge instructions file not found.\");\n }\n\n // Make sure that if the accused is currently delivering speech, it is relayed to the judge.\n if (currentContext == \"accusedContext\")\n {\n SetCurrentContext(\"judgeContext\");\n if (interactionCount == interactionLimit)\n {\n LoadJudgeInstructions(Instructions.JudgeStatement.DELIVER_JUDGMENT);\n }\n else\n {\n LoadJudgeInstructions(Instructions.JudgeStatement.CONVERSE_WITH_PLAYER);\n }\n currentResponse = response;\n SendJudgeMessage(currentResponse);\n }\n }\n }));\n\n }\n\n\n // Init clear file\n void ClearFile()\n {\n string filePath = Path.Combine(Application.dataPath, \"Scripts/ModelInterface/judge_instructions.json\");\n if (File.Exists(filePath))\n {\n try\n { \n string jsonContent = File.ReadAllText(filePath);\n JObject jsonObject = JObject.Parse(jsonContent);\n jsonObject[\"prototype\"][\"judgeContext\"] = \"\";\n jsonObject[\"prototype\"][\"accusedContext\"] = \"\";\n jsonObject[\"prototype\"][\"playerContext\"] = \"\";\n\n string jsonFileContent = jsonObject.ToString();\n using (StreamWriter writer = new StreamWriter(filePath, false))\n {\n writer.Write(jsonFileContent);\n }\n }\n catch (IOException ex)\n {\n Debug.LogError(\"Error opening judge_instructions.json for writing: \" + ex.Message);\n }\n }\n else\n {\n Debug.LogError(\"Judge instructions file not found.\");\n }\n }\n}\n"}, "f2da13b38394d220ba105a4e22b708a50a00830e": {"t": 1785760586.2318885, "n": 13747, "h": "dc8ed858ac99346c", "c": "using UnityEngine;\nusing System.Collections;\nusing System.IO;\nusing Newtonsoft.Json.Linq;\nusing System.Collections.Generic;\nusing UnityEngine.SceneManagement;\n\nusing LevelManagerNamespace;\nusing ModelBridge;\nusing Instructions;\n\npublic class JudgeController : MonoBehaviour\n{\n // Public variables for Unity Editor\n public DialogueBoxController dialogueBoxController;\n public GameObject playerPrefab;\n\n // Will increase with every level.\n public int interactionLimit = 2;\n\n // Change this based on which character is on trial.\n public string accusedCharacter = \"character_accused\";\n \n [SerializeField]\n private GameObject player; // Player gameobject in the courtroom.\n \n [SerializeField]\n private GameObject[] accusedCharacters; // Load with ALL possible accused characters on the stand.\n\n // Private variables for internal use\n PlayerDialogue playerDialogue;\n string judgeInstructions;\n string judgePrompt;\n string currentResponse;\n string currentSpeaker = \"judgeContext\";\n string currentContext = \"judgeContext\";\n bool accusedResponded = false;\n int interactionCount = 0;\n\n // Maps to make speaker and dialogue retrieval easier\n Dictionary contextSpeakerMap = new Dictionary();\n Dictionary contextDialogueMap = new Dictionary();\n\n // Start is called once before the first execution of Update after the MonoBehaviour is created\n void Start()\n {\n // Establish the accused character and disable the others.\n accusedCharacter = LevelManager.managerLevels[LevelManager.currentLevel - 1].levelTarget;\n foreach (GameObject character in accusedCharacters) {\n if (character.name == accusedCharacter) {\n character.SetActive(true);\n } else {\n character.SetActive(false);\n }\n }\n\n // Set interaction limit from level manager\n interactionLimit = LevelManager.managerLevels[LevelManager.currentLevel - 1].interactionLimit;\n\n // Instantiate player prefabs at the specified position \n Instantiate(playerPrefab, new Vector3(5.01000023f,-0.699999988f,0f), Quaternion.identity);\n\n // CLEAR FILE BEFORE ANYTHING\n ClearFile();\n\n // Initialize context speaker and dialogue maps\n contextSpeakerMap[\"judgeContext\"] = \"You, the judge, said\";\n contextSpeakerMap[\"accusedContext\"] = \"The accused person said\";\n contextSpeakerMap[\"playerContext\"] = \"The player said\";\n\n contextDialogueMap[\"judgeContext\"] = \"character_judge\";\n contextDialogueMap[\"accusedContext\"] = accusedCharacter;\n contextDialogueMap[\"playerContext\"] = \"character_player\";\n\n // Initialize dialogue sequence and find player object\n player = GameObject.Find(\"PlayerCourt\");\n playerDialogue = player.GetComponent();\n\n // Dialogue sequence coroutines must END before another is triggered to avoid feeding the\n // dialogue buffers with multiple dialogues at once through multiple coroutines.\n dialogueBoxController.AddDialogue(\"character_judge\", \"Give me a minute before I deliver my opening statement...\");\n StartCoroutine(dialogueBoxController.ShowDialogueExtended((string arg) => {\n SetCurrentContext(\"judgeContext\");\n\n // Judge should deliver opening statement upon entry into the court\n LoadJudgeInstructions(Instructions.JudgeStatement.DELIVER_OPENING_STATEMENT);\n StartCoroutine(ModelBridge.Bridge.ChatCompletion(\"https://api.deepseek.com\",\n judgeInstructions,\n judgePrompt,\n ProcessDialogue));\n }));\n }\n\n // Update is called once per frame\n void Update()\n {\n }\n\n // Set the current context and speaker based on the context\n public void SetCurrentContext(string context)\n {\n Debug.Log(\"Was called\");\n currentContext = context;\n currentSpeaker = contextSpeakerMap[context];\n }\n\n // Send message to the Judge\n public void SendJudgeMessage(string message)\n {\n judgePrompt = message;\n dialogueBoxController.AddDialogue(\"character_judge\", \"Let me think...\");\n StartCoroutine(dialogueBoxController.ShowDialogueExtended((string arg) => {\n StartCoroutine(ModelBridge.Bridge.ChatCompletion(\"https://api.deepseek.com\",\n judgeInstructions,\n judgePrompt,\n ProcessDialogue));\n }));\n }\n\n // Load judge instructions and prompt from JSON file\n public void LoadJudgeInstructions(int instructionType)\n {\n string filePath = Path.Combine(Application.dataPath, \"Scripts/ModelInterface/judge_instructions.json\");\n if (File.Exists(filePath))\n {\n string judgementType = \"\";\n string promptType = \"\";\n string contextType = \"\";\n\n // Determine the type of instruction and set the appropriate variables\n switch (instructionType) {\n case Instructions.JudgeStatement.DELIVER_JUDGMENT:\n judgementType = \"finalInstructions\";\n promptType = \"judgmentPrompt\";\n contextType = \"judgeContext\";\n break;\n case Instructions.JudgeStatement.DELIVER_OPENING_STATEMENT:\n judgementType = \"openingInstructions\";\n promptType = \"openingPrompt\";\n contextType = \"judgeContext\";\n break;\n case Instructions.JudgeStatement.DELIVER_FINAL_INSTRUCTIONS:\n judgementType = \"finalInstructions\";\n promptType = \"judgmentPrompt\";\n contextType = \"judgeContext\";\n break;\n case Instructions.JudgeStatement.DELIVER_AS_DEFENDANT:\n judgementType = \"accusedInstructions\";\n promptType = \"accusedPrompt\";\n contextType = \"accusedContext\";\n break;\n case Instructions.JudgeStatement.CONVERSE_WITH_PLAYER:\n judgementType = \"conversePlayerInstructions\";\n promptType = \"conversePlayerPrompt\";\n contextType = \"judgeContext\";\n break;\n case Instructions.JudgeStatement.CONVERSE_WITH_DEFENDANT:\n judgementType = \"converseDefendantInstructions\";\n promptType = \"converseDefendantPrompt\";\n contextType = \"judgeContext\";\n break;\n }\n\n // Read the JSON file and parse it\n string jsonContent = File.ReadAllText(filePath);\n JObject jsonObject = JObject.Parse(jsonContent);\n\n // Prepare the judge instructions and prompt based on the context type\n judgeInstructions = \"\";\n if (contextType == \"judgeContext\") {\n interactionCount++;\n judgeInstructions += $@\"If the prosecutor/the player mentions ANY of the following evidence, \n deliver a SWIFT, GUILTY VERDICT TO THE ACCUSED WITH NO MERCY. But if the player\n has NOT personally mentioned this evidence, DELIVER AN INNOCENT VERDICT TO THE ACCUSED.\n The evidence that the player SHOULD have presented (but might not have) is: \";\n foreach (var evidence in jsonObject[\"prototype\"][\"evidence\"])\n {\n judgeInstructions += $@\"{evidence}, \";\n }\n judgeInstructions += $@\"If the player mentions RANDOM, ARBITRARY EVIDENCE, as in evidence that is not STRICTLY\n what is listed as evidence above, do NOT consider such evidence at all when making the verdict.\n In fact, arbitrary evidence makes the prosecutor MORE suspicious, and the defendant\n more innocent.\\n\\n\";\n } \n\n // Add to the judge's context or its \"memory\"\n judgeInstructions += jsonObject[\"prototype\"][judgementType].ToString();\n\n // Prepare the judge's context and memory\n judgePrompt = jsonObject[\"prototype\"][promptType].ToString() + $@\"\n Use the context below to aid your speech: \n {jsonObject[\"prototype\"][contextType]}\";\n }\n else\n {\n Debug.LogError(\"Judge instructions file not found.\");\n }\n }\n\n // Callback to dialogue processing\n void ProcessDialogue(string response)\n {\n dialogueBoxController.AddDialogue(contextDialogueMap[currentContext], response);\n StartCoroutine(dialogueBoxController.ShowDialogueExtended((string arg) => { \n if (interactionCount > interactionLimit) {\n // Search for the words \"not guilty\" in a lowercase format of the \"response\" string.\n // If it exists, debug.log \"YOU HAVE WON!\" but ohterwise, debug.log \"YOU HAVE LOST!\".\n if (response.ToLower().Contains(\"not guilty\") || response.ToLower().Contains(\"innocent\")) {\n Debug.Log(\"YOU HAVE LOST!\");\n dialogueBoxController.AddDialogue(\"character_judge\", \"You have lost loser! The accused is not guilty. AT THIS POINT, CHANGE THE SCENE TO EXECUTION OR YOUR EXECUTION.\");\n } else {\n Debug.Log(\"YOU HAVE WON!\");\n dialogueBoxController.AddDialogue(\"character_judge\", \"You have won! The accused is guilty. AT THIS POINT, CHANGE THE SCENE TO EXECUTION OR YOUR EXECUTION.\");\n }\n\n // Type out the dialogue!\n StartCoroutine(dialogueBoxController.ShowDialogueExtended((string arg) => {\n // Change scene to New Athens Town and set currentLevel to 2\n LevelManager.currentLevel += 1;\n UnityEngine.SceneManagement.SceneManager.LoadScene(\"New Athens Town\");\n }));\n\n // Change scene to \n } \n else {\n playerDialogue.EnableChat();\n\n // Open the judge_instructions.json file and prepare it for writing\n string filePath = Path.Combine(Application.dataPath, \"Scripts/ModelInterface/judge_instructions.json\");\n if (File.Exists(filePath))\n {\n try\n { \n string jsonContent = File.ReadAllText(filePath);\n JObject jsonObject = JObject.Parse(jsonContent);\n jsonObject[\"prototype\"][\"judgeContext\"] += $@\"\\n{contextSpeakerMap[currentContext]} said: {response}, \";\n jsonObject[\"prototype\"][\"accusedContext\"] += $@\"\\n{contextSpeakerMap[currentContext]} said: {response}, \";\n\n string jsonFileContent = jsonObject.ToString();\n using (StreamWriter writer = new StreamWriter(filePath, false))\n {\n writer.Write(jsonFileContent);\n }\n }\n catch (IOException ex)\n {\n Debug.LogError(\"Error opening judge_instructions.json for writing: \" + ex.Message);\n }\n }\n else\n {\n Debug.LogError(\"Judge instructions file not found.\");\n }\n\n // Make sure that if the accused is currently delivering speech, it is relayed to the judge.\n if (currentContext == \"accusedContext\")\n {\n SetCurrentContext(\"judgeContext\");\n if (interactionCount == interactionLimit)\n {\n LoadJudgeInstructions(Instructions.JudgeStatement.DELIVER_JUDGMENT);\n }\n else\n {\n LoadJudgeInstructions(Instructions.JudgeStatement.CONVERSE_WITH_PLAYER);\n }\n currentResponse = response;\n SendJudgeMessage(currentResponse);\n }\n }\n }));\n\n }\n\n\n // Init clear file\n void ClearFile()\n {\n string filePath = Path.Combine(Application.dataPath, \"Scripts/ModelInterface/judge_instructions.json\");\n if (File.Exists(filePath))\n {\n try\n { \n string jsonContent = File.ReadAllText(filePath);\n JObject jsonObject = JObject.Parse(jsonContent);\n jsonObject[\"prototype\"][\"judgeContext\"] = \"\";\n jsonObject[\"prototype\"][\"accusedContext\"] = \"\";\n jsonObject[\"prototype\"][\"playerContext\"] = \"\";\n\n string jsonFileContent = jsonObject.ToString();\n using (StreamWriter writer = new StreamWriter(filePath, false))\n {\n writer.Write(jsonFileContent);\n }\n }\n catch (IOException ex)\n {\n Debug.LogError(\"Error opening judge_instructions.json for writing: \" + ex.Message);\n }\n }\n else\n {\n Debug.LogError(\"Judge instructions file not found.\");\n }\n }\n}\n"}, "d6074eff583dc63ef2b38f739498943a97360ad1": {"t": 1785760588.5643556, "n": 12688, "h": "5772cf84294a31c2", "c": "using UnityEngine;\nusing System.Collections;\nusing System.IO;\nusing Newtonsoft.Json.Linq;\nusing System.Collections.Generic;\nusing UnityEngine.SceneManagement;\n\nusing LevelManagerNamespace;\nusing ModelBridge;\nusing Instructions;\n\npublic class JudgeController : MonoBehaviour\n{\n // Will increase with every level.\n public int interactionLimit = 2;\n\n // Change this based on which character is on trial.\n public string accusedCharacter = \"character_accused\";\n \n [SerializeField]\n private GameObject player;\n \n [SerializeField]\n private GameObject george_obj; // George Heff character object, only used in level 2\n\n private PlayerDialogue playerDialogue;\n string judgeInstructions;\n string judgePrompt;\n string currentResponse;\n string currentSpeaker = \"judgeContext\";\n string currentContext = \"judgeContext\";\n bool accusedResponded = false;\n int interactionCount = 0;\n public DialogueBoxController dialogueBoxController;\n public GameObject playerPrefab;\n\n Dictionary contextSpeakerMap = new Dictionary();\n Dictionary contextDialogueMap = new Dictionary();\n // Start is called once before the first execution of Update after the MonoBehaviour is created\n void Start()\n {\n if (LevelManager.currentLevel == 1) {\n accusedCharacter = \"character_accused\";\n } else if (LevelManager.currentLevel == 2) {\n Destroy(GameObject.Find(\"character_accused\"));\n george_obj.SetActive(true);\n\n accusedCharacter = \"george_heff\";\n }\n\n Instantiate(playerPrefab, new Vector3(5.01000023f,-0.699999988f,0f), Quaternion.identity);\n Instantiate(playerPrefab, new Vector3(5.01000023f,-0.699999988f,0f), Quaternion.identity);\n\n // CLEAR FILE BEFORE ANYTHING\n ClearFile();\n\n contextSpeakerMap[\"judgeContext\"] = \"You, the judge, said\";\n contextSpeakerMap[\"accusedContext\"] = \"The accused person said\";\n contextSpeakerMap[\"playerContext\"] = \"The player said\";\n\n contextDialogueMap[\"judgeContext\"] = \"character_judge\";\n contextDialogueMap[\"accusedContext\"] = accusedCharacter;\n contextDialogueMap[\"playerContext\"] = \"character_player\";\n\n player = GameObject.Find(\"PlayerCourt\");\n playerDialogue = player.GetComponent();\n\n dialogueBoxController.AddDialogue(\"character_judge\", \"Give me a minute before I deliver my opening statement...\");\n StartCoroutine(dialogueBoxController.ShowDialogueExtended((string arg) => {\n SetCurrentContext(\"judgeContext\");\n\n // Judge should deliver opening statement upon entry into the court\n LoadJudgeInstructions(Instructions.JudgeStatement.DELIVER_OPENING_STATEMENT);\n StartCoroutine(ModelBridge.Bridge.ChatCompletion(\"https://api.deepseek.com\",\n judgeInstructions,\n judgePrompt,\n ProcessDialogue));\n }));\n }\n\n // Update is called once per frame\n void Update()\n {\n }\n\n public void SetCurrentContext(string context)\n {\n Debug.Log(\"Was called\");\n currentContext = context;\n currentSpeaker = contextSpeakerMap[context];\n }\n\n // Send message to the Judge\n public void SendJudgeMessage(string message)\n {\n judgePrompt = message;\n dialogueBoxController.AddDialogue(\"character_judge\", \"Let me think...\");\n StartCoroutine(dialogueBoxController.ShowDialogueExtended((string arg) => {\n StartCoroutine(ModelBridge.Bridge.ChatCompletion(\"https://api.deepseek.com\",\n judgeInstructions,\n judgePrompt,\n ProcessDialogue));\n }));\n }\n\n // Load judge instructions and prompt from JSON file\n public void LoadJudgeInstructions(int instructionType)\n {\n string filePath = Path.Combine(Application.dataPath, \"Scripts/ModelInterface/judge_instructions.json\");\n if (File.Exists(filePath))\n {\n string judgementType = \"\";\n string promptType = \"\";\n string contextType = \"\";\n\n switch (instructionType) {\n case Instructions.JudgeStatement.DELIVER_JUDGMENT:\n judgementType = \"finalInstructions\";\n promptType = \"judgmentPrompt\";\n contextType = \"judgeContext\";\n break;\n case Instructions.JudgeStatement.DELIVER_OPENING_STATEMENT:\n judgementType = \"openingInstructions\";\n promptType = \"openingPrompt\";\n contextType = \"judgeContext\";\n break;\n case Instructions.JudgeStatement.DELIVER_FINAL_INSTRUCTIONS:\n judgementType = \"finalInstructions\";\n promptType = \"judgmentPrompt\";\n contextType = \"judgeContext\";\n break;\n case Instructions.JudgeStatement.DELIVER_AS_DEFENDANT:\n judgementType = \"accusedInstructions\";\n promptType = \"accusedPrompt\";\n contextType = \"accusedContext\";\n break;\n case Instructions.JudgeStatement.CONVERSE_WITH_PLAYER:\n judgementType = \"conversePlayerInstructions\";\n promptType = \"conversePlayerPrompt\";\n contextType = \"judgeContext\";\n break;\n case Instructions.JudgeStatement.CONVERSE_WITH_DEFENDANT:\n judgementType = \"converseDefendantInstructions\";\n promptType = \"converseDefendantPrompt\";\n contextType = \"judgeContext\";\n break;\n }\n\n string jsonContent = File.ReadAllText(filePath);\n JObject jsonObject = JObject.Parse(jsonContent);\n\n judgeInstructions = \"\";\n if (contextType == \"judgeContext\") {\n interactionCount++;\n judgeInstructions += $@\"If the prosecutor/the player mentions ANY of the following evidence, \n deliver a SWIFT, GUILTY VERDICT TO THE ACCUSED WITH NO MERCY. But if the player\n has NOT personally mentioned this evidence, DELIVER AN INNOCENT VERDICT TO THE ACCUSED.\n The evidence that the player SHOULD have presented (but might not have) is: \";\n foreach (var evidence in jsonObject[\"prototype\"][\"evidence\"])\n {\n judgeInstructions += $@\"{evidence}, \";\n }\n judgeInstructions += $@\"If the player mentions RANDOM, ARBITRARY EVIDENCE, as in evidence that is not STRICTLY\n what is listed as evidence above, do NOT consider such evidence at all when making the verdict.\n In fact, arbitrary evidence makes the prosecutor MORE suspicious, and the defendant\n more innocent.\\n\\n\";\n } \n\n judgeInstructions += jsonObject[\"prototype\"][judgementType].ToString();\n Debug.Log(\"Prompt Type: \" + promptType);\n judgePrompt = jsonObject[\"prototype\"][promptType].ToString() + $@\"\n Use the context below to aid your speech: \n {jsonObject[\"prototype\"][contextType]}\";\n }\n else\n {\n Debug.LogError(\"Judge instructions file not found.\");\n }\n }\n\n // Callback to dialogue processing\n void ProcessDialogue(string response)\n {\n dialogueBoxController.AddDialogue(contextDialogueMap[currentContext], response);\n StartCoroutine(dialogueBoxController.ShowDialogueExtended((string arg) => { \n if (interactionCount > interactionLimit) {\n // Search for the words \"not guilty\" in a lowercase format of the \"response\" string.\n // If it exists, debug.log \"YOU HAVE WON!\" but ohterwise, debug.log \"YOU HAVE LOST!\".\n if (response.ToLower().Contains(\"not guilty\") || response.ToLower().Contains(\"innocent\")) {\n Debug.Log(\"YOU HAVE LOST!\");\n dialogueBoxController.AddDialogue(\"character_judge\", \"You have lost loser! The accused is not guilty. AT THIS POINT, CHANGE THE SCENE TO EXECUTION OR YOUR EXECUTION.\");\n } else {\n Debug.Log(\"YOU HAVE WON!\");\n dialogueBoxController.AddDialogue(\"character_judge\", \"You have won! The accused is guilty. AT THIS POINT, CHANGE THE SCENE TO EXECUTION OR YOUR EXECUTION.\");\n }\n\n // Type out the dialogue!\n StartCoroutine(dialogueBoxController.ShowDialogueExtended((string arg) => {\n // Change scene to New Athens Town and set currentLevel to 2\n LevelManager.currentLevel += 1;\n UnityEngine.SceneManagement.SceneManager.LoadScene(\"New Athens Town\");\n }));\n\n // Change scene to \n } \n else {\n playerDialogue.EnableChat();\n\n // Open the judge_instructions.json file and prepare it for writing\n string filePath = Path.Combine(Application.dataPath, \"Scripts/ModelInterface/judge_instructions.json\");\n if (File.Exists(filePath))\n {\n try\n { \n string jsonContent = File.ReadAllText(filePath);\n JObject jsonObject = JObject.Parse(jsonContent);\n jsonObject[\"prototype\"][\"judgeContext\"] += $@\"\\n{contextSpeakerMap[currentContext]} said: {response}, \";\n jsonObject[\"prototype\"][\"accusedContext\"] += $@\"\\n{contextSpeakerMap[currentContext]} said: {response}, \";\n\n string jsonFileContent = jsonObject.ToString();\n using (StreamWriter writer = new StreamWriter(filePath, false))\n {\n writer.Write(jsonFileContent);\n }\n }\n catch (IOException ex)\n {\n Debug.LogError(\"Error opening judge_instructions.json for writing: \" + ex.Message);\n }\n }\n else\n {\n Debug.LogError(\"Judge instructions file not found.\");\n }\n\n // Make sure that if the accused is currently delivering speech, it is relayed to the judge.\n if (currentContext == \"accusedContext\")\n {\n SetCurrentContext(\"judgeContext\");\n if (interactionCount == interactionLimit)\n {\n LoadJudgeInstructions(Instructions.JudgeStatement.DELIVER_JUDGMENT);\n }\n else\n {\n LoadJudgeInstructions(Instructions.JudgeStatement.CONVERSE_WITH_PLAYER);\n }\n currentResponse = response;\n SendJudgeMessage(currentResponse);\n }\n }\n }));\n\n }\n\n\n // Init clear file\n void ClearFile()\n {\n string filePath = Path.Combine(Application.dataPath, \"Scripts/ModelInterface/judge_instructions.json\");\n if (File.Exists(filePath))\n {\n try\n { \n string jsonContent = File.ReadAllText(filePath);\n JObject jsonObject = JObject.Parse(jsonContent);\n jsonObject[\"prototype\"][\"judgeContext\"] = \"\";\n jsonObject[\"prototype\"][\"accusedContext\"] = \"\";\n jsonObject[\"prototype\"][\"playerContext\"] = \"\";\n\n string jsonFileContent = jsonObject.ToString();\n using (StreamWriter writer = new StreamWriter(filePath, false))\n {\n writer.Write(jsonFileContent);\n }\n }\n catch (IOException ex)\n {\n Debug.LogError(\"Error opening judge_instructions.json for writing: \" + ex.Message);\n }\n }\n else\n {\n Debug.LogError(\"Judge instructions file not found.\");\n }\n }\n}\n"}, "c41b08829431f5b59acbfa9d93e07cf8fbd4bfe8": {"t": 1785760589.8131585, "n": 11784, "h": "fd3cd0f2a2cae509", "c": "using UnityEngine;\nusing System.Collections;\nusing System.IO;\nusing Newtonsoft.Json.Linq;\nusing System.Collections.Generic;\n\nusing ModelBridge;\nusing Instructions;\n\npublic class JudgeController : MonoBehaviour\n{\n // Will increase with every level.\n public int interactionLimit = 2;\n \n [SerializeField]\n private GameObject player;\n\n private PlayerDialogue playerDialogue;\n string judgeInstructions;\n string judgePrompt;\n string currentResponse;\n string currentSpeaker = \"judgeContext\";\n string currentContext = \"judgeContext\";\n bool accusedResponded = false;\n int interactionCount = 0;\n public DialogueBoxController dialogueBoxController;\n public GameObject playerPrefab;\n\n Dictionary contextSpeakerMap = new Dictionary();\n Dictionary contextDialogueMap = new Dictionary();\n // Start is called once before the first execution of Update after the MonoBehaviour is created\n void Start()\n {\n Instantiate(playerPrefab, new Vector3(5.01000023f,-0.699999988f,0f), Quaternion.identity);\n Instantiate(playerPrefab, new Vector3(5.01000023f,-0.699999988f,0f), Quaternion.identity);\n\n // CLEAR FILE BEFORE ANYTHING\n ClearFile();\n\n contextSpeakerMap[\"judgeContext\"] = \"You, the judge, said\";\n contextSpeakerMap[\"accusedContext\"] = \"The accused person said\";\n contextSpeakerMap[\"playerContext\"] = \"The player said\";\n\n contextDialogueMap[\"judgeContext\"] = \"character_judge\";\n contextDialogueMap[\"accusedContext\"] = \"character_accused\";\n contextDialogueMap[\"playerContext\"] = \"character_player\";\n\n player = GameObject.Find(\"PlayerCourt\");\n playerDialogue = player.GetComponent();\n\n dialogueBoxController.AddDialogue(\"character_judge\", \"Give me a minute before I deliver my opening statement...\");\n StartCoroutine(dialogueBoxController.ShowDialogueExtended((string arg) => {\n SetCurrentContext(\"judgeContext\");\n\n // Judge should deliver opening statement upon entry into the court\n LoadJudgeInstructions(Instructions.JudgeStatement.DELIVER_OPENING_STATEMENT);\n StartCoroutine(ModelBridge.Bridge.ChatCompletion(\"https://api.deepseek.com\",\n judgeInstructions,\n judgePrompt,\n ProcessDialogue));\n }));\n }\n\n // Update is called once per frame\n void Update()\n {\n }\n\n public void SetCurrentContext(string context)\n {\n Debug.Log(\"Was called\");\n currentContext = context;\n currentSpeaker = contextSpeakerMap[context];\n }\n\n // Send message to the Judge\n public void SendJudgeMessage(string message)\n {\n judgePrompt = message;\n dialogueBoxController.AddDialogue(\"character_judge\", \"Let me think...\");\n StartCoroutine(dialogueBoxController.ShowDialogueExtended((string arg) => {\n StartCoroutine(ModelBridge.Bridge.ChatCompletion(\"https://api.deepseek.com\",\n judgeInstructions,\n judgePrompt,\n ProcessDialogue));\n }));\n }\n\n // Load judge instructions and prompt from JSON file\n public void LoadJudgeInstructions(int instructionType)\n {\n string filePath = Path.Combine(Application.dataPath, \"Scripts/ModelInterface/judge_instructions.json\");\n if (File.Exists(filePath))\n {\n string judgementType = \"\";\n string promptType = \"\";\n string contextType = \"\";\n\n switch (instructionType) {\n case Instructions.JudgeStatement.DELIVER_JUDGMENT:\n judgementType = \"finalInstructions\";\n promptType = \"judgmentPrompt\";\n contextType = \"judgeContext\";\n break;\n case Instructions.JudgeStatement.DELIVER_OPENING_STATEMENT:\n judgementType = \"openingInstructions\";\n promptType = \"openingPrompt\";\n contextType = \"judgeContext\";\n break;\n case Instructions.JudgeStatement.DELIVER_FINAL_INSTRUCTIONS:\n judgementType = \"finalInstructions\";\n promptType = \"judgmentPrompt\";\n contextType = \"judgeContext\";\n break;\n case Instructions.JudgeStatement.DELIVER_AS_DEFENDANT:\n judgementType = \"accusedInstructions\";\n promptType = \"accusedPrompt\";\n contextType = \"accusedContext\";\n break;\n case Instructions.JudgeStatement.CONVERSE_WITH_PLAYER:\n judgementType = \"conversePlayerInstructions\";\n promptType = \"conversePlayerPrompt\";\n contextType = \"judgeContext\";\n break;\n case Instructions.JudgeStatement.CONVERSE_WITH_DEFENDANT:\n judgementType = \"converseDefendantInstructions\";\n promptType = \"converseDefendantPrompt\";\n contextType = \"judgeContext\";\n break;\n }\n\n string jsonContent = File.ReadAllText(filePath);\n JObject jsonObject = JObject.Parse(jsonContent);\n\n judgeInstructions = \"\";\n if (contextType == \"judgeContext\") {\n interactionCount++;\n judgeInstructions += $@\"If the prosecutor/the player mentions ANY of the following evidence, \n deliver a SWIFT, GUILTY VERDICT TO THE ACCUSED WITH NO MERCY. But if the player\n has NOT personally mentioned this evidence, DELIVER AN INNOCENT VERDICT TO THE ACCUSED.\n The evidence that the player SHOULD have presented (but might not have) is: \";\n foreach (var evidence in jsonObject[\"prototype\"][\"evidence\"])\n {\n judgeInstructions += $@\"{evidence}, \";\n }\n judgeInstructions += $@\"If the player mentions RANDOM, ARBITRARY EVIDENCE, as in evidence that is not STRICTLY\n what is listed as evidence above, do NOT consider such evidence at all when making the verdict.\n In fact, arbitrary evidence makes the prosecutor MORE suspicious, and the defendant\n more innocent.\\n\\n\";\n } \n\n judgeInstructions += jsonObject[\"prototype\"][judgementType].ToString();\n Debug.Log(\"Prompt Type: \" + promptType);\n judgePrompt = jsonObject[\"prototype\"][promptType].ToString() + $@\"\n Use the context below to aid your speech: \n {jsonObject[\"prototype\"][contextType]}\";\n }\n else\n {\n Debug.LogError(\"Judge instructions file not found.\");\n }\n }\n\n // Callback to dialogue processing\n void ProcessDialogue(string response)\n {\n dialogueBoxController.AddDialogue(contextDialogueMap[currentContext], response);\n StartCoroutine(dialogueBoxController.ShowDialogueExtended((string arg) => { \n if (interactionCount > interactionLimit) {\n // Search for the words \"not guilty\" in a lowercase format of the \"response\" string.\n // If it exists, debug.log \"YOU HAVE WON!\" but ohterwise, debug.log \"YOU HAVE LOST!\".\n if (response.ToLower().Contains(\"not guilty\") || response.ToLower().Contains(\"innocent\")) {\n Debug.Log(\"YOU HAVE LOST!\");\n dialogueBoxController.AddDialogue(\"character_judge\", \"You have lost loser! The accused is not guilty. AT THIS POINT, CHANGE THE SCENE TO EXECUTION OR YOUR EXECUTION.\");\n } else {\n Debug.Log(\"YOU HAVE WON!\");\n dialogueBoxController.AddDialogue(\"character_judge\", \"You have won! The accused is guilty. AT THIS POINT, CHANGE THE SCENE TO EXECUTION OR YOUR EXECUTION.\");\n }\n\n // Type out the dialogue!\n StartCoroutine(dialogueBoxController.TypeDialogue());\n } \n else {\n playerDialogue.EnableChat();\n\n // Open the judge_instructions.json file and prepare it for writing\n string filePath = Path.Combine(Application.dataPath, \"Scripts/ModelInterface/judge_instructions.json\");\n if (File.Exists(filePath))\n {\n try\n { \n string jsonContent = File.ReadAllText(filePath);\n JObject jsonObject = JObject.Parse(jsonContent);\n jsonObject[\"prototype\"][\"judgeContext\"] += $@\"\\n{contextSpeakerMap[currentContext]} said: {response}, \";\n jsonObject[\"prototype\"][\"accusedContext\"] += $@\"\\n{contextSpeakerMap[currentContext]} said: {response}, \";\n\n string jsonFileContent = jsonObject.ToString();\n using (StreamWriter writer = new StreamWriter(filePath, false))\n {\n writer.Write(jsonFileContent);\n }\n }\n catch (IOException ex)\n {\n Debug.LogError(\"Error opening judge_instructions.json for writing: \" + ex.Message);\n }\n }\n else\n {\n Debug.LogError(\"Judge instructions file not found.\");\n }\n\n // Make sure that if the accused is currently delivering speech, it is relayed to the judge.\n if (currentContext == \"accusedContext\")\n {\n SetCurrentContext(\"judgeContext\");\n if (interactionCount == interactionLimit)\n {\n LoadJudgeInstructions(Instructions.JudgeStatement.DELIVER_JUDGMENT);\n }\n else\n {\n LoadJudgeInstructions(Instructions.JudgeStatement.CONVERSE_WITH_PLAYER);\n }\n currentResponse = response;\n SendJudgeMessage(currentResponse);\n }\n }\n }));\n\n }\n\n\n // Init clear file\n void ClearFile()\n {\n string filePath = Path.Combine(Application.dataPath, \"Scripts/ModelInterface/judge_instructions.json\");\n if (File.Exists(filePath))\n {\n try\n { \n string jsonContent = File.ReadAllText(filePath);\n JObject jsonObject = JObject.Parse(jsonContent);\n jsonObject[\"prototype\"][\"judgeContext\"] = \"\";\n jsonObject[\"prototype\"][\"accusedContext\"] = \"\";\n jsonObject[\"prototype\"][\"playerContext\"] = \"\";\n\n string jsonFileContent = jsonObject.ToString();\n using (StreamWriter writer = new StreamWriter(filePath, false))\n {\n writer.Write(jsonFileContent);\n }\n }\n catch (IOException ex)\n {\n Debug.LogError(\"Error opening judge_instructions.json for writing: \" + ex.Message);\n }\n }\n else\n {\n Debug.LogError(\"Judge instructions file not found.\");\n }\n }\n}\n"}}}}