-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchessmaster960.lua
More file actions
33 lines (27 loc) · 785 Bytes
/
chessmaster960.lua
File metadata and controls
33 lines (27 loc) · 785 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
-- luacheck: globals event mainmemory
local chess960 = require('chess960')
local BOARD_BLACK_START_ADDR = 0x100
local BOARD_WHITE_START_ADDR = 0x170
local OPENING_BOOK_SETTING = 0x070C
local PIECES = {
['P'] = 0,
['K'] = 1,
['R'] = 3,
['N'] = 2,
['B'] = 4,
['Q'] = 5,
}
local function set_board(board)
for i = 1, 8 do
local piece = PIECES[string.sub(board, i, i)]
mainmemory.write_u8(BOARD_BLACK_START_ADDR + i - 1, piece | 0x20)
mainmemory.write_u8(BOARD_WHITE_START_ADDR + i - 1, piece | 0x10)
end
end
event.on_bus_exec(function()
local board = chess960.random_start_position()
set_board(board)
end, 0xC279)
-- appears to be useless setting, but turn it off anyways
mainmemory.write_u8(OPENING_BOOK_SETTING, 0x00)
math.randomseed(os.time())