1 Utility for Games
|
01-25-2014, 06:46 PM
(This post was last modified: 01-26-2014 02:13 AM by patrice.)
Post: #1
|
|||
|
|||
1 Utility for Games
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. Patrice “Everything should be made as simple as possible, but no simpler.” Albert Einstein |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
1 Utility for Games - patrice - 01-25-2014 06:46 PM
RE: 1 Utility for Games - cyrille de brébisson - 01-27-2014, 06:41 AM
RE: 1 Utility for Games - patrice - 01-27-2014, 07:50 AM
RE: 1 Utility for Games - Han - 03-11-2014, 03:18 PM
RE: 1 Utility for Games - patrice - 03-11-2014, 06:42 PM
RE: 1 Utility for Games - Han - 03-11-2014, 07:43 PM
RE: 1 Utility for Games - ArielPalazzesi - 01-27-2014, 11:25 PM
RE: 1 Utility for Games - patrice - 03-11-2014, 01:04 PM
RE: 1 Utility for Games - patrice - 03-11-2014, 08:42 PM
|
User(s) browsing this thread: 1 Guest(s)