Compress the pool files

This commit is contained in:
Empathic Qubit 2021-03-06 08:53:37 -05:00
parent 4252b66c03
commit 438df48497
4 changed files with 3548 additions and 5 deletions

2
.gitignore vendored
View file

@ -3,4 +3,4 @@ catchem/
state/
crashsave*
*.backup
*.pool
*.pool*

3525
LibDeflate.lua Normal file

File diff suppressed because it is too large Load diff

View file

@ -23,8 +23,12 @@ An AI based on SethBling's MarI/O to play Donkey Kong Country 2 with lsnes.
9: Restart
## Notes
Only tested on Pirate Panic
* Only tested on Pirate Panic
* The pool files are gzipped json
## 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)

View file

@ -3,6 +3,7 @@
local base = string.gsub(@@LUA_SCRIPT_FILENAME@@, "(.*/)(.*)", "%1")
local json = dofile(base.."/dkjson.lua")
local libDeflate = dofile(base.."/LibDeflate.lua")
local config = dofile(base.."/config.lua")
local spritelist = dofile(base.."/spritelist.lua")
local game = dofile(base.."/game.lua")
@ -906,9 +907,22 @@ function mainLoop (species, genome)
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)
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()
return
end
@ -960,7 +974,7 @@ function loadFile(filename, after)
return
end
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
statusLine = string.format("Error parsing: %s", err)
statusColor = 0x00990000