Porting Awari game

Discuss software for the Apple 1/replica 1

Porting Awari game

Postby cclaunch » Feb Sun 11, 2007 5:47 pm

Beginning port of game Awari, a Creative Computing title from the Basic Games book. It is an African game often played with beans or stones. The board is two rows of six pits which begin with three beans apiece. There are rules for moving the beans around the board, trying to get as many in your home area as possible by the time one of you runs out of beans in your pits.

Looks straightforward, should be quick.
cclaunch
 
Posts: 31
Joined: Jan Wed 03, 2007 7:18 pm
Location: Silicon Valley

Postby cclaunch » Feb Sun 11, 2007 5:59 pm

slowed slightly due to fuzzy resolution of book page and similar letters M, N, and H used throughout game. Need to understand the logic in order to choose correctly from indistinct blobs that could by any of the above.
cclaunch
 
Posts: 31
Joined: Jan Wed 03, 2007 7:18 pm
Location: Silicon Valley

Postby vbriel » Feb Sun 11, 2007 8:29 pm

Here's the original creative computing version in txt for you (This is not ready for the replica 1):

Code: Select all
5 PRINT TAB(34);"AWARI"
7 PRINT TAB(15);"CREATIVE COMPUTING  MORRISTOWN, NEW JERSEY"
10 DATA 0
15 DIM B(13),G(13),F(50):READ N
20 PRINT:PRINT:E=0
25 FOR I=0 TO 12:B(I)=3:NEXT I
30 C=0:F(N)=0:B(13)=0:B(6)=0
35 GOSUB 500
40 PRINT "YOUR MOVE";:GOSUB 110
45 IF E=0 THEN 80
50 IF M=H THEN GOSUB 100
55 IF E=0 THEN 80
60 PRINT "MY MOVE IS ";:GOSUB 800
65 IF E=0 THEN 80
70 IF M=H THEN PRINT ",";:GOSUB 800
75 IF E>0 THEN 35
80 PRINT:PRINT"GAME OVER"
85 D=B(6)-B(13):IF D<0 THEN PRINT "I WIN BY";-D;"POINTS":GOTO 20
90 N=N+1:IF D=0 THEN PRINT "DRAWN GAME":GOTO 20
95 PRINT "YOU WIN BY";D;"POINTS":GOTO 20
100 PRINT "AGAIN";
110 INPUT M:IF M<7 THEN IF M>0 THEN M=M-1:GOTO 130
120 PRINT "ILLEGAL MOVE":GOTO 100
130 IF B(M)=0 THEN 120
140 H=6:GOSUB 200
150 GOTO 500
200 K=M:GOSUB 600
205 E=0:IF K>6 THEN K=K-7
210 C=C+1:IF C<9 THEN F(N)=F(N)*6+K
215 FOR I=0 TO 5:IF B(I)<>0 THEN 230
220 NEXT I
225 RETURN
230 FOR I=7 TO 12:IF B(I)<>0 THEN E=1:RETURN
235 GOTO 220
500 PRINT:PRINT"   ";
505 FOR I=12 TO 7 STEP -1:GOSUB 580
510 NEXT I
515 PRINT:I=13:GOSUB 580
520 PRINT "                       ";:PRINT B(6):PRINT "   ";
525 FOR I=0 TO 5:GOSUB 580
530 NEXT I
535 PRINT:PRINT:RETURN
580 IF B(I)<10 THEN PRINT " ";
585 PRINT B(I);:RETURN
600 P=B(M):B(M)=0
605 FOR P=P TO 1 STEP -1:M=M+1:IF M>13 THEN M=M-14
610 B(M)=B(M)+1:NEXT P
615 IF B(M)=1 THEN IF M<>6 THEN IF M<>13 THEN IF B(12-M)<>0 THEN 625
620 RETURN
625 B(H)=B(H)+B(12-M)+1:B(M)=0:B(12-M)=0:RETURN
800 D=-99:H=13
805 FOR I=0 TO 13:G(I)=B(I):NEXT I
810 FOR J=7 TO 12:IF B(J)=0 THEN 885
815 G=0:M=J:GOSUB 600
820 FOR I=0 TO 5:IF B(I)=0 THEN 845
825 L=B(I)+I:R=0
830 IF L>13 THEN L=L-14:R=1:GOTO 830
835 IF B(L)=0 THEN IF L<>6 THEN IF L<>13 THEN R=B(12-L)+R
840 IF R>Q THEN Q=R
845 NEXT I
850 Q=B(13)-B(6)-Q:IF C>8 THEN 875
855 K=J:IF K>6 THEN K=K-7
860 FOR I=0 TO N-1:IF F(N)*6+K=INT(F(I)/6^(7-C)+.1) THEN Q=Q-2
870 NEXT I
875 FOR I=0 TO 13:B(I)=G(I):NEXT I
880 IF Q>=D THEN A=J:D=Q
885 NEXT J
890 M=A:PRINT CHR$(42+M);:GOTO 200
900 FOR I=0 TO N-1:PRINT B(I):NEXT I
999 END
User avatar
vbriel
Site Admin
 
