Adjusted the personality algorithm
- Use traits enum in example instead of strings - Moved traits enum to separate file - Asked AI for some documentation comments
This commit is contained in:
parent
3d6a9d0bbf
commit
f6ef83fd91
3 changed files with 61 additions and 36 deletions
12
Program.cs
12
Program.cs
|
@ -1,14 +1,14 @@
|
|||
using SimsPersonalityGenerator;
|
||||
|
||||
var character = new Sim();
|
||||
var sim = new Sim();
|
||||
Console.WriteLine("Generated Personality:");
|
||||
Console.WriteLine(character);
|
||||
Console.WriteLine(sim);
|
||||
|
||||
// Example of setting one trait higher and compensating for the differences
|
||||
Console.WriteLine("\nSetting Niceness higher...");
|
||||
character.SetTraitHigher("niceness", true);
|
||||
Console.WriteLine(character);
|
||||
sim.SetTraitHigher(Traits.Nice, true);
|
||||
Console.WriteLine(sim);
|
||||
|
||||
Console.WriteLine("\nSetting Neatness lower...");
|
||||
character.SetTraitHigher("neatness", false);
|
||||
Console.WriteLine(character);
|
||||
sim.SetTraitHigher(Traits.Neat, false);
|
||||
Console.WriteLine(sim);
|
82
Sim.cs
82
Sim.cs
|
@ -1,22 +1,29 @@
|
|||
namespace SimsPersonalityGenerator;
|
||||
|
||||
public enum Traits { Nice, Neat, Outgoing, Active, Playful }
|
||||
using System.Text.Json;
|
||||
|
||||
public class Sim
|
||||
{
|
||||
|
||||
public int Niceness { get; private set; }
|
||||
public int Neatness { get; private set; }
|
||||
public int Outgoingness { get; private set; }
|
||||
public int Activeness { get; private set; }
|
||||
public int Laziness { get; private set; }
|
||||
public int Playfulness { get; private set; }
|
||||
public int Nice { get; private set; }
|
||||
public int Neat { get; private set; }
|
||||
public int Outgoing { get; private set; }
|
||||
public int Active { get; private set; }
|
||||
public int Playful { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the Sim class with a random personality.
|
||||
/// </summary>
|
||||
public Sim()
|
||||
{
|
||||
GenerateRandomPersonality();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets one personality trait higher or lower and compensates by adjusting another trait.
|
||||
/// </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)
|
||||
{
|
||||
|
@ -24,67 +31,82 @@ public class Sim
|
|||
{
|
||||
case Traits.Nice:
|
||||
if (isHigh)
|
||||
Niceness = Math.Min(10, Neatness + 5);
|
||||
Nice = Math.Min(8, Neat + 5);
|
||||
else
|
||||
Neatness = Math.Min(10, Niceness + 5);
|
||||
Neat = Math.Min(8, Nice + 5);
|
||||
break;
|
||||
case Traits.Neat:
|
||||
if (isHigh)
|
||||
Neatness = Math.Min(10, Activeness + 5);
|
||||
Neat = Math.Min(8, Active + 5);
|
||||
else
|
||||
Activeness = Math.Min(10, Neatness + 5);
|
||||
Active = Math.Min(8, Neat + 5);
|
||||
break;
|
||||
case Traits.Outgoing:
|
||||
if (isHigh)
|
||||
Outgoingness = Math.Min(10, Playfulness + 5);
|
||||
Outgoing = Math.Min(8, Playful + 5);
|
||||
else
|
||||
Playfulness = Math.Min(10, Outgoingness + 5);
|
||||
Playful = Math.Min(8, Outgoing + 5);
|
||||
break;
|
||||
case Traits.Active:
|
||||
if (isHigh)
|
||||
Activeness = Math.Min(10, Niceness + 5);
|
||||
Active = Math.Min(8, Nice + 5);
|
||||
else
|
||||
Niceness = Math.Min(10, Activeness + 5);
|
||||
Nice = Math.Min(8, Active + 5);
|
||||
break;
|
||||
case Traits.Playful:
|
||||
if (isHigh)
|
||||
Playfulness = Math.Min(10, Outgoingness + 5);
|
||||
Playful = Math.Min(8, Outgoing + 5);
|
||||
else
|
||||
Outgoingness = Math.Min(10, Playfulness + 5);
|
||||
Outgoing = Math.Min(8, Playful + 5);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("Invalid trait name.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a random personality with balanced traits.
|
||||
/// </summary>
|
||||
private void GenerateRandomPersonality()
|
||||
{
|
||||
Random rand = new Random();
|
||||
Niceness = rand.Next(11);
|
||||
Neatness = rand.Next(11);
|
||||
Outgoingness = rand.Next(11);
|
||||
Activeness = rand.Next(11);
|
||||
Playfulness = rand.Next(11);
|
||||
Nice = rand.Next(11);
|
||||
Neat = rand.Next(11);
|
||||
Outgoing = rand.Next(11);
|
||||
Active = rand.Next(11);
|
||||
Playful = rand.Next(11);
|
||||
|
||||
// Ensure that the sum of traits is balanced
|
||||
int totalSum = Niceness + Neatness + Outgoingness + Activeness + Playfulness;
|
||||
int totalSum = Nice + Neat + Outgoing + Active + Playful;
|
||||
if (totalSum > 50)
|
||||
{
|
||||
int overage = totalSum - 50;
|
||||
int average = totalSum - 50;
|
||||
int traitToReduce = rand.Next(5);
|
||||
switch (traitToReduce)
|
||||
{
|
||||
case 0: Niceness -= Math.Min(Niceness, overage); break;
|
||||
case 1: Neatness -= Math.Min(Neatness, overage); break;
|
||||
case 2: Outgoingness -= Math.Min(Outgoingness, overage); break;
|
||||
case 3: Activeness -= Math.Min(Activeness, overage); break;
|
||||
case 4: Playfulness -= Math.Min(Playfulness, overage); break;
|
||||
case 0: Nice -= Math.Min(Nice, average); break;
|
||||
case 1: Neat -= Math.Min(Neat, average); break;
|
||||
case 2: Outgoing -= Math.Min(Outgoing, average); break;
|
||||
case 3: Active -= Math.Min(Active, average); break;
|
||||
case 4: Playful -= Math.Min(Playful, average); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a JSON representation of the character's personality traits.
|
||||
/// </summary>
|
||||
/// <returns>A JSON containing the values of all personality traits.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Niceness: {Niceness}, Neatness: {Neatness}, Outgoingness: {Outgoingness}, Activeness: {Activeness}, Playfulness: {Playfulness}";
|
||||
var sim = new Sim();
|
||||
{
|
||||
Nice = Nice;
|
||||
Neat = Neat;
|
||||
Outgoing = Outgoing;
|
||||
Playful = Playful;
|
||||
Active = Active;
|
||||
};
|
||||
return JsonSerializer.Serialize<Sim>(sim);
|
||||
}
|
||||
}
|
||||
|
|
3
Traits.cs
Normal file
3
Traits.cs
Normal file
|
@ -0,0 +1,3 @@
|
|||
namespace SimsPersonalityGenerator;
|
||||
|
||||
public enum Traits { Nice, Neat, Outgoing, Active, Playful }
|
Loading…
Add table
Reference in a new issue