Lua program "skitchinspeedometerpro.lua" (cannibalized from the Sonic speedometer):
-- simple skitchin' speedometer display
-- demonstrates reading memory and writing text,
-- as well as predicting future frames and reading memory from them
-- create space in memory for a savestate
state = savestate.create()
-- register a function to run when the screen gets updated
gui.register( function ()
-- get the X and Y velocity of the player
dist = memory.readwordsigned(0xff0736)
speed = memory.readbytesigned(0xff0768)
xpos = memory.readwordsigned(0xff0748)
xvel = memory.readbytesigned(0xff1541)
frames = memory.readbyteunsigned(0xff01fb)
health = memory.readwordunsigned(0xff077A)
skates = memory.readwordunsigned(0xff0002)
-- look 25 frames into the future and find if a jump is possible next frame
savestate.save(state)
gens.emulateframeinvisible()
joypad.set(1, {up = true})
joypad.set(1, {B = true})
joypad.set(1, {C = true})
i = 1
while i<25> 0) then
canjump = 1
else
canjump = 0
end
savestate.load(state)
-- print the velocities onscreen, near the top-right corner,
-- in a green color with a black outline
message = string.format("position: %d, %d", dist, xpos)
gui.text(210, 10, message, "#00FF00FF", "black")
message = string.format("velocity: %d, %d", speed, xvel)
gui.text(210, 18, message, "#00FF00FF", "black")
message = string.format("frames: %d", frames)
gui.text(180, 140, message, "#00FF00FF", "black")
message = string.format("%d", health)
gui.text(300, 185, message, "#00FF00FF", "black")
message = string.format("%d", skates)
gui.text(300, 193, message, "#00FF00FF", "black")
message = string.format("can jump: %d", canjump)
gui.text(100,140,message, "#00FF00FF", "black")
end)
I think that code is pretty self-explanatory, especially if you run it.
Matlab program "skitchin.m":
function skitchin(t)
frame = 35614;
x = 76107726;
v = 25447;
x_fin = 139500000;
nitro = 0;
v_max = 32255;
acc = 56; %per frame
coast = -4.3;
while x<x_fin> 0;
v = v + acc;
if v > v_max;
v = v_max;
end
nitro = nitro - 1;
else
v = v + coast;
end
x = x+v;
frame = frame+1;
end
frame
Matlab is my bread and butter, but I don't think anything is too difficult to understand for someone with a good background in programming. The only thing I feel the need to point out is that the input argument t is a
vector specifying the time(s) that I want to simulate using a nitro. The program's output is the projected time (in frames) to completion of the level. The values of acc and coast were derived empirically, although coast may vary somewhat from level to level. The values for frame, x, v, and x_fin all vary contextually; whenever I want to simulate a new level, I change the values of those variables manually. I then run the code several times until I find a global minimum. I could probably automate the minimization process, but it generally isn't too difficult.
Level maps:
Vancouver
---------
Oil - 214/139
Ramp - 247/210
CB Ramp - 296/216
Pipe -368/192
SL Ramp - 410/304
Gravel - 428/70
Crowbar - 510/212
Ramp - 558/210
Crowbar - 644/219
CB Ramp - 687/227
Bench - 729/363
SL Ramp - 761/285
Bench - 804/463
Nitro - 835/-632
Gravel - 841/91
SL Ramp - 865/321
Pipe - 951/183
Trash cans - 961/245
Bench - 964/410
Trash cans - 977/122
Trash cans - 995/260
Ramp - 1074/230
Ramp - 1150/222
Oil - 1165/142
Crowbar - 1270/191
Ramp - 1322/224
Gravel - 1344/-113
Crowbar - 1495/199
Ramp - 1525/209
Denver
------
Ramp - 168/-220
Oil - 181/20
CB Ramp - 304/-215
SL Ramp - 367/327
Slow Ahead - 394/-225
Potholes - 403/-226
Slow Ahead - 423/-234
Ramp - 458/-186
Oil - 467/0
Gravel - 523/-91
Crowbar - 576/-214
Slow Ahead - 633/265
Slow Ahead - 653/265
Ramp - 681/190
Nitro - 687/179
Truck - 693/Right
Oil - 737/-68
CB Ramp - 774/215
Ramp - 867/214
Intersection - 937
Oil - 961/-120
Ramp - 977/211
Gravel - 1017/83
Intersection - 1048
Mound - 1089/200
Chain - 1096/160
Barriers - 1102/Right
Oil - 1141/34
SL Ramp - 1144/296
Ramp - 1208/150
Boxcar - 1220/202
Gravel - 1268/-150
Pipe - 1311/123
Gravel - 1312/-127
Cones and Potholes - 1319/Right
Oil - 1374/-120
Intersection - 1376
Nitro - 1432/-200
Intersection - 1453
Gravel - 1468/100
Ramp - 1492/-224
San Diego
---------
Intersection - 140
Intersection - 179
Intersection - 320
Nitro - 432/-196
SL Ramp - 518/319
Intersection - 560
Intersection - 600
Oil - 645/210
Intersection - 680
Intersection - 720
Crowbar - 800/-270
RW Sign - 821/-272
Mound - 839/-186
Truck - 850/Left
Pipe - 893/-207
Intersection - 899
CB Ramp - 922/-174
Intersection - 939
CB Ramp - 994/-162
Barriers - 1047/Left
Intersection - 1080
Gravel - 1104/-87
Gravel - 1130/-150
Intersection - 1200
Pipe - 1206/196
Oil - 1242/128
Intersection - 1280
Ramp - 1304/230
Oil - 1308/-60
Intersection - 1360
Mound - 1391/200
Bat - 1399/124
Open MH - 1404/165
Intersection - 1420
Intersection - 1475
Gravel - 1497/-140
Intersection - 1540
Seattle
-------
Gravel - 110/-148
Oil - 193/70
Gravel - 274/-115
Nunchuks - 474/-220
Washington
----------
Oil - 102/40
Oil - 167/73
Nitro - 179/265
Oil - 251/61
Cones - 304/left
Split road - 313 to 388
Oil - 317/130
Mound - 333/-210
Oil - 337/143
Barriers - 338/left
Oil - 354/111
Nunchuks - 361/-265
Oil - 383/115
Nitro - 386/55
Barriers - 388/left
Oil - 416/-40
Gravel - 412/301
Gravel - 443/-70
Gravel - 457/250
Gravel - 465/-55
Gravel - 469/120
Gravel - 527/-85
Oil - 571/-82
Gravel - 582/120
Pothole - 633/-197
Gravel - 648/120
Gravel - 664/-123
Nitro - 665/248
Gravel - 674/90
Gravel - 708/94
Oil - 716/-53
Gravel - 729/100
Gravel - 805/-147
Bat - 814/-215
Gravel - 895/-80
Oil - 913/-36
Pothole - 930/-220
Nitro - 958/78
SL ramp - 961/304
Pothole - 982/-206
Gravel - 1008/-72
Oil - 1055/53
Crowbar - 1106/-229
RW sign - 1118/-21
RW sign - 1127/-21
Divided road - 1137 to 1292
Oil - 1183/-44
Gravel - 1200/-119
Chain - 1210/166
Pothole - 1315/250
SL ramp - 1363/328
Toronto
-------
Gravel - 191/-5
Nitro - 258/180
SL Ramp - 713/329
Speed Bump - 1064
Nitro - 1129/177
Speed Bump - 1211
Ramp - 1267/-160
Speed Bump - 1387
Nitro - 1461/256
Speed Bump - 1803
End - 2128 (139500000)
Detroit
-------
Nitro - 365/290
Nitro - 642/-290
Slow Ahead - 788/190
Nitro - 817/381
Mound - 875/170
Nitro - 901/66
Slow Ahead - 918/-370
Slow Ahead - 1018/-346 (fool's gold!)
Slow Ahead - 1197/-121
Slow Ahead - 1243/-140
Mound - 1287/-168
SL Ramp - 1304/324 (choose between mound and SL ramp)
Ramp - 1341/-197
Mound - 1347/-191 (choose between ramp and mound)
Ramp - 1379/-194 (can't jump truck)
SL Ramp - 1555/326
SL Ramp - 1614/341
End - 2128 (139500000)
Chicago
-------
Speed Bump - 205
SL Ramp - 348/314
Speed Bump - 412
SL Ramp - 500/316
Speed Bump - 541
Nitro - 615/205
Speed Bump - 634
Speed Bump - 741
Heap - 789/-331
Miami
-----
Nitro - 306/-185
SL Ramp - 938/310
SL Ramp - 1068/329
SL Ramp - 1322/320
Nitro - 1406/-220
SL Ramp - 1704/???
Nitro - 1715/-212
SL Ramp - 1724/324
SL Ramp - 1894/329
Mound - 2381/191
Nitro - 2427/481
Nitro - 2464/506
Nitro - 2650/-700
Nitro - 2671/-707
End - 2895 (18960625)
New York
--------
Nitro - 147/260
SL Ramp - 160/314
SL Ramp - 250/311
SL Ramp - 362/307
SL Ramp - 558/307
SL Ramp - 649/315
Nitro - 725/-217
Nitro - 1061/252
Slow Ahead - 1550/-307
Slow Ahead - 1556/-246
Slow Ahead - 1566/-191
Slow Ahead - 1584/-131
Slow Ahead - 1600/-60
Nitro - 1618/-294
Slow Ahead - 1621/-64
Slow Ahead - 1639/-53
Nitro - 1708/-203
Slow Ahead - 1860/135
Mound - 1875/197
Slow Ahead - 1881/128
Nitro - 1980/-270
Heap - 2035/-300
Heap - 2115/-306 (may be difficult to catch)
Heap - 2311/-306
Heap - 2368/-323
Heap - 2447/312
Nitro - 2529/-263
Heap - 2585/-309
Heap - 2622/-312
Slow Ahead - 2700/317
Slow Ahead - 2729/150
Heap - 2842/327
Nitro - 2898/239
Heap - 2970/277
End - 2992 (196121868)
Speed Bonus (Vancouver, Toronto, and Miami)
-------------------------------------------
Nitro - 266/-212
Nitro - 595/50
Cattle Prod - 653/763
Nitro - 888/-197