This program should load the data in the second code block below and display the board and numerous stats and flags
Variables required for 100% legal move generation have been included & initialized including 50 move rule and 3 fold repetition
Save game files and saved position need to include these variable ive hard coded them in for now but will append and update the save game file creator at a later date. A PGN file which starts at move can be be reverse engineered to set the '50 move rule' and '3 fold repetition' flags. This feature will be added later.
Currently there are two data structures , a piece list and a simple 8x8 board with 1=white 2= black and 0 = empty
The piece list has an extra field which can be used to signify original and promoted pieces, moved and never moved pieces and other key attributes and metrics.
Code: Select all
'positionsetup
dim as integer i,ii,x,y,c,col
dim as string q,qq
dim as integer sx,sy 'start x , start y
dim title as string
dim special as string
dim id(32) as string 'name
dim xx(32) as integer ' x cordinate A to H on chessboard as is
dim yy(32) as integer ' y cordinate 1 to 8 on chessboard displayed inverted
dim mo(32) as integer
dim notes as string
'array to hold the board for legal move detection 1=white 2= black 3 empty
dim bw (8,8) as integer
dim as integer woo,wooo,boo,booo,mnum,enp,m50rule
dim as string stm,pgn,repx3
'zero some arrays
'for i=1 to 32
' id(i) = ""
' xx(i) = 0
' yy(i) = 0
' mo(i) = 0
'next i
chdir "testfiles"
OPEN "startposition.txt" FOR input AS #1
input #1, title
? title
input #1,special
? special
for i =1 to 32
input # 1, id(i),xx(i),yy(i),mo(i)
? id(i);xx(i);yy(i);mo(i) ; " piece number ";i
next i
input #1,notes
? notes
CLOSE #1
woo=1:wooo=1:boo=1:booo=1
stm="white"
'stm="black"
mnum=1
enp=0
pgn="no"
if pgn="no" then repx3="no" : m50rule=0
?
?" positionsetup "
? " get/set flags"
?
? " side to move ";stm
? " move number ";mnum
?
? " castling rights"
? " woo ";woo
? " wooo ";wooo
? " boo ";boo
? " booo ";booo
?
? " PGN / move history found = ";pgn
? " 3 fold Repetition history = ";repx3
? " Fifty move rule counter = ";m50rule
?
? " en passant after pawn push on file number = "; enp
'open saved position and load it into array
' display the board
screen 19
'draw chess board notes 'Draw String (99, 66), "Origin", 12
c=0
for i = 1 to 8
for ii= 1 to 8
c=c+1
if c = 1 then col = 27 : c=c-2 else col = 6
line (i*20,ii*20)-((i*20)+18,(ii*20)+18),col,bf
'sleep 30
next ii
c=c+1
if c = 1 then col = 7 : c=c-2 else col = 11
next i
'sleep:end
col = 31
for i=1 to 32
if i > 16 then col = 0
draw string ((xx(i)*20)+6,(yy(i)*20)+2),id(i),col
'? xx(i),i : sleep
'sleep 150
next i
'cls
'load simplified peices into bw array just as black or white values
color 7 : locate 2,51 :? "peice list, in play > 0"
for i=1 to 16
if mo(i)>0 then bw (xx(i),yy(i)) =1 else bw (xx(i),yy(i)) = 0
color 7: locate i+2 ,50: ? i; bw (xx(i),yy(i))
next i
for i=17 to 32
if mo(i)>0 then bw (xx(i),yy(i)) =2 else bw (xx(i),yy(i)) = 0
color 8: locate i+2 ,50:? i;bw (xx(i),yy(i))
next i
'PSEUDO MOVE GENERATION **********************************************************************************
'find whos turn it is , should be added to saved position for completness,need to expand the format to encompass this
' find kings normal moves
'get kings start position
if stm ="white" then sx = xx(1) : sy = yy (1) : color 7
if stm ="black" then sx = xx(17) : sy = yy (17) : color 8
locate 2,24: ? " ";stm;" king at";sx;" sx";sy;" sy"
sleep:end
saved game file , see first post
save the text below as startposition.txt in directory called testfiles ( or just comment out chdir "testfiles" in the code above )
Code: Select all
"default"
"specialnull"
"K",5,8,99
"Q",4,8,99
"R",1,8,99
"R",8,8,99
"B",3,8,99
"B",6,8,99
"N",2,8,99
"N",7,8,99
"P",1,7,99
"P",2,7,99
"P",3,7,99
"P",4,7,99
"P",5,7,99
"P",6,7,99
"P",7,7,99
"P",8,7,99
"k",5,1,99
"q",4,1,99
"r",1,1,99
"r",8,1,99
"b",3,1,99
"b",6,1,99
"n",2,1,99
"n",7,1,99
"p",1,2,99
"p",2,2,99
"p",3,2,99
"p",4,2,99
"p",5,2,99
"p",6,2,99
"p",7,2,99
"p",8,2,99
"notes"