Fellow monks, this weeks feels like cyocum stupid question week but I cannot think of a more elegant way of doing this so I am asking your advice.
I am writing a chess program as some of you may remember (the code in there right now is very sub-optimal and I am thinking about trashing it and starting over so beware if you check out the code). One of the big probelms that is slowing it down is move generation so I determined to preprocess all valid moves for all peices and store them so that the piece objects can share the data. The preprocessing is now finished and I have moved on to the next step, which is representing this the best way in Perl code.
I figure that a hash of hashes with the value being an anonymous array of arrays with all the valid moves contained in them. Now, my problem is how to best represent this.
if I do this:
use strict; use warnings; #row #col #list of list of valid moves our %hash = (0 => 0 => [[[1, 0],[2, 0],[3, 0],[4, 0],[5, 0],[6, 0],[7, + 0]], [[0, 1],[0, 2],[0, 3],[0, 4],[0, 5],[0, 6],[0, 7]]]);
I get this:
Odd number of elements in hash assignment
This forces me to do this:
use strict; use warnings; our %hash; $hash{0}->{0} = [[[1, 0],[2, 0],[3, 0],[4, 0],[5, 0],[6, 0],[7, 0]], [[0, 1],[0, 2],[0, 3],[0, 4],[0, 5],[0, 6],[0, 7]]];
This works but is ugly and does not really give the reader an indication that this is a shared piece of data that never changes. If I were doing this in C/C++, I would make it all const.
Any ideas or examples of how to make this look better would be highly appreciated. As always, thank you all for your time and effort.
In reply to Representing Complex but Static Data in Perl by cyocum
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |