#include <stdio.h>
#include <time.h>
#define NICKS_CURRENT_HAPPINESS 5 #define NICKS_FAMILY_LIFE_METER 3 #define NICKS_FRIENDSHIP_METER 5 #define NICKS_LIFE_SATISFACTION 4 #define NICKS_CARING_FRIENDS 3 #define NICKS_RECENT_FUN_ACTIVITIES 3 #define NICKS_PLANNED_FUN_ACTIVITIES 4 #define NICKS_ACADEMIC_WORK_LOAD 5 #define NICKS_HOMEWORK_LOAD 8 #define NICKS_STRESS_LEVEL 8 #define NICKS_ANNOYANCE_LEVEL (10-NICKS_LIFE_SATISFACTION)
typedef enum { SANE, INSANE, UNKNOWN, CURRENT_STATE = UNKNOWN } sane_states;
void CrashUniverse( void );
void UpdateSanity( short* x )
{
short low = 0, mid, high = 0, r;
high += NICKS_CURRENT_HAPPINESS*(NICKS_LIFE_SATISFACTION+NICKS_FAMILY_LIFE_METER+
NICKS_FRIENDSHIP_METER);
high += NICKS_CARING_FRIENDS + NICKS_RECENT_FUN_ACTIVITIES + NICKS_PLANNED_FUN_ACTIVITIES;
low -= NICKS_STRESS_LEVEL*(NICKS_ACADEMIC_WORK_LOAD+NICKS_HOMEWORK_LOAD+
NICKS_ANNOYANCE_LEVEL);
mid = high+low;
r = rand() % (high+1);
if ( (rand() % 2) == 0 )
r *= -1;
r = r < low ? r = low : (r > high ? r = high : r );
if ( r >= low && r <= low+NICKS_CURRENT_HAPPINESS )
{
*x = INSANE;
printf( "Sanity lost during update...\n");
}
else if ( r >= mid )
*x = SANE;
else
*x = UNKNOWN;
}
void FixNicksSanity( short* person )
{
short percent_to_help_sanity = (NICKS_CARING_FRIENDS*10) > 100 ? 100 : (NICKS_CARING_FRIENDS*10);
short percent_to_hurt_sanity = 100-(percent_to_help_sanity/2);
short x = (rand() % 100)+1;
if ( x <= percent_to_help_sanity )
{
*person = SANE;
printf( "Sanity saved!\n" );
getche();
}
else if ( x >= percent_to_hurt_sanity )
{
*person = INSANE;
printf( "Sanity lost...\n");
getche();
}
else
{
*person = UNKNOWN;
printf( "Continuing questionable mental state...\n" );
getche();
}
}
void RunWorld( short* person )
{
if ( !person || *person < SANE || *person >= INSANE )
{
printf( "\n\nFatal error while updating the world...Termination of existence...\n\n");
CrashUniverse();
exit(1); }
if ( *person == SANE ) printf( "Woot, sanity!\n" );
UpdateSanity(person);
}
void CrashUniverse( void )
{
printf( "\n\nNick clutches his head in agony as his world spirals out of control.\nSuddenly the world grinds to a halt. The universe goes dark as stars stop their\nfision. The universe stops expanding and turns into a cold empty shell.\n\n" );
printf( "God mutters, \"Not again! Damn this pesky software...\"\n\nHe then proceeded to reboot the Universe server... (which runs Linux).\n\n");
getche();
}
int main ( )
{
short Nick = CURRENT_STATE; srand(time(NULL));
while ( 1 ) {
while ( Nick == SANE )
RunWorld(&Nick);
while ( Nick == UNKNOWN )
FixNicksSanity(&Nick);
if ( Nick >= INSANE || Nick < SANE )
{
printf( "\n\nThe universe is screwed.... ::sigh::\n\n" );
CrashUniverse();
return 1; }
}
}