-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
52 lines (38 loc) · 1.09 KB
/
Copy pathmain.lua
File metadata and controls
52 lines (38 loc) · 1.09 KB
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
--need to implement websocket
--main lua script to talk to python
--#region script setup (variables, client to server connection)
console.log('Init')
--read and store two main bytes for position (x-coordinate of camera)
position = mainmemory.read_u16_be(0xEE00)
--"score" of AI-player, used for feedback
fitness = 0
--#endregion
--#region movement functions
function holdingRight (holding)
joypad.set({Right=holding}, 1)
end
function holdingLeft ()
joypad.set({Left=holding})
end
function holdingJump()
joypad.set({A=holding})
end
--update fitness score
function updateFitness ()
fitness = position
end
--#endregion
--#region main
while true do
position = mainmemory.read_u16_be(0xEE00)
--only update fitness when we get further than previous
if position > fitness then
updateFitness()
end
--gui text for reading information
gui.text(50, 150, 'Position ' .. tostring(position))
gui.text(50, 200, 'Fitness ' .. tostring(fitness))
--make emulator go to next frame (rather than waiting for script to end)
emu.frameadvance()
end
--#endregion