CIIC 3015 Project #2
CIIC 3015 Project #2
CIIC 3015 Project #2
22September2021
EricSalo([email protected])
DUE:Tuesday,October19atnoon
TL/DR:Therewillbeashortvideopostedshowingmerunningthroughmyownsolutiontothis
project.Pleasewatchit,apictureisworthathousandwords.
Yourassignmentistowriteaninteractivesimulation(Read:textadventuregame.Theywereall
therageintheearly1980s!)ofsomeonewhocomeshomeandwantstogotosleep.Iftheuser
managestofallasleep,theywin!Thesimulationworksasfollows:Yourusermustnavigateand
interactwithanenvironmentconsistingoftheirfrontdoor,livingroom,kitchen,officeand
bedroom.Theydothisbytypingcommandsataprompt.Thesimulationprocesseseach
command,updatesitsstate,andrepeats.Amapofthesimulationenvironmentwouldlooklike
this:
Bedroom
FrontDoor LivingRoom Office
Kitchen
So,theLivingRoomisEastoftheFrontDoorandSouthoftheBedroom,forexample.
Theconstraintsofactionwithinthisenvironmentareasfollows:
Inordertowin,youmustenterthebedroomandsleep.Whatcouldbeeasier!
Inordertoenteryourbedroomyoumustgetpastyourravenousgreyhound,Stella.Stellawill
blockyourentranceintothebedroomuntilsheisfedanicetastybonefromthepantryinthe
kitchen.Sheisalsoveryparticularaboutherdiningenvironmentandrequiresthetelevisionto
beturnedonbeforeshewillbegineating.(Itmaybeturnedoffagainaftershehasstarted.)
Thedoortothepantryinthekitchenisclosedandlocked.Beforeitcanbeopened,itmustbe
unlockedusingthekey,whichcanbefoundinthesafeintheoffice.Thesafehasacombination
lock.Thecombinationtothesafeis21-64-32.Afterthepantryhasbeenopened,thenicetasty
boneinsidemayberemoved.
Ifthetelevisioninthelivingroomison,thenoisewillkeepyouawakeandyouwillnotbeableto
sleep.Andbecauseyouobsessoversuchthings,youmustcloseandrelockthepantrydoor
afterremovingthebone,andreturnthepantrydoorkeytotheofficesafe,andclosethesafe,
beforeyouwillbeabletorelaxenoughtosleep.Youmustalsoreturnthecanoflovelyspam
fromthebedroomtothepantrywhereitbelongs.
Onceyouenterthehousethroughthefrontdoor,youmaynotleave.
Thecommandsareallsingle-characterandareasfollows:
'b'(bed)
Getintothebedandtrytosleep.Ifyouaresuccessfulyouwinthegame!Youmustbeinthe
bedroom.Thetvmustbeoff.Thepantrydoorkeymustbeintheofficesafe.Thepantrydoor
mustbeclosedandlocked.Theofficesafemustbeclosed(itwilllockautomatically)..
‘c’(close)
Closesomethinginneedofclosing,suchasthesafeorthepantrydoor.
'e'(east)
Movetotheroomtotheeast,ifpossible.
'f'(feed)
FeedStella.Youmustbeinthelivingroom.Youmustpossessthebone.Thetvmustbeon.
'g'(get)
Retrieveanitemofinterestfromthecurrentroom,suchasthepantrydoorkeyorthenicetasty
boneorthecanoflovelyspam.
‘l’(lock)
Lockthepantrydoor.Youmustbeinthekitchen.Thepantrydoormustbeclosedandunlocked.
'n'(north)
Movetotheroomtothenorth,ifpossible.
'o'(open)
Opensomethinginneedofopening,suchasthesafeorthepantrydoor.
'p'(put)
Putawaysomethinginneedofputtingaway,suchasthepantrydoorkeyorthecanoflovely
spam.Forthepantrydoorkey,theofficesafemustbeopen.Forthecanoflovelyspam,the
pantrydoormustbeopen.
'q'(quit)
Quitthegame.
's'(south)
Movetotheroomtothesouth,ifpossible.
't'(togglethetv)
Togglethestateofthetv.Ifitison,turnitoff.Ifitisoff,turniton.Youmustbeinthelivingroom.
'u'(unlock)
Unlockthepantrydoor.Youmustbeinthekitchen.Youmustpossessthepantrydoorkey.The
pantrydoormustbelocked.(Thiscommandalsoworksonthesafeintheoffice.)
'w'(west)
Movetotheroomtothewest,ifpossible
DISCUSSION:
Thisisnowherenearasdifficultasitmayfirstappear,Ipromise.
Nosophisticatedalgorithmsarerequiredhere,it’salmostentirelyjustsimplebooleanvariables
andreallylongif-chains.Theuserentersacommand,youcheckthecurrentstateofyour
variousflags,decidewhethertoallowordisallowthataction,updatethestate,printahelpful
message,andrepeat.
Theheartofthisproblemisbeingabletokeeptrackandcleanlyhandleallofthevarious
possiblecombinationsofstatesandactions,andtopresentalogicallyconsistentmodelofthe
world.Forexample,noneofthefollowingshouldbepossible:
1. Openingsomethingthatisalreadyopen.
2. Closingsomethingthatisalreadyclosed.
3. Lockingsomethingthatisalreadylocked.
4. Lockingadoorthatisstillopen.
5. Unlockingsomethingthatisalreadyunlocked.
6. Gettingsomethingthatyoualreadypossess.
7. Puttingawaysomethingthatyoudonotpossess.
8. Feedingsomeonewhoisalreadyeating.
9. Retrievingsomethingfromacontainerthatisclosed.
10. Puttingsomethingintoacontainerthatisclosed.
Andsoon.
Agradingrubricwillbepostedsoonbutmaynotbeavailableimmediately.Inaddition,the
beginningsofabasiceventloopwillbeuploadedtoMoodleasastartingpointforanyonewho
maybeinterestedinusingit.
YouarewarmlyencouragedtoaddyourownDLCtoextendthissimulationhoweveryouwish,
subjecttothefollowing:
1. Beawarethatthereisnoofficialextracreditonthisproject.Youwillbegradedsolelyon
basicfunctionalityaccordingtotherubric.InProject1manyofyoufocusedstronglyon
extrasattheexpenseofcorrectness.Pleasegetthefundamentalsdownfirstbefore
goingnutswiththebellsandwhistles.
2. Donotaddanythingwhichinterfereswiththebasicvictorycondition.Forexample,don’t
addadogwhistletosummonStellaoutofthelivingroomorasledgehammertobreak
intothesafe.Theexactsamesequenceofcommandsshouldstillresultinawin(ora
loss)regardlessofanyadditionalcontent.Instead,addnewroomsoritemsoreventsor
puzzlesasself-containedoptionalsidequests,anddocumentthemasneededeither
in-gameorout-of-game.
Hint:ArrangeyourPythoncodeinsomekindofalphabeticalorder,forroomnames,commands,
orwhatever.Itwillhelptremendouslyasyoumakeprogressandyourprojectgrows.(“Oh,the
LivingRoomcode?Yeah,that’sbetweenKitchenandOffice…”)
AswithProject1,youareallowedbutnotrequiredtoworkinateamwithoneotherstudent
fromanylabsection.
ADDENDUM9/24:
YoumustimplementyourentiresimulationwithinafunctioncalledProject2()whichreturnsTrue
whentheuserwinsthegameandFalsewhentheuserquitsthegame.Thiswillallowusto
writetestcasesinCodeRunner,whichwillbemadeavailablewellbeforetheprojectisdue.