/* 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 */ import static java.lang.System.*; import static java.lang.Integer.*; import java.io.*; class hmrabi { static BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); static int seed; static int rndseq(int n){ seed=(seed*1255+6173) % 29282; return (seed*n) / 29282; } static void intro(){ out.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 Java, C and Pascal 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(){ out.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; out.printf("A horrible plague struck! Half the people died.\n"); } out.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; out.printf("Land is trading at %d bushels per acre.\n",land); } static void quitnow(){ out.printf("\nHammurabi: I cannot do what you wish.\n"+ "Get yourself another steward!!!!!\n"); exit(0); } static void notacres(){ out.printf("Hammurabi: Think again. You have only %d"+ " acres. Now then,\n",acres); } static void notgrain(){ out.printf("Hammurabi: Think again. You have only\n"+ "%d bushels of grain. Now then,\n",store); } static void notpeople(){ out.printf("But you have only %d people to tend the fields."+ " Now then,\n",people); } static int getbuy() throws IOException { String buf; int q; for(;;){ out.printf("How many acres do you wish to buy? "); buf=in.readLine(); q=parseInt(buf); if(q<0) quitnow(); if(land*q<=store) return q; notgrain(); } } static int getsell() throws IOException { String buf; int q; for(;;){ out.printf("How many acres do you wish to sell? "); buf=in.readLine(); q=parseInt(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() throws IOException { 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++) out.printf("%c",7); out.printf("\nSo long for now.\n\n"); exit(0); } static void failure(){ out.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; out.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){ out.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){ out.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 { out.printf( "A fantastic performance!!! Charlemange, Disraeli, and\n"+ "Jefferson combined could not have done better!\n"); } } static public void main(String[] args) throws IOException { String buf; int c; out.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"); out.printf("Would you like more information? "); buf=in.readLine(); if(buf.substring(0,1).toUpperCase().equals("Y")) intro(); out.printf("\nPlease enter a random seed between 0 and 29282: "); buf=in.readLine(); seed=parseInt(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){ out.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(); out.printf("\nWould you like to continue playing? "); buf=in.readLine(); if(buf.substring(0,1).toUpperCase().equals("N")) finish(); } year++; } } } // class hmrabi