![]() |
VOOZH | about |
We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.
Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.
Follow TNS on your favorite social media networks.
Become a TNS follower on LinkedIn.
Check out the latest featured and trending stories while you wait for your first TNS newsletter.
User tim = new ("12345","Timbo");
User jim = new ("45123","Jimbo");
User kim = new ("6534", "Kimbo");
TopScore ts = new TopScore();
ts.AddScore(Score.RegisteredGame.MatterBlatter, tim, 1000, "Level 3");
ts.AddScore(Score.RegisteredGame.MatterBlatter, tim, 1200, "Level 4");
ts.AddScore(Score.RegisteredGame.MasterBlaster, jim, 1000, "HellGate");
ts.AddScore(Score.RegisteredGame.MasterBlaster, tim, 1200, "FinalBoss");
ts.AddScore(Score.RegisteredGame.MatterBlatter, kim, 1000, "Level 3");
ts.AddScore(Score.RegisteredGame.MatterBlatter, kim, 3200, "Level 5");
ts.PurgeUser(kim);
List<string> topscores = ts.FormattedTopScoreTable(Score.RegisteredGame.MatterBlatter);
Console.WriteLine($"TOP SCORES FOR {Score.RegisteredGame.MatterBlatter}");
topscores.ForEach(sc => Console.WriteLine(sc));
public struct User {
public string PlayerId;
public string KnownAs;
public User(string playerId, string knownAs) {
PlayerId = playerId;
KnownAs = knownAs;
}
}
public class Score : IComparable<Score> {
public enum RegisteredGame { MatterBlatter, MasterBlaster, MinionPinion}
public DateTime Entrydate;
public int ScoreValue; public string Level = "";
public RegisteredGame Game;
public User Player;
public int CompareTo(Sco re? other) {
return (other.ScoreValue - ScoreValue);
}
public Score(RegisteredGame registeredGame, User player, int scoreValue, string level = "") {
Game = registeredGame;
Entrydate = DateTime.Now;
ScoreValue = scoreValue;
Level = level;
Player = player;
}
}
public class TopScore {
private List<Score> scores = new List<Score>();
const short TABLESIZE = 10;
public void AddScore(Score.RegisteredGame registeredGame, User user, int scorevalue, string level) {
Score score = new (registeredGame, user, scorevalue, level);
scores.Add(score);
}
public void PurgeUser(User user) {
scores.RemoveAll(score => score.Player.PlayerId == user.PlayerId);
}
public List<string> FormattedTopScoreTable(Score.RegisteredGame registeredGame) {
List<string> toptable = new List<string>(); //First sort it
List<Score> justOnegame = scores.FindAll(sc => sc.Game == registeredGame);
justOnegame.Sort(); //Grab subset
List<Score> topItems = (justOnegame.Count < TABLESIZE)?justOnegame:(List<Score>)justOnegame.Take(TABLESIZE);
topItems.ForEach(sc => toptable.Add($"{sc.ScoreValue} {sc.Player.KnownAs} ({sc.Level})"));
return toptable;
}
}
[
{
"game": "MatterBlatter",
"player": "tim",
"score": 1000,
"level": "Level 3"
}, {
"game": "MatterBlatter",
"player": "tim",
"score": 1200,
"level": "Level 4"
}, {
"game": "MasterBlaster",
"player": "jim",
"score": 1000,
"level": "HellGate"
}, {
"game": "MasterBlaster",
"player": "tim",
"score": 1200,
"level": "FinalBoss"
}, {
"game": "MatterBlatter",
"player": "kim",
"score": 1000,
"level": "Level 3"
}, {
"game": "MatterBlatter",
"player": "kim",
"score": 3200,
"level":
"Level 5"
}
]
PlayerId, which will cause a problem later.)
My next step will be to ask for the appropriate code to read from the scores.json file and convert to arguments for the TopScore object. I used the new “slash” command /file to add the new scores file that I just made with the JSON into the Assistant for context. Think of this as extra RAG-like additions:
👁 ImageScoreEntry class to the main code that the LLM created in the Assistant to the right:
👁 Image/tab, which just adds the whole open file as context.
I had difficulty asking the inline assistant to replace the redundant code with the new code. It was loathe to delete old code — which may be a good thing!
After adding a few more scores from Jim for flavor, we get a nice ranked table:
👁 Imageusing System.Text.Json;
User tim = new ("12345","Timbo");
User jim = new ("45123","Jimbo");
User kim = new ("6534", "Kimbo");
TopScore ts = new TopScore();
string jsonString = File.ReadAllText("scores.json");
List<ScoreEntry> scoreEntries = JsonSerializer.Deserialize<List<ScoreEntry>>(jsonString);
foreach (var entry in scoreEntries) {
ts.AddScore(
Enum.Parse<Score.RegisteredGame>(entry.game),
User.FindByPlayerId(entry.player),
entry.score,
entry.level
);
}
ts.PurgeUser(kim);
List<string> topscores = ts.FormattedTopScoreTable(Score.RegisteredGame.MatterBlatter);
Console.WriteLine($"TOP SCORES FOR {Score.RegisteredGame.MatterBlatter}");
topscores.ForEach(sc => Console.WriteLine(sc));
public struct User {
public string PlayerId;
public string KnownAs;
private static List<User> registeredUsers = new ();
public User(string playerId, string knownAs) {
PlayerId = playerId;
KnownAs = knownAs;
registeredUsers.Add(this);
}
public static User FindByPlayerId(string id) {
return registeredUsers.FirstOrDefault(u => u.PlayerId == id);
}
}
public class ScoreEntry {
public string game { get; set; }
public string player { get; set; }
public int score { get; set; }
public string level { get; set; }
}
public class Score : IComparable<Score> {
public enum RegisteredGame { MatterBlatter, MasterBlaster, MinionPinion}
public DateTime Entrydate;
public int ScoreValue;
public string Level = "";
public RegisteredGame Game;
public User Player;
public int CompareTo(Score? other) {
return (other.ScoreValue - ScoreValue);
}
public Score(RegisteredGame registeredGame, User player, int scoreValue, string level = "")
{
Game = registeredGame;
Entrydate = DateTime.Now;
ScoreValue = scoreValue;
Level = level;
Player = player;
}
}
public class TopScore {
private List<Score> scores = new List<Score>();
const short TABLESIZE = 10;
public void AddScore(Score.RegisteredGame registeredGame, User user, int scorevalue, string level) {
Score score = new (registeredGame, user, scorevalue, level);
scores.Add(score);
}
public void PurgeUser(User user) {
scores.RemoveAll(score => score.Player.PlayerId == user.PlayerId);
}
public List<string> FormattedTopScoreTable(Score.RegisteredGame registeredGame) {
List<string> toptable = new List<string>(); //First sort it
List<Score> justOnegame = scores.FindAll(sc => sc.Game == registeredGame);
justOnegame.Sort(); //Grab subset
List<Score> topItems = (justOnegame.Count < TABLESIZE)?justOnegame:(List<Score>)justOnegame.Take(TABLESIZE);
for (int i = 0; i < topItems.Count; i++) {
Score sc = topItems[i];
int rank = i + 1;
toptable.Add($"{rank,2}. {sc.ScoreValue,8} {sc.Player.KnownAs,-10} ({sc.Level})");
}
return toptable;
}
}