/* hmrabi.c--Govern Ancient Sumeria Translated to Java by Eric Olson July 16, 2013 Translated to Pascal by Eric Olson July 6, 2013 Translated to C by Eric Olson June 6, 2013 Converted from the original Focal program and modified for the Edusystem 70 by David Ahl, DIGITAL */ #include #include typedef char String[255]; static int seed; static int rndseq(int n){ seed=(seed*1255+6173) % 29282; return (seed*n) / 29282; } static void intro(){ printf( "\nDescription\n" "\n" "In this game you direct the adminitrator of Sumeria, Hammurabi,\n" "how to manage the city. The city initially has 1,000 acres, 100\n" "people and 3,000 bushels of grain in storage.\n" "\n" "You may buy and sell land with your neighboring city-states for\n" "bushels of grain--the price will vary between 17 and 26 bushels\n" "per acre. You also must use grain to feed your people and as\n" "seed to plant the next year''s crop.\n" "\n" "You will quickly find that a certain number of people can only\n" "tend a certain amount of land and that people starve if they\n" "are not fed anough. You also have the unexpected to contend\n" "with such as a plague, rats destroying stored grain, and variable\n" "harvests.\n" "\n" "You will also find that managing just the few resources in this\n" "game is not a trivial job over a period of say ten years. The\n" "crisis of population density rears its head very rapidly.\n" "\n" "Source\n" "\n" "This program translated to C, Pascal and Java by Eric Olson from\n" "101 BASIC Computer Games by David Ahl. In turn that program was\n" "translated from the original FOCAL program which was floating\n" "around DIGITAL in the late 1970's.\n"); } static int acres,people,year,land,store; static int starve,rats,plague,yield,harvest,immigrant; static int buy,sell,feed,plant; static int starvetotal; static double starveperct; static void status(){ printf("\n\nHammurabi: I beg to report to you,\n" "In year %d , %d people starved, %d came to the city.\n", year,starve,immigrant); people+=immigrant; if(plague<=0){ people/=2; printf("A horrible plague struck! Half the people died.\n"); } printf("Population is now %d\n" "The city now owns %d acres.\n" "You harvested %d bushels per acre.\n" "Rats ate %d bushels.\n" "You now have %d bushels in store.\n\n", people,acres,yield,rats,store); land=rndseq(10)+17; printf("Land is trading at %d bushels per acre.\n",land); } static void quitnow(){ printf("\nHammurabi: I cannot do what you wish.\n" "Get yourself another steward!!!!!\n"); exit(0); } static void notacres(){ printf("Hammurabi: Think again. You have only %d" " acres. Now then,\n",acres); } static void notgrain(){ printf("Hammurabi: Think again. You have only\n" "%d bushels of grain. Now then,\n",store); } static void notpeople(){ printf("But you have only %d people to tend the fields." " Now then,\n",people); } static int getbuy() { String buf; int q; for(;;){ printf("How many acres do you wish to buy? "); fgets(buf,sizeof(buf),stdin); q=atoi(buf); if(q<0) quitnow(); if(land*q<=store) return q; notgrain(); } } static int getsell() { String buf; int q; for(;;){ printf("How many acres do you wish to sell? "); fgets(buf,sizeof(buf),stdin); q=atoi(buf); if(q<0) quitnow(); if(qacres) notacres(); // Enough grain for seed? else if(d/2>store) notgrain(); // Enough people to tend the crops? else if(d>=10*people) notpeople(); else return d; } } static void inputs() { buy=getbuy(); acres+=buy; store-=land*buy; if(buy==0){ sell=getsell(); acres-=sell; store+=land*sell; } feed=getfeed(); store-=feed; plant=getplant(); store-=plant/2; } static void finish(){ int n; for(n=0;n<10;n++) printf("%c",7); printf("\nSo long for now.\n\n"); exit(0); } static void failure(){ printf( "Due to this extreme mismanagement you have not only\n" "been impeached and thrown out of office but you have\n" "also been declared ''national fink'' !!\n"); } static void score(){ double l,p1; p1=starveperct/year; l=(double)acres/people; printf( "\nIn your 10-year term of office %.1f percent of the\n" "population starved per year on average, i.e., a total of\n" "%d people died!!\n" "You started with 10 acres per person and ended with\n" "%.1f acres per person.\n\n",p1,starvetotal,l); if (p1>33||l<7) failure(); else if (p1>10||l<9){ printf( "Your heavy-handed performance smacks of Nero and Ivan IV.\n" "The people (remaining) find you an unpleasant ruler, and,\n" "frankly, hate your guts!\n"); } else if (p1>3||l<10){ printf( "Your performance could have been somewhat better, but\n" "Really wasn't too bad at all. %d people would\n" "dearly like to see you assassinated but we all have our\n" "trivial problems.\n",(int)((people*rndseq(80))/100)); } else { printf( "A fantastic performance!!! Charlemange, Disraeli, and\n" "Jefferson combined could not have done better!\n"); } } int main() { String buf; int c; printf("hmrabi--Govern Ancient Sumeria\n\n" "Try your hand at governing ancient Sumeria\n" "Successfully for a 10-year term of office.\n\n"); printf("Would you like more information? "); fgets(buf,sizeof(buf),stdin); if(toupper(buf[0])=='Y') intro(); printf("\nPlease enter a random seed between 0 and 29282: "); fgets(buf,sizeof(buf),stdin); seed=atoi(buf); starveperct=0; starvetotal=0; people=95; store=2800; harvest=3000; rats=harvest-store; yield=3; acres=harvest/yield; immigrant=5; plague=1; starve=0; year=1; for(;;){ status(); inputs(); // A Bountyfull Harvest!! yield=rndseq(5)+1; harvest=plant*yield; // The rats are running wild!! c=rndseq(5)+1; if(c%2==0) rats=store/c; else rats=0; store+=harvest-rats; // Determine how many people immigrated. immigrant=(int)((rndseq(5)+1)*(20.0*acres+store)/people/100+1); // How many people had full tummies? starve=people-(int)(feed/20); if(starve<0) starve=0; // Starve enough for impeachment? else if(starve>0.45*people){ printf( "\nYou starved %d people in one year!!!\n",starve); failure(); finish(); } starveperct+=starve*100.0/people; starvetotal+=starve; people-=starve; // Horrors, a 15% chance of plague plague=rndseq(20)-3; if(year%10==0){ score(); printf("\nWould you like to continue playing? "); fgets(buf,sizeof(buf),stdin); if(toupper(buf[0])=='N') finish(); } year++; } }