## Number Guessing Game

Discuss software for the Apple 1/replica 1

### Number Guessing Game

In the spirit of a little more fun (and re-creating a program I wrote for a TRS-80 when I was 9) here is a number guessing game.

Code: Select all
`100 REM ** NUMBER GUESSING DEMO IN APPLE I BASIC110 REM ** BY CHRIS FORESMAN, 2006120 DIM Y\$(1)130 PRINT "LET'S PLAY THE GUESSING GAME!"140 PRINT "I'M THINKING OF A NUMBER FROM 1 TO 100."150 PRINT "YOU TRY TO GUESS IT IN 6 TRIES!"160 PRINT ""165 N = RND(100)+1170 FOR I=1 TO 6180 INPUT "WHAT'S YOUR GUESS",G190 IF ABS(N-G) < 3 PRINT "CLOSE!"200 IF G > N THEN PRINT "LOWER."210 IF G < N THEN PRINT "HIGHER."220 IF G = N THEN PRINT "YOU GUESSED IT IN ";I;" TRIES!":GOTO 250230 NEXT I240 PRINT "SORRY, THE NUMBER I WAS THINKING OF IS ";N;"."250 PRINT ""260 INPUT "WOULD YOU LIKE TO PLAY AGAIN (Y/N)",Y\$270 IF Y\$ = "Y" THEN GOTO 140280 END`

Feel free to point out any dumb errors.

foresmac

Posts: 16
Joined: Feb Sun 12, 2006 11:48 pm

Well I'm no expert in BASIC these days, but it seems to me there are a few problems with this program.

First error is:
Code: Select all
`190 IF ABS(N-G) < 3 PRINT "CLOSE!"`

You need to put THEN in before PRINT for Apple-1 BASIC.

Second error is also in this line, but this time it is a logic error. You probably don't want to print out "CLOSE!" when N=G, so you need to adjust your IF condition.

Third error is:
Code: Select all
`220 IF G = N THEN PRINT "YOU GUESSED IT IN ";I;" TRIES!":GOTO 250`

The GOTO 250 is not conditional on G=N, so it will always jump to 250.

I'd suggest restructuring a little, and separating out the G=N code a bit.

You probably should have given it a try before posting.

Ken

edit: After rereading this post, I think I ought to apologise if you think I seem a bit harsh. I don't mean to be at all! I'm just pointing out some problems as you asked, and I think its great that people are writing code and sharing it on the Forums. There are quite probably bugs in the code I just posted in another thread as well!
Kallikak

Posts: 172
Joined: Jan Sun 29, 2006 6:42 pm
Location: Sydney

No way, it really helps.

I've had so much C shoved down my throat it's hard to think in terms of a different syntax.

Thanks for the pointers, and I'll keep a closer eye on my conditional branches. It would probably be easier to separate what happens on these conditional branches into subroutines.

foresmac

Posts: 16
Joined: Feb Sun 12, 2006 11:48 pm

OK, here's another stab:
Code: Select all
`100 REM ** NUMBER GUESSING DEMO IN APPLE I BASIC110 REM ** BY CHRIS FORESMAN, 2006120 DIM Y\$(1)130 PRINT "LET'S PLAY THE GUESSING GAME!"140 PRINT "I'M THINKING OF A NUMBER FROM 1 TO 100."150 PRINT "YOU TRY TO GUESS IT IN 6 TRIES!"160 PRINT ""165 N = RND(100)+1170 FOR I=1 TO 6180 INPUT "WHAT'S YOUR GUESS",G190 IF G = N THEN GOTO 290200 IF ABS(N-G) < 3 PRINT "CLOSE!"210 IF G < N THEN PRINT "HIGHER."220 IF G > N THEN PRINT "LOWER."230 NEXT I240 PRINT "SORRY, THE NUMBER I WAS THINKING OF IS ";N;"."250 PRINT ""260 INPUT "WOULD YOU LIKE TO PLAY AGAIN (Y/N)",Y\$270 IF Y\$ = "Y" THEN GOTO 140280 END290 PRINT "YOU GUESSED IT IN ";I;" TRIES!":GOTO 250`

Actually, I should find an Apple I emulator. My Replica 1 is being graded for a history of tech class.

foresmac

Posts: 16
Joined: Feb Sun 12, 2006 11:48 pm

Having found Cocoa Pom, I find it unusable on my machine. It can't keep up with my typing, and I can only type about 30-35 wpm. Jeesh!

I'll just have to wait. Maybe in the meantime I should order an NVRAM chip, because I don't have my serial board set up, and I don't have a USB to serial converter either.

I think I'm going to try to devise a way to use compact flash cards with an Apple I. Or something. Seems like there should be an easier way to dump text into it. <ponders...>

foresmac

Posts: 16
Joined: Feb Sun 12, 2006 11:48 pm

Pom 1 is an Apple-1 emulator written in java. I use it often and find it quite good. There were some problems, but the code is open and so I was able to fix them. I will make my adjustments available with my assembler next week.

Ken
Kallikak

Posts: 172
Joined: Jan Sun 29, 2006 6:42 pm
Location: Sydney

That would be awesome.
Thanks, Ken.

foresmac

Posts: 16
Joined: Feb Sun 12, 2006 11:48 pm