// This method would be called when an AI completes a task and requires a new one to strive towards
// The Random Number Generator that it will use to determine exactly what to do next is passed as a parameter
void AI::generateNewTask(RandomNumberGenerator generator)
// Just a holder variable that will contain a value between 1 and a very large number
// which will possibly be 18,446,744,073,709,551,615 which is the max decimal value a 64 bit unsigned integer can hold
unsigned long long rawRandomValue = generator.getNextValue();
// We want to scale the value down to a value between 0 and 9999, this prevents weird percision bugs that could be created in the next
// calculation if we didn't do this
unsigned long long clampedRandomValue = rawRandomValue % 10000;
// We take our clamp value and divide it by the maximum value a clamped value can be, which effecitivley transforms the value into a normalized float
// 'c' contains the 0.0 to 1.0 floating point value that we want
float c = (float)clampedRandomValue / 10000.0f
// Our AI is going to be more "economic" oriented since in your example, boba, you said he was heading out to mine.
// Lets say the description of our AI's attributes or perosnality is just described by a single floating point number for each attribute possible
// The sum of the values for all these attribtues must be equal to 1.0. Lets say he has the following attributes:
// Aggressive - 10% or 0.1 as a floating point value in memory
// Economic - 70% or 0.7
// Exploration - 20% or 0.2
// These are the constants talked about above, in reality these would be determined when the AI is first created
// And just be instance member variables for the "AI" class
float currentAIAggressiveRate = 0.1f;
float currentAIEconomicRate = 0.7f;
float currentAIExplorationRate = 0.2f
// Thses values set below represent the chance an attribute will influence the generation of the AI's new task
// The key takeaway point here and in the branching code below is that an attribute with a higher rate
// will more likely be chosen which is what the programmer would want, they would want an "aggressive"
// person to usually choose aggressive tasks to do like pirate, fight, ect...
float aggressiveChance = currentAIAggressiveRate;
float economicChance = aggressiveChance + currentAIEconomicRate;
float explorationChance = economicChance + currentAIExplorationRate;
if(c <= aggressiveChance)
// Now that we know the AI has decided he will work towards an aggressive oriented task, we have to generate one
// Which an entire different function and just take the returned task and set this specific AI's task instance variable
// with that value
Task newTask = generateAggressiveTask();
else if(c <= economicChance)
Task newTask = generateEconomicTask();
else if(c <= explorationChance)
Task newTask = generateExplorationTask();
Dinosawer wrote:Programmatically, making the game perfectly deterministic is extremely difficult if not impossible, and since it's impossible to notice unless you automate your input just to see if it is I din't see the point of wasting time on it.
Mordakai wrote:Dinosawer wrote:Programmatically, making the game perfectly deterministic is extremely difficult if not impossible, and since it's impossible to notice unless you automate your input just to see if it is I din't see the point of wasting time on it.
This is rather dependent on the context and type of game. For anything real time, like an FPS, RTS, Space Sim, and so on, yeah, not especially relevant.
But it is very applicable to turn based games. The best example I can think of is the success rolls in XCOM (the new ones in particular), where the game actually does provide the option for the player to choose. If your soldier misses that 90% shot and dies as a result, it's the difference between being dead for good and reloading for another chance.
Users browsing this forum: No registered users and 3 guests