The game board is typically represented in memory by a numeric array: one dimension for the pillars, and a second dimension for the rings. BRAHMA follow this design:
Code: Select all
;DIM A(3,5)
; values=ring-size
;ring-level 1--- 1 0 0
; 2--- 2 0 0
; 3--- 3 0 0
; 4--- 4 0 0
; 5--- 5 0 0
;
; | | |
; pillar: 1 2 3
BRAHMA type-in from your computer magazine April 1982 vol 2 no 4 page 77
This is a version that is very basic and with little feedback ... but it does run in 1K. And on a 1K machine it is OK, but on 16K - as normal - it is slow until the screen stabilizes
Type-in thanks to Antipontifex and Xavsnap
The magazine put a ZX-80 badge on this, but Paul says it is for the ZX-81. I tried it on the ZX80 but even after changing all the GOTO to GO TO, it didn't work
Unfortunately, the magazine listing is missing the critical line that actually draws all the rings. The listing actually has three bugs. Ah, such were the joys of the type-in eraBrahma
ZX80
Paul Blythe,
Sheffield,
South Yorkshire.
This LOGIC problem is based on the project given by Brahma, the Hindu deity, to his
disciples. The object of the game is to transfer a set of rings, of different sizes, from one pillar to another but at no time can a larger ring be on top of a smaller.
The program runs on a ZX-81 1K. However, typing errors or illegal moves when playing the game stretch the memory to its limits. There are five rings; ring 1 is the smallest. If, however, you have additional memory, you can have more rings by using the alternative lines shown at the end of the program where N is the number of rings. The solution for five rings is given below.
BRAHMA
10 DIM A(3,5)
11 FOR B=1 TO 5
12 LET A(1,B)=B
13 NEXT B
14 GOTO 160
20 PRINT "FROM"
21 INPUT C
50 FOR B=1 TO 5
60 IF A(C,B)<>0 THEN GOTO 80
70 NEXT B
75 GOTO 20
80 PRINT "TO"
81 INPUT D
82 IF C=D THEN GOTO 20
90 FOR E=1 TO 5
100 IF A(D,E)=0 THEN NEXT E
125 IF E=6 THEN GOTO 190
130 IF A(C,B)>A(D,E) THEN GOTO 190
140 LET A(D,E)=A(C,B)
150 CLS
155 LET A(C,B)=0
160 FOR F=1 TO 5
170 PRINT " ";A(1,F);" ";A(2,F);" ";A(3,F)
180 GOTO 20
190 LET A(D,5)=A(C,B)
200 GOTO 150
10 DIM A (3,N)
11 FOR B=1 TO N
50 FOR B=1 TO N
90 FOR E=1 TO N
125 IF E=N+1 THEN GOTO 190
160 FOR F=1 TO N
190 LET A (D,N)=A(C,B)
SOLUTION
1-3, 1-2, 3-2, 1-3, 2-1, 2-3, 1-3, 1-2, 3-2, 3-1,
2-1, 3-2, 1-3, 1-2, 3-2, 1-3, 2-1, 2-3, 1-3, 2-1,
3-2, 3-1, 2-1, 2-3, 1-3, 1-2, 3-2, 1-3, 2-1, 2-3,
1-3
These changes make it work:
1. To see all the rings, add
Code: Select all
175 NEXT F
Code: Select all
130 IF A(C,B)>A(D,E) THEN GOTO 190
Code: Select all
130 IF A(C,B)>A(D,E) THEN GOTO 20
Code: Select all
131 LET E = E-1
Paul said:
This is basically replacing the fixed '5' with the variable N. But it doesn't work. Antipontifex identified a missing line that needs to be added:you can have more rings by using the alternative lines shown at the end of the program where N is the number of rings
Code: Select all
5 LET N=5
[edit: Added files, and revised the text]