游戏汉诺塔源代码(1/2)
focalдbasicfortran
01.01chanoibydec
01.02cfromprogramminglanguages
01.03clastchange:8/7/71
01.04
01.05cthisprogramworkswiththetowersofhanoiproblem.
01.06cyouaregiventhreetowerswithvarioussizeddiscson
01.07coneofthem.theobjectistoplaceallthediscson
01.08canothertoweronatatime,withthestipulationthata
01.09clargerdiscmayneverbeontopofasmallerone.this
01.10cprogramisgoodforanynumberofdiscsandcanberun
01.11ceitherinmanual(youtellitwheretomove)orautomatic
01.12cmode.itwillalsoexplainitsmovesordrawtheforyou,
01.13cdependingonhowyouanswerthemovesorplotsquestion.
01.14c**outdiscisthedisc(1ontop)thatyouwanttomove
01.15c**indiscistheposition(1ontop)whereyoumoveto
01.16c**outtoweristhetower(1onleft)fromwhichyoumove
01.17c**intoweristhetower(3onright)youmoveto
01.18cthisprogramassumesnocheating,anddoesnotcheckforit.
01.19
01.29e
01.30a"no.ofdisks"n,!
01.40fi=1,n;sss(i)=i
01.50sso=1;ssi=3
01.60sno=n;sni=n;si=0
01.70a"movesorplots",move,!
01.80i(fabs(mo-0moves)),1.85;d23
01.85a"autoormanual",a,!
01.90i(fabs(a-0manual)),5.1;d2;t!!"done!",!!;q
本章未完,点击下一页继续阅读。