|
Post by B+ on Aug 10, 2020 8:06:46 GMT
'21_Game from Rosetta Code b+ saw this at Rosetta 2020-08-09 ' ref: http://rosettacode.org/wiki/21_Game
' Take turns adding 1, 2, or 3 until someone makes the total = 21, they are winner.
while 1 Total = 0 'reset print "21_Game - Rosetta Code" 'title for total print "Running Total: "; Total if rnd(1) < .5 then human = 1 : bebop = 4 else human = 0 : bebop = 2 'who goes first end if while 1 human = 1 - human 'toggle player if human then [getHuman] 'in case human plays 22, 23... locate 30, bebop INPUT "Human: enter 1, 2, 3 for your turn, any other quits > "; add bebop = bebop + 4 if add < 1 OR add > 3 then print "Human quits, goodbye!": end if add + Total > 21 then print "Too much to add, try again...": GOTO [getHuman] else 'ai turn if Total >= 18 then add = 21 - Total else select case Total case 17 : add = 1 case 16 : add = 1 case 15 : add = 2 case 14 : add = 3 case else : add = 3 ' AI not that smart ;( end select end if end if if human then print " Human adds "; add else print " AI adds "; add Total = Total + add print "Running Total: "; Total if Total = 21 then if human then print "*** Human wins ***" else print " *** AI wins ***"' exit while end if wend print: input "Press enter to continue, q + enter to quit "; delay$ if delay$ = "q" then print "Goodbye!" : end cls wend
Stay tuned for smarter AI...
Say does this remind you of the Game NIM?
|
|
|
Post by B+ on Aug 10, 2020 8:48:33 GMT
Oh that didn't take long to figure out:
'21_Game from Rosetta Code b+ saw this at Rosetta 2020-08-09 ' ref: http://rosettacode.org/wiki/21_Game '2020-08-10 harder game, better AI
' Take turns adding 1, 2, or 3 until someone makes the total = 21, they are winner.
while 1 Total = 0 'reset print "21_Game - Rosetta Code" 'title for total print "Running Total: "; Total if rnd(1) < .5 then human = 1 : bebop = 4 else human = 0 : bebop = 2 'who goes first end if while 1 human = 1 - human 'toggle player if human then [getHuman] 'in case human plays 22, 23... locate 30, bebop INPUT "Human: enter 1, 2, 3 for your turn, any other quits > "; add bebop = bebop + 4 if add < 1 OR add > 3 then print "Human quits, goodbye!": end if add + Total > 21 then print "Too much to add, try again...": GOTO [getHuman] else 'ai turn if Total >= 18 then add = 21 - Total else add = 0 for i = 1 to 3 if (Total + i) mod 4 = 1 then add = i next if add = 0 then add = 1 end if end if if human then print " Human adds "; add else print " AI adds "; add Total = Total + add print "Running Total: "; Total if Total = 21 then if human then print "*** Human wins ***" else print " *** AI wins ***"' exit while end if wend print: input "Press enter to continue, q + enter to quit "; delay$ if delay$ = "q" then print "Goodbye!" : end cls wend
You have to go first to win.
|
|
|
Post by tsh73 on Aug 10, 2020 21:45:16 GMT
Nice but you can't beat it for the life . (Robert A. Heinlein Door Into Summer)
|
|
|
Post by B+ on Aug 10, 2020 22:17:09 GMT
Nice but you can't beat it for the life . (Robert A. Heinlein Door Into Summer) LOL "we could teach him to miss"... Yeah that's why I never liked NIM, it's like not being "in" on a joke. I saw the challenge at Rosetta, and saw the long programs there and said, "Basic could do better, be much briefer and intelligible." It took me longer to get it looking pretty than to get the thing working. Just for the record, it can be beat: Sample Run 21_Game - Rosetta Code Running Total: 0
Human: enter 1, 2, 3 for your turn, any other quits > 1 Human adds 1 Running Total: 1 AI adds 1 Running Total: 2 Human: enter 1, 2, 3 for your turn, any other quits > 3 Human adds 3 Running Total: 5 AI adds 1 Running Total: 6 Human: enter 1, 2, 3 for your turn, any other quits > 3 Human adds 3 Running Total: 9 AI adds 1 Running Total: 10 Human: enter 1, 2, 3 for your turn, any other quits > 3 Human adds 3 Running Total: 13 AI adds 1 Running Total: 14 Human: enter 1, 2, 3 for your turn, any other quits > 3 Human adds 3 Running Total: 17 AI adds 1 Running Total: 18 Human: enter 1, 2, 3 for your turn, any other quits > 3 Human adds 3 Running Total: 21 *** Human wins ***
Press enter to continue, q + enter to quit
You know I think that is the nature of Rosetta Code Games, the fun is coding them not playing them.
|
|
|
Post by tenochtitlanuk on Aug 11, 2020 13:22:22 GMT
'The Moon Is a Harsh Mistress, and 'Door into Summer'. Two of my favourites, still on my shelves ( in three languages for D.I.S.). Remember 'TANSTAAFL' anyone?
|
|
|
Post by B+ on Aug 11, 2020 15:45:59 GMT
'The Moon Is a Harsh Mistress, and 'Door into Summer'. Two of my favourites, still on my shelves ( in three languages for D.I.S.). Remember 'TANSTAAFL' anyone? Eh! 50 years ago I was big into Sci Fi (before they called it that! or around the time when they started) Heinlein was OK but my favorites were Asimov and Clark then things went to hell with Vonnegut Jr when I ate my Breakfast of Champions. HaHaaaaa! Moved a couple of times so my bookshelf has experienced paradigm shifts. Do you remember the graphics of virus in the movie Andromeda Strain? I looked it up on Internet and it's not what I remember but it was a main motivator for me to do computer programming. I wonder if I am repeating myself, I'd swear I've told this story before at JB or other forum. ? D.I.S. Internet says Disney Stock market, then Dept of Info Services ;-)) Update: There was a movie made of Breakfast of Champions, wow just found out. Holy moly it's with Bruce Willis back when he had hair. :-))
|
|