From 4ac00a9378cb696f6e42054f3625f927e23493b5 Mon Sep 17 00:00:00 2001 From: lee2sman Date: Fri, 1 Apr 2022 02:04:10 -0400 Subject: [PATCH] add twopigs.txt --- tinybasic.gmi | 7 ++- twopigs.txt | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 twopigs.txt diff --git a/tinybasic.gmi b/tinybasic.gmi index 8ea69e7..a608d55 100644 --- a/tinybasic.gmi +++ b/tinybasic.gmi @@ -2,6 +2,8 @@ 2022-03-31 +2022-04-01 update: I've added a link to my full code for a player + computer opponent version of the PIG dice game to the end. + Lately I've been getting into BASIC. I was a kid in the 80s and 90s and I remember those computers that would boot into a BASIC interpreter. I didn't have one of those but came in contact with one every year or two and played a handful of text games on them. I was aware of some of the commands and syntax, GOTO and the like, and I have looked through the classic BASIC Video Games book a number of times. The ecosystem of BASIC interested me but I hadn't delved too deeply. Recently I read about Tiny BASIC: > Tiny BASIC is a family of dialects of the BASIC programming language that can fit into 4 or fewer KBs of memory. Tiny BASIC was designed in response to the open letter published by Bill Gates complaining about users pirating Altair BASIC, which sold for $150. Tiny BASIC was intended to be a completely free version of BASIC that would run on the same early microcomputers. --Wikipedia [1] @@ -96,7 +98,9 @@ So here's my small and not terribly fun or sophisticated game of Pig. No doubt m PRINT "GOODBYE" ``` -From here, it would be relatively easy to create some version of Blackjack with a little bit more effort. Of course, it would also be fun to make text adventures, pizza-ordering calculators, the classic game Lemonade, or my favorite BASIC game TI-83 calculator version of Drug Wars/Dope Wars (that's a story for a different time). +UPDATE: I've added a link to a 2 player version (player + computer opponent) I made of Pig dice to the links at the end. Source code license: COPYLEFT ALL RIGHTS WRONGED, natch. There are likely errors as this is the first time I'm programming in any BASIC, and I made this in less than an hour, and sure enough, I was making spaghetti GOTO code! But you are welcome to improve or build upon this in any way you like. + +From here, it would be relatively easy to create some version of Blackjack with a little bit more effort. Of course, it would also be fun to make text adventures, pizza-ordering calculators, the classic text game Lemonade Stand, or a version of my favorite BASIC game TI-83 calculator version of Drug Wars/Dope Wars (that's a story for a different time). To play the game you'll need to download Tiny BASIC. Save the program with a .bas extension. The computer opponent sorely needs better AI than what I've implemented. There's a procedurally-generated maze / dungeon adventure game, like a simplified text RPG, called Kingdom of the Lyre that was made for and entered into PROCJAM in 2019. [5] I played it. It's challenging and I thought it was fun. I'd love to have a Tiny BASIC game jam one day. @@ -112,6 +116,7 @@ To wrap up, I'll leave you with this WANTED ad from Volume 1, Number 1 of Dr. Do => http://tinybasic.cyningstan.org.uk/download/10/random-number-generator Minimal random number generator for Tiny BASIC => http://tinybasic.cyningstan.org.uk/download/44/kingdom-of-the-lyre Kingdom of the Lyre game => http://www.ittybittycomputers.com/IttyBitty/TinyBasic/TBuserMan.htm Tom Pittman's Tiny BASIC User Manual +=> twopigs.txt Tiny BASIC code for playing a computer opponent in the dice game PIG => ./index.gmi Back to index diff --git a/twopigs.txt b/twopigs.txt new file mode 100644 index 0000000..81c7d7f --- /dev/null +++ b/twopigs.txt @@ -0,0 +1,121 @@ + REM --- PIG Dice + REM --- Created: 2022-04-01 by lettuce + REM --- for Tiny BASIC + REM --- COPYLEFT ALL RIGHTS WRONGED + + REM --- Variable List + REM + REM A - aggression, max times the computer will roll + REM C - Computer's total + REM H - Current Hand total + REM I - For determining if player needs instructions + REM D - Current die roll + REM P - Player total + REM R - A random number returned by the Random Number Generator + REM Q - For determining if player would like to roll again + LET A=4 + LET H=0 + LET C=0 + LET P=0 + + REM --- Initialise the random number seed +10 PRINT "ENTER A 4 DIGIT NUMBER:" + INPUT R + + PRINT "DO YOU NEED INSTRUCTIONS? (0 NO, 1 YES)" + INPUT I + IF I=1 THEN GOSUB 250 + + REM --- START + PRINT "WHAT POINT TOTAL TO PLAY TO?" + INPUT W + +15 PRINT "You play first: " + + REM --- MAIN GAME LOOP +20 PRINT "YOUR CURRENT HAND IS ",H + PRINT "WOULD YOU LIKE TO ROLL? (0 NO, 1 YES)" + INPUT Q + +30 IF Q=0 THEN GOTO 40 + + REM --- CHECK IF PLAYER BUSTED + GOSUB 200 + PRINT "YOU ROLLED ",D + IF D=1 THEN GOTO 50 + LET H=H+D + GOTO 20 + + REM --- COMPUTER'S TURN +40 REM FIRST ADD PLAYER'S HAND TOTAL TO PLAYER TOTAL + REM AND DISPLAY IT + LET P=P+H + REM RESET H +42 LET H=0 + GOSUB 150 + REM CHECK IF PLAYER WON + GOSUB 100 + PRINT "" + PRINT "MY TURN" + LET A=4 +45 GOSUB 200 + PRINT "I ROLLED ",D + IF D=1 THEN GOTO 60 + LET H=H+D + LET A=A-1 + REM CHECKING TO SEE IF COMPUTER WILL STOP ROLLING + IF A<1 THEN GOTO 47 + IF C+H

W THEN GOTO 120 + RETURN +120 PRINT "CONGRATULATIONS, YOU WIN!" + GOTO 300 + + REM - CHECK IF COMPUTER WINS +130 IF C>W THEN GOTO 140 + RETURN +140 PRINT "YOU LOSE!" + GOTO 300 + + REM PRINT PLAYER TOTAL +150 PRINT "YOUR CURRENT TOTAL IS ",P + RETURN + +200 LET D=1+R-R/6*6 + LET R=5*R+35 + LET R=R-R/6547*6547 + RETURN + + REM INSTRUCTIONS +250 PRINT "Pig is a simple competitive dice game for two players. In a round, a player may roll a single die as many times as they want, each time adding the points to their hand for that round. They may stop at any time and add the hand to their total game points. If they roll a 1 at any time they are 'BUSTED'. They immediately stop and lose all accrued points in the hand for that round. When a player stops by choice or due to busting, the other player begins a new turn. Game continues in this fashion ending when either player reaches a previously agreed-upon point total." + PRINT "" + RETURN + + REM END +300 PRINT "YOUR SCORE IS ",P + PRINT "COMPUTER SCORE IS ",C + PRINT "GOODBYE" +