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;
|
using SimsPersonalityGenerator;
|
||||||
|
|
||||||
var character = new Sim();
|
var sim = new Sim();
|
||||||
Console.WriteLine("Generated Personality:");
|
Console.WriteLine("Generated Personality:");
|
||||||
Console.WriteLine(character);
|
Console.WriteLine(sim);
|
||||||
|
|
||||||
// Example of setting one trait higher and compensating for the differences
|
// Example of setting one trait higher and compensating for the differences
|
||||||
Console.WriteLine("\nSetting Niceness higher...");
|
Console.WriteLine("\nSetting Niceness higher...");
|
||||||
character.SetTraitHigher("niceness", true);
|
sim.SetTraitHigher(Traits.Nice, true);
|
||||||
Console.WriteLine(character);
|
Console.WriteLine(sim);
|
||||||
|
|
||||||
Console.WriteLine("\nSetting Neatness lower...");
|
Console.WriteLine("\nSetting Neatness lower...");
|
||||||
character.SetTraitHigher("neatness", false);
|
sim.SetTraitHigher(Traits.Neat, false);
|
||||||
Console.WriteLine(character);
|
Console.WriteLine(sim);
|
82
Sim.cs
82
Sim.cs
|
@ -1,22 +1,29 @@
|
||||||
namespace SimsPersonalityGenerator;
|
namespace SimsPersonalityGenerator;
|
||||||
|
|
||||||
public enum Traits { Nice, Neat, Outgoing, Active, Playful }
|
using System.Text.Json;
|
||||||
|
|
||||||
public class Sim
|
public class Sim
|
||||||
{
|
{
|
||||||
|
|
||||||
public int Niceness { get; private set; }
|
public int Nice { get; private set; }
|
||||||
public int Neatness { get; private set; }
|
public int Neat { get; private set; }
|
||||||
public int Outgoingness { get; private set; }
|
public int Outgoing { get; private set; }
|
||||||
public int Activeness { get; private set; }
|
public int Active { get; private set; }
|
||||||
public int Laziness { get; private set; }
|
public int Playful { get; private set; }
|
||||||
public int Playfulness { get; private set; }
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the Sim class with a random personality.
|
||||||
|
/// </summary>
|
||||||
public Sim()
|
public Sim()
|
||||||
{
|
{
|
||||||
GenerateRandomPersonality();
|
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
|
// TODO: Fix trait mix up
|
||||||
public void SetTraitHigher(Traits trait, bool isHigh)
|
public void SetTraitHigher(Traits trait, bool isHigh)
|
||||||
{
|
{
|
||||||
|
@ -24,67 +31,82 @@ public class Sim
|
||||||
{
|
{
|
||||||
case Traits.Nice:
|
case Traits.Nice:
|
||||||
if (isHigh)
|
if (isHigh)
|
||||||
Niceness = Math.Min(10, Neatness + 5);
|
Nice = Math.Min(8, Neat + 5);
|
||||||
else
|
else
|
||||||
Neatness = Math.Min(10, Niceness + 5);
|
Neat = Math.Min(8, Nice + 5);
|
||||||
break;
|
break;
|
||||||
case Traits.Neat:
|
case Traits.Neat:
|
||||||
if (isHigh)
|
if (isHigh)
|
||||||
Neatness = Math.Min(10, Activeness + 5);
|
Neat = Math.Min(8, Active + 5);
|
||||||
else
|
else
|
||||||
Activeness = Math.Min(10, Neatness + 5);
|
Active = Math.Min(8, Neat + 5);
|
||||||
break;
|
break;
|
||||||
case Traits.Outgoing:
|
case Traits.Outgoing:
|
||||||
if (isHigh)
|
if (isHigh)
|
||||||
Outgoingness = Math.Min(10, Playfulness + 5);
|
Outgoing = Math.Min(8, Playful + 5);
|
||||||
else
|
else
|
||||||
Playfulness = Math.Min(10, Outgoingness + 5);
|
Playful = Math.Min(8, Outgoing + 5);
|
||||||
break;
|
break;
|
||||||
case Traits.Active:
|
case Traits.Active:
|
||||||
if (isHigh)
|
if (isHigh)
|
||||||
Activeness = Math.Min(10, Niceness + 5);
|
Active = Math.Min(8, Nice + 5);
|
||||||
else
|
else
|
||||||
Niceness = Math.Min(10, Activeness + 5);
|
Nice = Math.Min(8, Active + 5);
|
||||||
break;
|
break;
|
||||||
case Traits.Playful:
|
case Traits.Playful:
|
||||||
if (isHigh)
|
if (isHigh)
|
||||||
Playfulness = Math.Min(10, Outgoingness + 5);
|
Playful = Math.Min(8, Outgoing + 5);
|
||||||
else
|
else
|
||||||
Outgoingness = Math.Min(10, Playfulness + 5);
|
Outgoing = Math.Min(8, Playful + 5);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ArgumentException("Invalid trait name.");
|
throw new ArgumentException("Invalid trait name.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generates a random personality with balanced traits.
|
||||||
|
/// </summary>
|
||||||
private void GenerateRandomPersonality()
|
private void GenerateRandomPersonality()
|
||||||
{
|
{
|
||||||
Random rand = new Random();
|
Random rand = new Random();
|
||||||
Niceness = rand.Next(11);
|
Nice = rand.Next(11);
|
||||||
Neatness = rand.Next(11);
|
Neat = rand.Next(11);
|
||||||
Outgoingness = rand.Next(11);
|
Outgoing = rand.Next(11);
|
||||||
Activeness = rand.Next(11);
|
Active = rand.Next(11);
|
||||||
Playfulness = rand.Next(11);
|
Playful = rand.Next(11);
|
||||||
|
|
||||||
// Ensure that the sum of traits is balanced
|
// 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)
|
if (totalSum > 50)
|
||||||
{
|
{
|
||||||
int overage = totalSum - 50;
|
int average = totalSum - 50;
|
||||||
int traitToReduce = rand.Next(5);
|
int traitToReduce = rand.Next(5);
|
||||||
switch (traitToReduce)
|
switch (traitToReduce)
|
||||||
{
|
{
|
||||||
case 0: Niceness -= Math.Min(Niceness, overage); break;
|
case 0: Nice -= Math.Min(Nice, average); break;
|
||||||
case 1: Neatness -= Math.Min(Neatness, overage); break;
|
case 1: Neat -= Math.Min(Neat, average); break;
|
||||||
case 2: Outgoingness -= Math.Min(Outgoingness, overage); break;
|
case 2: Outgoing -= Math.Min(Outgoing, average); break;
|
||||||
case 3: Activeness -= Math.Min(Activeness, overage); break;
|
case 3: Active -= Math.Min(Active, average); break;
|
||||||
case 4: Playfulness -= Math.Min(Playfulness, overage); 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()
|
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