-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
created echo agent and quantize character functions
- Loading branch information
Showing
5 changed files
with
209 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using Unity.MLAgents; | ||
using Unity.MLAgents.Sensors; | ||
using Unity.MLAgents.Actuators; | ||
using System.Collections.Generic; | ||
using CommandTerminal; | ||
|
||
namespace DialogosEngine | ||
{ | ||
public class EchoAgent : Agent | ||
{ | ||
char _GuessedChar; | ||
|
||
public override void OnEpisodeBegin() | ||
{ | ||
ClearConsole(); | ||
} | ||
|
||
public void FixedUpdate() | ||
{ | ||
char expectedChar = GetExpectedChar(); | ||
float reward = CalculateReward(expectedChar, _GuessedChar); | ||
SetReward(reward); | ||
} | ||
|
||
public override void CollectObservations(VectorSensor sensor) | ||
{ | ||
string buffer = GetConsoleBuffer(); | ||
float[] vectorizedBuffer = Lexer.VectorizeUTF8(buffer); | ||
foreach (var obs in vectorizedBuffer) | ||
{ | ||
sensor.AddObservation(obs); | ||
} | ||
} | ||
|
||
public override void OnActionReceived(ActionBuffers actions) | ||
{ | ||
float[] actionArray = new float[1] { actions.ContinuousActions[0] }; | ||
_GuessedChar = Lexer.QuantizeUTF8(actionArray)[0]; | ||
HandleGuessedCharacter(_GuessedChar); | ||
} | ||
|
||
private void ClearConsole() | ||
{ | ||
Terminal.Instance.Buffer.Reset(); | ||
} | ||
|
||
private float CalculateReward(char expectedChar, char guessedChar) | ||
{ | ||
// Implementation to calculate the reward based on the guessed character | ||
return 0; | ||
} | ||
|
||
private string GetConsoleBuffer() | ||
{ | ||
return Terminal.Instance.Buffer.GetLastLog(); | ||
} | ||
|
||
private void HandleGuessedCharacter(char guessedChar) | ||
{ | ||
// Implementation to handle the guessed character | ||
} | ||
|
||
private char GetExpectedChar() | ||
{ | ||
// Implementation to get the expected character for the current step | ||
return new char(); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters