This is what I recommend doing:
These are just things that I have done:
Create the board array as a one-dimensional array from 0 to 63
Define the black and white pieces in alternating order, so
- 0=Empty Space
- 1=Black Pawn
- 2=White Pawn
- 3=Black Knight
- 4=White Knight
- 5=Black Bishop
- 6=White Bishop
- 7=Black Rook
- 8=White Rook
- 9=Black Queen
- 10=White Queen
- 11=Black King
- 12=White King
Then the code would work as so:
DIM BOARD[64]
RESETBOARD
DEF RESETBOARD
RESTORE @NEWBOARD
FOR I=0 TO 63
READ BOARD[I]
NEXT
@NEWBOARD
DATA 7,3,5,11,9,5,3,7
DATA 1,1,1,1,1,1,1,1
DATA 0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0
DATA 2,2,2,2,2,2,2,2
DATA 8,4,6,12,10,6,4,8
END
'Here are a few extra functions that may help you
'FAST FUNCTION TO CHECK IF AN X,Y POSITION IS WITHIN BOUNDS OF THE BOARD
DEF INBOUNDS(X,Y)
RETURN X>=0&&Y>=0&&X<8&&Y<8
END
'EXTRACT THE X VALUE OUT OF AN INDEX
DEF GETXINDEX(N)
IF N>=0&&N<64 THEN RETURN N MOD 8 ELSE RETURN -1
END
'EXTRACT THE Y VALUE OUT OF AN INDEX
DEF GETYINDEX(N)
IF N>=0&&N<64 THEN RETURN N DIV 8 ELSE RETURN -1
END
'CONVERT FROM X AND Y TO A SINGLE INDEX FROM 0-63
DEF GETINDEX(X,Y)
IF !INBOUNDS(X,Y) THEN RETURN -1
RETURN Y*8+X
END
'-1=ERROR
'0=PAWN
'1=KNIGHT
'2=BISHOP
'3=ROOK
'4=QUEEN
'5=KING
DEF GETPIECE(X,Y)
IF !INBOUNDS(X,Y) THEN RETURN -1
RETURN (BOARD[Y*8+X]-1) DIV 2
END
'-1=ERROR
'0=BLACK
'1=WHITE
DEF GETCOLOR(X,Y)
IF !INBOUNDS(X,Y) THEN RETURN -1
RETURN BOARD[Y*8+X] MOD 2
END
If you are trying to build a chess AI
- Create a function that can list all the possible positions a piece can be placed with the current board situation
- Create a scoring system to determine which of those moves will give you the most points
- Find a minimax algorithm, preferably alpha-beta-pruning, which will use logic to search a certain depth (like 5 moves ahead) in a tree-like structure to rank each path and find the path that has the highest score.
Sorry I got a little carried away, but I hope this helps you at least a little bit.