mirror of
https://github.com/simtactics/servo.git
synced 2025-03-15 00:21:20 +00:00
- WIP decision engine - Redesigned choice dataset - Moved data, images and models folders into notebooks directory for easier eaccess
230 lines
No EOL
6.9 KiB
Text
230 lines
No EOL
6.9 KiB
Text
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"# Motive Engine\n",
|
|
"\n",
|
|
"\n",
|
|
"\n",
|
|
"The Motive Engine is based on opposing weights. An object signals it's presence if the Sim's need is low. The need is the motive and that drives a Sims' decision. All games in the franchise are based on this dynamic at it's core. For example, if hunger is low then the fridge's presence is high and vice versa. A Sim's mood is the sum of the current state of their motives. They will only choose the fridge if it increases it's overall mood. The ML portion comes in deciding which has the priority.\n",
|
|
"\n",
|
|
"A Sim's motives decrease in increments and independently of each other during game play. They are randomized for this experiment. "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {},
|
|
"source": [
|
|
"#r \"nuget:Microsoft.ML\""
|
|
],
|
|
"outputs": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {},
|
|
"source": [
|
|
"using System.Linq;"
|
|
],
|
|
"outputs": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {},
|
|
"source": [
|
|
"const int NAX_MOOD = 600;\n",
|
|
"const int MAX_MOTIVE = 100;"
|
|
],
|
|
"outputs": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {},
|
|
"source": [
|
|
"static int MaxLimit(this int val, int max)\n",
|
|
"{\n",
|
|
" if (max < 0)\n",
|
|
" throw new ArgumentOutOfRangeException();\n",
|
|
"\n",
|
|
" if (val >= max)\n",
|
|
" return max;\n",
|
|
"\n",
|
|
" return val;\n",
|
|
"}"
|
|
],
|
|
"outputs": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {},
|
|
"source": [
|
|
"class Motives\n",
|
|
"{\n",
|
|
" public Motives(int hunger, int bladder, int fun, int energy, \n",
|
|
" int environment, int social)\n",
|
|
" {\n",
|
|
" Hunger = hunger;\n",
|
|
" Bladder = bladder;\n",
|
|
" Fun = fun;\n",
|
|
" Energy = energy;\n",
|
|
" Environment = environment;\n",
|
|
" Social = social;\n",
|
|
" }\n",
|
|
"\n",
|
|
" public int Hunger { get; set; }\n",
|
|
" public int Bladder { get; set; }\n",
|
|
" public int Fun { get; set; }\n",
|
|
" public int Energy { get; set; }\n",
|
|
" public int Environment { get; set; }\n",
|
|
" public int Social { get; set; }\n",
|
|
"\n",
|
|
" // The mood is the sum of all the motives.\n",
|
|
" // It deteremines the best course of action.\n",
|
|
" public int Mood\n",
|
|
" {\n",
|
|
" get\n",
|
|
" {\n",
|
|
" var curMood = new[] { Hunger, Bladder, Fun,\n",
|
|
" Social, Environment, Energy };\n",
|
|
"\n",
|
|
" return curMood.Sum();\n",
|
|
" }\n",
|
|
" }\n",
|
|
"\n",
|
|
" // In the game, this would increament gradually\n",
|
|
" // until it reaches it's max motive.\n",
|
|
" int CalcuateMotiveChange(int motive, int input)\n",
|
|
" {\n",
|
|
" var curMotive = motive;\n",
|
|
" var curMood = Mood;\n",
|
|
"\n",
|
|
" // New motive equals the current motive plus the input\n",
|
|
" var newMotive = curMotive + input;\n",
|
|
"\n",
|
|
" // New mood equals the new motive plus the current mood\n",
|
|
" var newMood = newMotive + curMood;\n",
|
|
"\n",
|
|
" // Changed motive is the new motive with the limit\n",
|
|
" var changedMotive = newMotive.MaxLimit(MAX_MOTIVE);\n",
|
|
"\n",
|
|
" // Does the new motive increase my current motive?\n",
|
|
" // Does the new motive increase my overall mood?\n",
|
|
" if (changedMotive >= curMotive && curMood <= NAX_MOOD \n",
|
|
" && changedMotive <= MAX_MOTIVE && curMood <= NAX_MOOD)\n",
|
|
" return changedMotive;\n",
|
|
" \n",
|
|
" // Fall back to the current movement\n",
|
|
" return curMotive;\n",
|
|
" }\n",
|
|
"\n",
|
|
" public void ChangeHunger(int input)\n",
|
|
" {\n",
|
|
" Hunger = CalcuateMotiveChange(Hunger, input);\n",
|
|
" }\n",
|
|
"\n",
|
|
" public void ChangeFun(int input)\n",
|
|
" {\n",
|
|
" Fun = CalcuateMotiveChange(Fun, input);\n",
|
|
" }\n",
|
|
"\n",
|
|
" public void ChangeBladder(int input)\n",
|
|
" {\n",
|
|
" Bladder = CalcuateMotiveChange(Bladder, input);\n",
|
|
" }\n",
|
|
"\n",
|
|
" public void ChangeSocial(int input)\n",
|
|
" {\n",
|
|
" Social = CalcuateMotiveChange(Social, input);\n",
|
|
" }\n",
|
|
"\n",
|
|
" public void ChangeEnergy(int input)\n",
|
|
" {\n",
|
|
" Energy = CalcuateMotiveChange(Energy, input);\n",
|
|
" }\n",
|
|
"\n",
|
|
" public void ChangeEnvironment(int input)\n",
|
|
" {\n",
|
|
" Environment = CalcuateMotiveChange(Environment, input);\n",
|
|
" }\n",
|
|
"}"
|
|
],
|
|
"outputs": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {},
|
|
"source": [
|
|
"void PrintMotives(Motives motives)\n",
|
|
"{\n",
|
|
" Console.WriteLine($\"Hunger: {motives.Hunger}{Environment.NewLine}\" +\n",
|
|
" $\"Fun: {motives.Fun}{Environment.NewLine}\" +\n",
|
|
" $\"Bladder: {motives.Bladder}{Environment.NewLine}\" +\n",
|
|
" $\"Social: {motives.Social}{Environment.NewLine}\" +\n",
|
|
" $\"Environment: {motives.Environment}\");\n",
|
|
" Console.WriteLine($\"Mood: {motives.Mood}\");\n",
|
|
"}"
|
|
],
|
|
"outputs": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {},
|
|
"source": [
|
|
"// Run this first\n",
|
|
"var rng = new Random();\n",
|
|
"\n",
|
|
"var motives = new Motives(hunger: rng.Next(MAX_MOTIVE), \n",
|
|
"bladder: rng.Next(MAX_MOTIVE), fun: rng.Next(MAX_MOTIVE), \n",
|
|
"energy: rng.Next(MAX_MOTIVE), environment: rng.Next(MAX_MOTIVE), \n",
|
|
"social: rng.Next(MAX_MOTIVE));\n",
|
|
"\n",
|
|
"PrintMotives(motives);"
|
|
],
|
|
"outputs": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {},
|
|
"source": [
|
|
"// Run this next\n",
|
|
"var newRng = new Random();\n",
|
|
"\n",
|
|
"// Minimum random number is whatever the current motive is\n",
|
|
"motives.ChangeHunger(newRng.Next(motives.Hunger, MAX_MOTIVE));\n",
|
|
"motives.ChangeFun(newRng.Next(motives.Fun, MAX_MOTIVE));\n",
|
|
"motives.ChangeSocial(newRng.Next(motives.Social, MAX_MOTIVE));\n",
|
|
"motives.ChangeBladder(newRng.Next(motives.Bladder, MAX_MOTIVE));\n",
|
|
"motives.ChangeEnergy(newRng.Next(motives.Energy, MAX_MOTIVE));\n",
|
|
"motives.ChangeEnvironment(newRng.Next(motives.Environment, MAX_MOTIVE));\n",
|
|
"\n",
|
|
"PrintMotives(motives);"
|
|
],
|
|
"outputs": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": ".NET (C#)",
|
|
"language": "C#",
|
|
"name": ".net-csharp"
|
|
},
|
|
"language_info": {
|
|
"file_extension": ".cs",
|
|
"mimetype": "text/x-csharp",
|
|
"name": "C#",
|
|
"pygments_lexer": "csharp",
|
|
"version": "8.0"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 4
|
|
} |