1 Utility for Games +- HP Forums (http://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: HP Prime Software Library (/forum-15.html) +--- Thread: 1 Utility for Games (/thread-516.html) |
1 Utility for Games - patrice - Yesterday 12:46 PM This utility is aimed to games with levels, but can have other usages. The goal is to save space in source code. Usually in games with levels, there is a map per level. It is common to describe the levels as a matrix which is not space efficient in source code. Encoding the map in a string and using the RLE simple minded compression can do dramatic savings. String codes ! can be used for end of code (last char in string) $ is for a new line . is the default value (background), usually it is 0 in the matrix letters are used to describe the diff parts of the map Exemple with ArielPalazzesi's Sokoban $ encode a new line in matrix . encode 0 the background w encode 1 the Walls c encode 2 a Cube d encode 3 a Destination s encode 4 Sokoban (the pusher) First is a matrix to string conversion and reverse Code: EXPORT m2s(Mt) Code: matriz := [ [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,1,1,1,4,0,1,1,0,0,0,0,0,0],[0,0,0,0,0,0,0,1,0,2,2,0,0,1,0,0,0,0,0,0],[0,0,0,0,0,0,0,1,0,0,2,0,0,1,0,0,0,0,0,0],[0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0],[0,0,0,0,0,0,0,1,1,1,0,0,1,1,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,1,3,3,3,1,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] ]; Code: St:=m2s(matriz); Code: "$$$........wwww$......wwws.ww$......w.cc..w$......w..c..w$......w.....w$......www..ww$........w...w$........wdddw$........wwwww$$$$" Code: St:="$$$........wwww$......wwws.ww$......w.cc..w$......w..c..w$......w.....w$......www..ww$........w...w$........wdddw$........wwwww$$$$"; And with the RLE compression on fly Code: NTOS(Cnt) Code: St:=RLEEnc(matriz); Nota: numbers are reserved for the RLE compression RLE compression is simple enough that one can encode a map by hand. |