Posts: 1184
Joined: Jul Tue 19, 2005 12:10 pm
Location: Ohio

Postby cclaunch » Feb Mon 12, 2007 12:22 am

This is awesome -- thanks, Vince.
cclaunch
 
Posts: 31
Joined: Jan Wed 03, 2007 7:18 pm
Location: Silicon Valley

Postby cclaunch » Feb Mon 12, 2007 12:18 pm

Seemed straightforward, BUT

minor issue - uses exponentiation which is not supported in Apple I basic

major pain -- indexes arrays origin 0 (e.g. if you DIM A(5) they would access as A(0) thru A(4) which means lots of changes to both fixed references and loop boundaries
cclaunch
 
Posts: 31
Joined: Jan Wed 03, 2007 7:18 pm
Location: Silicon Valley

Postby vbriel » Feb Mon 12, 2007 1:38 pm

Yeah, the array A(0) can be a pain but what I did for checkers was to simply add 1 to the value for anytime addressing the array. There is no guarantee that will work but it did in my case.

Vince
User avatar
vbriel
Site Admin
 
Posts: 1184
Joined: Jul Tue 19, 2005 12:10 pm
Location: Ohio

Postby cclaunch » Feb Sun 25, 2007 2:37 pm

Status to date. Working in extremely infrequent free minutes and slogging through the port.

The version posted by Vince contains at least one error. In line 815 it contains G=0 however no other use of variable G. More suspiciously, the code paths in this section have several ways it can test the value of variable Q before it is set by the program. The G=0 appears to really be Q=0 which is how I am proceeding.

Some of the calculating for the computer's move involves numbers that work fine with floating point but quickly get bigger than a 16 bit integer. Will rework this to preserve the logic while fitting the integer only operation of Woz Basic.
cclaunch
 
Posts: 31
Joined: Jan Wed 03, 2007 7:18 pm
Location: Silicon Valley

Postby cclaunch » Feb Sun 25, 2007 10:18 pm

cclaunch wrote:The version posted by Vince contains at least one error.


It is hard to tell if this error was introduced in the original magazine article, in the book repeating them, in the original source, or in the transcription to this forum, but these sorts of minute changes can wreak havoc with the operation of a program.

Moral of this story -- while the reason for a misbehaving program is 99% likely to be a porting error or implementation difference with the Apple/I versus the newer systems on which these programs were developed, there is always that 1% chance that the program, as entered, would not perform correctly on the newer systems. The porting process has to include some verification of the algorithm and the coding, not just translate from one environment to the Replica/Apple world.
cclaunch
 
Posts: 31
Joined: Jan Wed 03, 2007 7:18 pm
Location: Silicon Valley


Return to Software

Who is online

Users browsing this forum: No registered users and 1 guest

cron