Pavel Marceluch

Crokinole counter written in BASIC for SHARP PC-1403H

When I visited my family over christmas, my dad gave me his old SHARP pocket computer 1403H. It’s a lovely retro device. It acts just like any other calculator, but you can switch it into a BASIC mode. In this mode, you can either write or run BASIC. I started learning it immediately, but the manual he gave me was entirely in German, so I had to find the English one on the internet. Scrolling a PDF is not as fun as going through a book, but at least I know what’s going on.

I decided that I would try to write a Crokinole Counter. I’ve written this exact app like five times on different platforms already. The idea is simple: ask for the number of players, ask for their names, and then ask for round scores until someone wins.

I’ve written the code on my PC in a text editor, but I did not find any BASIC interpreter I liked, so I just ran all tests and debugging on the device. It’s just around 60 lines of code, but the calc (short for calculator) display has only one line! Inputting it all in took some time, and there were still a few bugs. But in the end, it worked flawlessly!

Here is the BASIC code I wrote:

 10	PRINT "CROKINOLE COUNTER V1"
 20	PRINT "(C) PAVEL MARCELUCH"
 30	
 40	INPUT "ENTER PLAYER COUNT: ";PC
 50	IF PC < 2 OR PC > 4 THEN GOTO 40
 60	DIM GS(PC)
 70	DIM PN$(PC)
 80	DIM RS(PC)
 90	DIM RI(PC)
100	
110	INPUT "ENTER PLAYER NAME 1: ";PN$(1)
120	INPUT "ENTER PLAYER NAME 2: ";PN$(2)
130	IF PC = 2 THEN GOTO 180
140	INPUT "ENTER PLAYER NAME 3: ";PN$(3)
150	IF PC = 3 THEN GOTO 180
160	INPUT "ENTER PLAYER NAME 4: ";PN$(4)
170	
180	IF PC = 2 THEN PRINT "SCORES: "+STR$(GS(1))+", "+STR$(GS(2))
190	IF PC = 3 THEN PRINT "SCORES: "+STR$(GS(1))+", "+STR$(GS(2))+", "+STR$(GS(3))
200	IF PC = 4 THEN PRINT "SCORES: "+STR$(GS(1))+", "+STR$(GS(2))+", "+STR$(GS(3))+", "+STR$(GS(4))
210	
220	FOR I=1 TO PC
230	  T=0:X=0
240	  PRINT "ENTER TOKENS FOR "+PN$(I)
250	  INPUT "X5 COUNT: ";X
260	  T=T+X*5:X=0
270	  INPUT "X10 COUNT: ";X
280	  T=T+X*10:X=0
290	  INPUT "X15 COUNT: ";X
300	  T=T+X*15:X=0
310	  INPUT "X20 COUNT: ";X
320	  T=T+X*20:X=0
330	  RS(I)=T
340	NEXT I
350	
360	RI(1) = 1
370	RI(2) = 2
380	IF PC = 2 THEN GOTO 420
390	RI(3) = 3
400	IF PC = 3 THEN GOTO 420
410	RI(4) = 4
420	FOR I=1 TO PC-1
430	  FOR J=1 TO PC-I
440	    IF RS(J) < RS(J+1) THEN GOSUB 480
450	  NEXT J
460	NEXT I
470	GOTO 570
480	
490	T = RS(J)
500	RS(J) = RS(J+1)
510	RS(J+1) = T
520	T = RI(J)
530	RI(J) = RI(J+1)
540	RI(J+1) = T
550	RETURN
560	
570	GS(RI(1)) = GS(RI(1))+RS(1)-RS(2)
580	PRINT "PLAYER "+PN$(RI(1))+" GOT "+STR$(RS(1)-RS(2))+" POINTS."
590	IF GS(RI(1)) >= 100 THEN GOTO 620
600	GOTO 180
610	
620	PRINT "PLAYER "+PN$(RI(1))+" WON!"
630	END

PC - Player Count
GS - int array for Game Score
PN$ - string array for Player Names
RS - int array for Round Score
RI - int array for Round Index

The calculator cannot store a string longer than 7 characters, so every time I need to output a long string, I have to do it in one PRINT. Variable names can also be max 2 characters. Code readibility stopped being my concern pretty fast. I decided to indent the code a little bit in this preview though.

Tags: