Post Reply 
Really really fast BASIC handheld
01-13-2019, 10:03 PM (This post was last modified: 01-14-2019 07:43 PM by berndpr.)
Post: #30
RE: Really really fast BASIC handheld
Hallo!
Here I show the 8-Queen-Problem with addtional feature to show all changes in A and all 92 solutions.

CLS
PRINT "8-Queen-Problem with all solutions"
OPTION DEFINT
N=0
R=8
S=0
X=0
DIM A[9]
@LA
IF X==R GOTO @LE
INC X
A[X]=R: SHOW S,A
@LB
INC S
Y=X
@LC
DEC Y
IF Y==0 GOTO @LA
T=A[X]-A[Y]
IF T==0 GOTO @LD
IF X-Y!=ABS(T) GOTO @LC
@LD
DEC A[x]:SHOW S,A
IF A[X]!=0 GOTO @LB
DEC X
IF X!=0 GOTO @LD
@LE
IF A[1]==0 GOTO @LF
INC N
ZEIG S,A
PRINT
PRINT N;" .Solution=;S ; " Pos:";
FOR I=1 TO 8
PRINT CHR$(64+A[I]);I;
IF I!=8 THEN PRINT ",";
NEXT
BUTOFF
GOTO @LD
@LF
LOCATE 1,15
PRINT "FINISHED"
END

DEF SHOW S,A
LOCATE 1,2
BUTON
PRINT S
PRINT " A B C D E F G H"
FOR I=1 TO 8
J=A[I]
PRINT J;" ";I;
IF J>0 THEN
PRINT " ."*(J-1);" ";CHRS$(&H2640);" ."*(8-J);
ELSE
PRINT " ."*8;
ENDIF
PRINT " ";I
NEXT
END

DEF BUTON
REPEAT
B=BUTTON()
UNTIL B!=0
IF B==#A THEN VSYNC 3 'only to slow down display or output is faster than the eye.
IF B==#B THEN STOP
END

DEF BUTOFF
BUTON
REPEAT
B=BUTTON()
UNTIL B==0 || B==#X

END

Button B quits the program.
The program runs only, if a key is pressed.
If you press the button X the program progress until the button is released. It stops not at the next solution.

Hold Button A to progress slowly and stops at the next solution.
Any other Button progress fast and stops at next solution.
For next solution release button and hold again.

DEF is define a function
END is end program or end function
BUTTON() return the bits of the pressed hardware keys.
#X is the number (bit) of key X
|| is an OR
N is the number of the solution
"ABC"*3 is a string repeat: "ABCABCABC"
CHRS$(&H2640) is the venus symbol (queen). It's a Unicode value.
If the value in A is a zero, no queen is shown.

This version was developed for Yabasic (PS2 BASIC from the demo cd of the first release, available for PC Windows and Linux too, http://www.yabasic.de/) and is not optimized for speed but use exact the 8-Queen-Benchmark. I have changed it to SmileBASIC (not big changes).

I hope this will help you
Bernd

P.S.:
I have corrected errors in the code and changed the button control.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Really really fast BASIC handheld - berndpr - 01-13-2019 10:03 PM



User(s) browsing this thread: 1 Guest(s)