- Joined
- Mar 19, 2009
Ok so here's the problem,
I made a puzzle generator which generates grids based on tiles of various forms.
The first issue I encountered was that I had multiple generations of the same grid, and the only difference is that they are rotated by 90 degrees each
xxx | oxx | xxo | xxx
xxx | xxx | xxx | xxx
oxx | xxx | xxx | xxo
So at first i solved the problem generically by building a 2 dimensional array of bools, and calculating the hash for each side then combining it to get the overall hash
which would then be used in the puzzle hashmap.
The grid would be saved anyway in the puzzle data so in case of hash collisions it would do a cell by cell comparison for all 4 rotations.
I tried to generate all possible solutions, but it would just eat up all memory. So I implemented some generation rules so that not all puzzles would be saved.
I finished the work, but now I am wondering how I could optimize the problem even further.
So here is my current solution which I can't manage to implement correctly.
I noticed I didn't need puzzles with an area greater than 7x6 (so in total 42 cells) and if we treat a bool cell as a single bit the next thought that comes to mind is to map those bits to a number which would then be unique, if we calculate this Id for the 4 rotated puzzles and for example get the smallest one of those 4 ids it should be unique am I right?
By doing so I wouldn't need to hold the information of the grid, hell I wouldn't even create it and puzzle comparison would be a simple number comparison.
I have tried some approaches, but I am getting something wrong somewhere, is someone willing to help me? I am really curious to see by how much this optimization could speed things up <.<
I made a puzzle generator which generates grids based on tiles of various forms.
The first issue I encountered was that I had multiple generations of the same grid, and the only difference is that they are rotated by 90 degrees each
xxx | oxx | xxo | xxx
xxx | xxx | xxx | xxx
oxx | xxx | xxx | xxo
So at first i solved the problem generically by building a 2 dimensional array of bools, and calculating the hash for each side then combining it to get the overall hash
which would then be used in the puzzle hashmap.
The grid would be saved anyway in the puzzle data so in case of hash collisions it would do a cell by cell comparison for all 4 rotations.
I tried to generate all possible solutions, but it would just eat up all memory. So I implemented some generation rules so that not all puzzles would be saved.
I finished the work, but now I am wondering how I could optimize the problem even further.
So here is my current solution which I can't manage to implement correctly.
I noticed I didn't need puzzles with an area greater than 7x6 (so in total 42 cells) and if we treat a bool cell as a single bit the next thought that comes to mind is to map those bits to a number which would then be unique, if we calculate this Id for the 4 rotated puzzles and for example get the smallest one of those 4 ids it should be unique am I right?
By doing so I wouldn't need to hold the information of the grid, hell I wouldn't even create it and puzzle comparison would be a simple number comparison.
I have tried some approaches, but I am getting something wrong somewhere, is someone willing to help me? I am really curious to see by how much this optimization could speed things up <.<