Renamed SetTraitHigher to RebalanceTraits

- Rebalance method now accounts for high and low personality points are
This commit is contained in:
Tony Bark 2025-02-02 04:09:53 -05:00
parent f6ef83fd91
commit 85ce1f4023
3 changed files with 32 additions and 27 deletions

View file

@ -1,14 +1,11 @@
using SimsPersonalityGenerator;
var sim = new Sim();
Console.WriteLine("Generated Personality:");
Console.WriteLine(sim);
// Example of setting one trait higher and compensating for the differences
Console.WriteLine("\nSetting Niceness higher...");
sim.SetTraitHigher(Traits.Nice, true);
Console.WriteLine(sim);
Console.WriteLine("\nSetting Neatness lower...");
sim.SetTraitHigher(Traits.Neat, false);
Console.WriteLine("\nSetting niceness higher...");
sim.RebalanceTraits(Traits.Nice, true);
Console.WriteLine(sim);

View file

@ -1,12 +1,12 @@
# Sims Personality Generator
As the name suggests, this will generate a personality for The Sims 1 and 2. If you set one trait higher than other, it will automatically adjust itself to compensate for the difference.
As the name suggests, this will generate a personality for The Sims 1 and 2. If you choose to have a bias towards one trait being higher over the others, it will automatically compensate for the difference. It is recommended to only set a bias towards one trait at a time.
## Background
I wanted to play The Sims 2 with my characters. Problem was I've been spoiled by traits. How do I create an ideal personality within these limitations? What if I have a random generator that gives me some options but also is smart enough to let me set some bias towards Playfulness or Nice?
The code itself was initially generated using the Qwen Coder model because I wouldn't know to begin. While it is easy to generate random numbers, I also had to have it to account for one being higher than the other. How? That was the point in asking the AI for a template, with that taken into consideration.
The code itself was initially generated using the [Qwen Coder](https://qwenlm.github.io/blog/qwen2.5-coder-family/) model because I wouldn't know to begin. While it is easy to generate random numbers, I also had to have it to account for one being higher than the other. How? That was the point in asking the AI for a template, with that taken into consideration.
## License

46
Sim.cs
View file

@ -11,6 +11,9 @@ public class Sim
public int Active { get; private set; }
public int Playful { get; private set; }
const int MIN_HIGHEST_POINT = 8;
const int MAX_LOWEST_POINT = 5;
/// <summary>
/// Initializes a new instance of the Sim class with a random personality.
/// </summary>
@ -24,40 +27,39 @@ public class Sim
/// </summary>
/// <param name="trait">The name of the trait to adjust.</param>
/// <param name="isHigh">True if the trait should be set higher, false if it should be set lower.</param>
// TODO: Fix trait mix up
public void SetTraitHigher(Traits trait, bool isHigh)
public void RebalanceTraits(Traits trait, bool isHigh = false)
{
switch (trait)
{
case Traits.Nice:
if (isHigh)
Nice = Math.Min(8, Neat + 5);
if (isHigh && Nice >= MAX_LOWEST_POINT)
Nice = Math.Min(MIN_HIGHEST_POINT, Neat + 5);
else
Neat = Math.Min(8, Nice + 5);
Neat = Math.Min(MIN_HIGHEST_POINT, Nice + 5);
break;
case Traits.Neat:
if (isHigh)
Neat = Math.Min(8, Active + 5);
if (isHigh && Neat >= MAX_LOWEST_POINT)
Neat = Math.Min(MIN_HIGHEST_POINT, Active + 5);
else
Active = Math.Min(8, Neat + 5);
Active = Math.Min(MIN_HIGHEST_POINT, Neat + 5);
break;
case Traits.Outgoing:
if (isHigh)
Outgoing = Math.Min(8, Playful + 5);
if (isHigh && Outgoing >= MAX_LOWEST_POINT)
Outgoing = Math.Min(MIN_HIGHEST_POINT, Playful + 5);
else
Playful = Math.Min(8, Outgoing + 5);
Playful = Math.Min(MIN_HIGHEST_POINT, Outgoing + 5);
break;
case Traits.Active:
if (isHigh)
Active = Math.Min(8, Nice + 5);
if (isHigh && Active >= MAX_LOWEST_POINT)
Active = Math.Min(MIN_HIGHEST_POINT, Nice + 5);
else
Nice = Math.Min(8, Active + 5);
Nice = Math.Min(MIN_HIGHEST_POINT, Active + 5);
break;
case Traits.Playful:
if (isHigh)
Playful = Math.Min(8, Outgoing + 5);
if (isHigh && Playful >= MAX_LOWEST_POINT)
Playful = Math.Min(MIN_HIGHEST_POINT, Outgoing + 5);
else
Outgoing = Math.Min(8, Playful + 5);
Outgoing = Math.Min(MIN_HIGHEST_POINT, Playful + 5);
break;
default:
throw new ArgumentException("Invalid trait name.");
@ -67,7 +69,7 @@ public class Sim
/// <summary>
/// Generates a random personality with balanced traits.
/// </summary>
private void GenerateRandomPersonality()
public void GenerateRandomPersonality()
{
Random rand = new Random();
Nice = rand.Next(11);
@ -107,6 +109,12 @@ public class Sim
Playful = Playful;
Active = Active;
};
return JsonSerializer.Serialize<Sim>(sim);
var options = new JsonSerializerOptions()
{
WriteIndented = true,
};
return JsonSerializer.Serialize<Sim>(sim, options);
}
}