|Pathologically Eclectic Rubbish Lister|
Representing Complex but Static Data in Perlby cyocum (Curate)
|on Apr 07, 2005 at 09:46 UTC||Need Help??|
cyocum has asked for the
wisdom of the Perl Monks concerning the following question:
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:
I get this:
This forces me to do this:
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.