59 lines
1.8 KiB
Text
59 lines
1.8 KiB
Text
V board = [[‘ ’] * 8] * 8
|
||
V piece_list = [‘R’, ‘N’, ‘B’, ‘Q’, ‘P’]
|
||
|
||
F place_kings(&brd)
|
||
L
|
||
V (rank_white, file_white, rank_black, file_black) = (random:(0 .. 7), random:(0 .. 7), random:(0 .. 7), random:(0 .. 7))
|
||
V diff_list = [abs(rank_white - rank_black), abs(file_white - file_black)]
|
||
I sum(diff_list) > 2 | Set(diff_list) == Set([0, 2])
|
||
(brd[rank_white][file_white], brd[rank_black][file_black]) = (Char(‘K’), Char(‘k’))
|
||
L.break
|
||
|
||
F pawn_on_promotion_square(pc, pr)
|
||
I pc == ‘P’ & pr == 0
|
||
R 1B
|
||
E I pc == ‘p’ & pr == 7
|
||
R 1B
|
||
R 0B
|
||
|
||
F populate_board(&brd, wp, bp)
|
||
L(x) 0.<2
|
||
Int piece_amount
|
||
[Char] pieces
|
||
I x == 0
|
||
piece_amount = wp
|
||
pieces = :piece_list
|
||
E
|
||
piece_amount = bp
|
||
pieces = :piece_list.map(s -> s.lowercase())
|
||
L piece_amount != 0
|
||
V (piece_rank, piece_file) = (random:(0 .. 7), random:(0 .. 7))
|
||
V piece = random:choice(pieces)
|
||
I brd[piece_rank][piece_file] == ‘ ’ & pawn_on_promotion_square(piece, piece_rank) == 0B
|
||
brd[piece_rank][piece_file] = piece
|
||
piece_amount--
|
||
|
||
F fen_from_board(brd)
|
||
V fen = ‘’
|
||
L(x) brd
|
||
V n = 0
|
||
L(y) x
|
||
I y == ‘ ’
|
||
n++
|
||
E
|
||
I n != 0
|
||
fen ‘’= String(n)
|
||
fen ‘’= y
|
||
n = 0
|
||
I n != 0
|
||
fen ‘’= String(n)
|
||
fen ‘’= I fen.count(‘/’) < 7 {‘/’} E ‘’
|
||
fen ‘’= " w - - 0 1\n"
|
||
R fen
|
||
|
||
V (piece_amount_white, piece_amount_black) = (random:(0 .. 15), random:(0 .. 15))
|
||
place_kings(&board)
|
||
populate_board(&board, piece_amount_white, piece_amount_black)
|
||
print(fen_from_board(board))
|
||
L(x) board
|
||
print(‘[’x.map(c -> ‘'’c‘'’).join(‘, ’)‘]’)
|