-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.lua
65 lines (52 loc) · 1.45 KB
/
game.lua
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
config = require "config"
local _M = {}
function _M.getPositions()
currentX = memory.readbyte(0x0040)
currentY = memory.readbyte(0x0041)
end
function _M.getScore()
local scoreLeft = tonumber(string.format("%x", memory.readbyte(0x0055)))
local scoreMiddle = tonumber(string.format("%x", memory.readbyte(0x0054)))
local scoreRight = tonumber(string.format("%x", memory.readbyte(0x0053)))
local score = scoreLeft*10000 + scoreMiddle*100 + scoreRight
local state = memory.readbyte(0x0048)
return score, state
end
function _M.getTile(x, y)
return memory.readbyte(0x0400 + y*0x000A + x)
end
function _M.getInputs()
_M.getPositions()
local inputs = {}
local inputDeltaDistance = {}
inputs[#inputs+1] = currentX
inputs[#inputs+1] = currentY
inputs[#inputs+1] = memory.readbyte(0x0042)
inputs[#inputs+1] = memory.readbyte(0x00BF)
inputDeltaDistance[#inputDeltaDistance+1] = 1
inputDeltaDistance[#inputDeltaDistance+1] = 1
inputDeltaDistance[#inputDeltaDistance+1] = 1
inputDeltaDistance[#inputDeltaDistance+1] = 1
for dy=0,19,1 do
string = ""
for dx=0,9,1 do
val = _M.getTile(dx, dy)
if val == 239 then
val = 0
else
val = 1
end
inputs[#inputs+1] = val
inputDeltaDistance[#inputDeltaDistance+1] = 20 - dy*.05
end
end
return inputs, inputDeltaDistance
end
function _M.clearJoypad()
controller = {}
for b = 1,#config.ButtonNames do
controller["P1 " .. config.ButtonNames[b]] = false
end
joypad.set(controller)
end
return _M