/* Nick Cash's Sanity Program */
/* This software is released to the public domain. 2007 Nick Cash */
#include <stdio.h> #include <time.h> /* the higher the better */ #define NICKS_CURRENT_HAPPINESS 5 /* 1-10 */ #define NICKS_FAMILY_LIFE_METER 3 /* 1-10 */ #define NICKS_FRIENDSHIP_METER 5 /* 1-10, based on friendly influences */ #define NICKS_LIFE_SATISFACTION 4 /* 1-10 */ /* the higher the better, but no real scale */ #define NICKS_CARING_FRIENDS 3 /* current number of deep, caring friends */ #define NICKS_RECENT_FUN_ACTIVITIES 3 /* number of fun activities within 7 days */ #define NICKS_PLANNED_FUN_ACTIVITIES 4 /* current future plans for fun activities */ /* the higher the worse */ #define NICKS_ACADEMIC_WORK_LOAD 5 /* 1-10 */ #define NICKS_HOMEWORK_LOAD 8 /* 1-10 */ #define NICKS_STRESS_LEVEL 8 /* 1-10 */ #define NICKS_ANNOYANCE_LEVEL (10-NICKS_LIFE_SATISFACTION) /* sanity states, update CURRENT_STATE to reflect current state of mind */ typedef enum { SANE, INSANE, UNKNOWN, CURRENT_STATE = UNKNOWN } sane_states; /* prototype */ void CrashUniverse( void ); /* Update sanity */ 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); /* check for negative score */ if ( (rand() % 2) == 0 ) r *= -1; /* verify validity within range */ r = r < low ? r = low : (r > high ? r = high : r ); /* determine state */ 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; } /* FixNicksSanity, based off of close friends */ 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(); } } /* Update the world */ 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); /* failure */ } if ( *person == SANE ) /* do not update for unknowns */ printf( "Woot, sanity!\n" ); UpdateSanity(person); } /* uh... print a message? */ 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(); } /* here we go */ int main ( ) { short Nick = CURRENT_STATE; /* sanity questionable currently */ /* seed pseudo-random num gen with current time */ srand(time(NULL)); while ( 1 ) /* it goes on and on my friends...*/ { 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; /* failure */ } } }