Number Guessing Game

Discuss software for the Apple 1/replica 1

Number Guessing Game

Postby foresmac » May Mon 08, 2006 4:31 am

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 BASIC
110 REM ** BY CHRIS FORESMAN, 2006
120 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)+1
170 FOR I=1 TO 6
180 INPUT "WHAT'S YOUR GUESS",G
190 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 250
230 NEXT I
240 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 140
280 END


Feel free to point out any dumb errors.
User avatar
foresmac
 
Posts: 16
Joined: Feb Mon 13, 2006 12:48 am

Postby Kallikak » May Tue 09, 2006 12:13 am

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 7:42 pm
Location: Sydney

Postby foresmac » May Wed 10, 2006 12:43 am

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.
User avatar
foresmac
 
Posts: 16
Joined: Feb Mon 13, 2006 12:48 am

Postby foresmac » May Wed 10, 2006 12:54 am

OK, here's another stab:
Code: Select all
100 REM ** NUMBER GUESSING DEMO IN APPLE I BASIC
110 REM ** BY CHRIS FORESMAN, 2006
120 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)+1
170 FOR I=1 TO 6
180 INPUT "WHAT'S YOUR GUESS",G
190 IF G = N THEN GOTO 290
200 IF ABS(N-G) < 3 PRINT "CLOSE!"
210 IF G < N THEN PRINT "HIGHER."
220 IF G > N THEN PRINT "LOWER."
230 NEXT I
240 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 140
280 END
290 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.
User avatar
foresmac
 
Posts: 16
Joined: Feb Mon 13, 2006 12:48 am

Postby foresmac » May Wed 10, 2006 9:31 am

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...>
User avatar
foresmac
 
Posts: 16
Joined: Feb Mon 13, 2006 12:48 am

Postby Kallikak » May Wed 10, 2006 5:01 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 7:42 pm
Location: Sydney

Postby foresmac » May Wed 10, 2006 5:15 pm

:D
That would be awesome.
Thanks, Ken.
User avatar
foresmac
 
Posts: 16
Joined: Feb Mon 13, 2006 12:48 am


Return to Software

Who is online

Users browsing this forum: No registered users and 1 guest

cron