Allocate from a budget of 25
- Newly generated algorithm thanks to GPT - Somehow I thought the budget was 50
This commit is contained in:
parent
a8717a5177
commit
8dcefdded0
2 changed files with 34 additions and 89 deletions
|
@ -1,101 +1,46 @@
|
||||||
using PersonalityGenerator;
|
var rng = new Random();
|
||||||
|
|
||||||
var isFinishedSession = false;
|
int totalPoints = 25;
|
||||||
|
int[] points = new int[5]; // To store the personality points for Outgoing, Nice, Playful, Neat, and Active
|
||||||
|
string[] personalities = { "Outgoing", "Nice", "Playful", "Neat", "Active" };
|
||||||
|
|
||||||
void GenerateTraits()
|
// Function to randomly allocate points
|
||||||
|
void AllocatePoints()
|
||||||
{
|
{
|
||||||
// Prompt the user to enter traits they want to prioritize.
|
int remainingPoints = totalPoints;
|
||||||
Console.WriteLine("You can prioritize one or more traits to be above 8 by entering them.");
|
|
||||||
Console.Write("Enter traits separated by commas (e.g., Outgoing, Nice), or press Enter to generate a random personality: ");
|
|
||||||
|
|
||||||
// Read the user input and trim any leading or trailing whitespace.
|
|
||||||
var prioritizedTraitsInput = Console.ReadLine()?.Trim();
|
|
||||||
|
|
||||||
// Initialize a dictionary with predefined traits and their initial values set to 0.
|
|
||||||
var traits = new Dictionary<string, int>
|
|
||||||
{
|
|
||||||
{ "Outgoing", 0 },
|
|
||||||
{ "Nice", 0 },
|
|
||||||
{ "Playful", 0 },
|
|
||||||
{ "Neat", 0 },
|
|
||||||
{ "Active", 0 }
|
|
||||||
};
|
|
||||||
|
|
||||||
// Process the prioritized traits input:
|
// First, allocate points to each personality.
|
||||||
// 1. Split the input string by commas.
|
for (int i = 0; i < points.Length; i++)
|
||||||
// 2. Trim whitespace from each resulting trait.
|
|
||||||
// 3. Filter out any empty or invalid traits (traits that are not in the predefined list).
|
|
||||||
var prioritizedTraits = new HashSet<string>(prioritizedTraitsInput.Split(',')
|
|
||||||
.Select(t => t.Trim()).Where(t => !string.IsNullOrEmpty(t) && traits.ContainsKey(t)));
|
|
||||||
|
|
||||||
// Check if there are any prioritized traits provided by the user.
|
|
||||||
if (prioritizedTraits.Count > 0)
|
|
||||||
{
|
{
|
||||||
// Assign values to the prioritized traits.
|
points[i] = rng.Next(0, 11); // Assign 0-10 points to each personality
|
||||||
TraitGenerator.AssignPrioritizedTraits(traits, prioritizedTraits);
|
remainingPoints -= points[i];
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// If no prioritized traits are provided, assign random values to all traits.
|
|
||||||
TraitGenerator.AssignRandomTraits(traits);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display the generated personality traits.
|
// Adjust the remaining points
|
||||||
TraitGenerator.DisplayPersonality(traits);
|
for (int i = 0; i < points.Length; i++)
|
||||||
|
|
||||||
// Mark the session as finished.
|
|
||||||
isFinishedSession = true;
|
|
||||||
|
|
||||||
// Re-enter the session manager to allow for another session or to exit.
|
|
||||||
SessionManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Retrieves user input from the console with a given prompt.
|
|
||||||
string? GetUserInput(string prompt)
|
|
||||||
{
|
|
||||||
Console.WriteLine(prompt);
|
|
||||||
var input = Console.ReadLine();
|
|
||||||
|
|
||||||
return input;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Manages the personality generator session. It checks if a previous session is finished
|
|
||||||
// and prompts the user to either generate a new personality or exit the application.
|
|
||||||
void SessionManager()
|
|
||||||
{
|
|
||||||
// Greet the user at the start of a new session only if the previous session wasn't finished.
|
|
||||||
if (!isFinishedSession)
|
|
||||||
Console.WriteLine("Welcome to the Sim Personality Generator!");
|
|
||||||
|
|
||||||
// Define a message to prompt the user about generating a personality.
|
|
||||||
// The message differs slightly if a previous session was already finished.
|
|
||||||
var message = "Would you like to generate a random personality? [y/n]";
|
|
||||||
if (isFinishedSession)
|
|
||||||
message = "Would you like to generate a new personality? [y/n]";
|
|
||||||
|
|
||||||
// Retrieve the user's input through a prompt specified by 'message'.
|
|
||||||
var input = GetUserInput(message);
|
|
||||||
|
|
||||||
// Convert the input to lowercase to handle user input in a case-insensitive manner.
|
|
||||||
switch (input?.ToLower())
|
|
||||||
{
|
{
|
||||||
case "y":
|
if (remainingPoints == 0) break;
|
||||||
// Reset the session status if the previous session was finished.
|
|
||||||
if (isFinishedSession)
|
|
||||||
isFinishedSession = false;
|
|
||||||
|
|
||||||
// Clear the console to provide a clean interface for generating a new personality.
|
int adjustment = Math.Min(rng.Next(0, 3), remainingPoints); // Small adjustment within range
|
||||||
Console.Clear();
|
points[i] += adjustment;
|
||||||
|
remainingPoints -= adjustment;
|
||||||
|
|
||||||
// Generate a new set of personality traits
|
if (points[i] > 10) // Ensure no personality gets more than 10 points
|
||||||
GenerateTraits();
|
{
|
||||||
break;
|
int excess = points[i] - 10;
|
||||||
|
points[i] = 10;
|
||||||
default:
|
remainingPoints += excess; // Return excess points to the pool
|
||||||
// If the user enters anything other than 'y', terminate the application gracefully.
|
}
|
||||||
Environment.Exit(Environment.ExitCode);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Print the final personality points
|
||||||
|
for (int i = 0; i < points.Length; i++)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"{personalities[i]}: {points[i]} points");
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine($"Total remaining points in the pool: {remainingPoints}");
|
||||||
}
|
}
|
||||||
|
|
||||||
SessionManager();
|
// Generate the points and print the result
|
||||||
|
AllocatePoints();
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<Version>0.1.100</Version>
|
<Version>0.1.100</Version>
|
||||||
<TargetFramework>net9.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
Reference in a new issue