Compress the pool files
This commit is contained in:
parent
4252b66c03
commit
438df48497
4 changed files with 3548 additions and 5 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -3,4 +3,4 @@ catchem/
|
||||||
state/
|
state/
|
||||||
crashsave*
|
crashsave*
|
||||||
*.backup
|
*.backup
|
||||||
*.pool
|
*.pool*
|
||||||
|
|
3525
LibDeflate.lua
Normal file
3525
LibDeflate.lua
Normal file
File diff suppressed because it is too large
Load diff
|
@ -23,8 +23,12 @@ An AI based on SethBling's MarI/O to play Donkey Kong Country 2 with lsnes.
|
||||||
9: Restart
|
9: Restart
|
||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
Only tested on Pirate Panic
|
* Only tested on Pirate Panic
|
||||||
|
* The pool files are gzipped json
|
||||||
|
|
||||||
## Credits
|
## Credits
|
||||||
|
|
||||||
A lot of basic info came from [Donkey Hacks](http://donkeyhacks.zouri.jp/html/En-Us/dkc2/index.html), the NEAT A/I comes from [SethBling's Mar I/O](https://github.com/mam91/neat-genetic-mario), and basic information about the tilemap came from [p4plus2/DKC2-disassembly](https://github.com/p4plus2/DKC2-disassembly)
|
* [Donkey Hacks](http://donkeyhacks.zouri.jp/html/En-Us/dkc2/index.html)
|
||||||
|
* [SethBling's Mar I/O](https://github.com/mam91/neat-genetic-mario)
|
||||||
|
* [Basic tilemap info from p4plus2/DKC2-disassembly](https://github.com/p4plus2/DKC2-disassembly)
|
||||||
|
* [dkjson](http://dkolf.de/src/dkjson-lua.fsl/home)
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
local base = string.gsub(@@LUA_SCRIPT_FILENAME@@, "(.*/)(.*)", "%1")
|
local base = string.gsub(@@LUA_SCRIPT_FILENAME@@, "(.*/)(.*)", "%1")
|
||||||
|
|
||||||
local json = dofile(base.."/dkjson.lua")
|
local json = dofile(base.."/dkjson.lua")
|
||||||
|
local libDeflate = dofile(base.."/LibDeflate.lua")
|
||||||
local config = dofile(base.."/config.lua")
|
local config = dofile(base.."/config.lua")
|
||||||
local spritelist = dofile(base.."/spritelist.lua")
|
local spritelist = dofile(base.."/spritelist.lua")
|
||||||
local game = dofile(base.."/game.lua")
|
local game = dofile(base.."/game.lua")
|
||||||
|
@ -906,9 +907,22 @@ function mainLoop (species, genome)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function bytes(x)
|
||||||
|
local b4=x%256 x=(x-x%256)/256
|
||||||
|
local b3=x%256 x=(x-x%256)/256
|
||||||
|
local b2=x%256 x=(x-x%256)/256
|
||||||
|
local b1=x%256 x=(x-x%256)/256
|
||||||
|
return string.char(b1,b2,b3,b4)
|
||||||
|
end
|
||||||
|
|
||||||
function writeFile(filename)
|
function writeFile(filename)
|
||||||
local file = io.open(filename, "w")
|
local file = io.open(filename, "w")
|
||||||
file:write(json.encode(pool))
|
local json = json.encode(pool)
|
||||||
|
local zlib = libDeflate:CompressDeflate(json)
|
||||||
|
file:write("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x00")
|
||||||
|
file:write(zlib)
|
||||||
|
file:write(string.char(0,0,0,0))
|
||||||
|
file:write(bytes(#json % (2^32)))
|
||||||
file:close()
|
file:close()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -960,7 +974,7 @@ function loadFile(filename, after)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local contents = file:read("*all")
|
local contents = file:read("*all")
|
||||||
local obj, pos, err = json.decode(contents)
|
local obj, pos, err = json.decode(libDeflate:DecompressDeflate(contents:sub(11, #contents - 8)))
|
||||||
if err ~= nil then
|
if err ~= nil then
|
||||||
statusLine = string.format("Error parsing: %s", err)
|
statusLine = string.format("Error parsing: %s", err)
|
||||||
statusColor = 0x00990000
|
statusColor = 0x00990000
|
||||||
|
|
Loading…
Add table
Reference in a new issue