R
Richard Cornford
Thanks for the feedback, and code on this one. Quite
honestly, it didn't occur to me that speed would be an
issue when I first approached this.
Thinking about what you are doing I suspect that speed isn't so much an
issue as a fatal problem.
Once I ran the code a few times, I realized that
more complex arrays were taking HOURS to run, and started
re-evaluating the code and my approach in general.
Given that you have up to 42 items with apparently 7 or so values per
item the possible total number of permutations gets so large that you
might be talking lifetimes to run rather than just hours.
Long-term, I'm working on an ajax-based Monopoly game.
At the moment, I'm focusing on some basic AI for the game.
I have relative values for each configuration of a property
in the game of Monopoly. (e.g., what is Boardwalk with 2
houses worth, long term, as opposed to Park Place with two
houses).
I gather that the board game 'Monopoly' originated in the Unites States.
Here in the UK the game uses locations in London, so we may talk about
Whitechapel and Mayfair in place of Boardwalk and Park Place, but at
least the concept of the game should be familiar to most Britons. I
gather that the game didn't catch on at all in Canada, and I don't know
about France, Denmark, the Netherlands or the rest of the world. That
may represent a problem when asking for help in an international
newsgroup as many potentially useful contributors will not automatically
be familiar with the concepts of the game.
In this project, I've created a form, where a player can
enter all the properties they own, and their current
state (e.g., mortgaged, unmortgaged, 3 houses, a hotel,
etc.), and how much cash the player has on hand.
Interesting. When I played Monopoly (and it has been quite a few years
since I last did) I recall the position of all of the other players
playing a big role in my decision making.
So if another player is 7 squares short of a property of yours on which
you can build, and he/she is cash poor so they will suffer
disproportional at having to pay a rent that exceeds their available
cash, then it may be worth risking excessive spending to build on that
property (and maybe adjacent properties) because having to roll two dice
gives then at least a one in six chance of taking that hit.
I also recall that one of the strategies I used when playing Monopoly
was to keep an accurate mental tally of how much money I, and all of the
other players, had at any time, but to keep my own cash in a loose heap
(with the bigger denominations nonchalantly concealed at the bottom of
the heap) so that none of the other players had an accurate idea of how
much money I had and they tended to assume that I had less cash than I
really did (unless they bothered to keep their own mental tally). As a
strategy it worked quite well, and eventually resulted in my siblings
resolving to never play Monopoly with me again (and they haven't).
I'm then running through all the various options
they have available to them (e.g., mortgage one property
to get cash, then build on another). I'm then calculating
the relative value of that complete configuration and
comparing them. So, yes, I'm actually running some calculations
based on each array. At the end, I tell the player their best
possible option. Pretty straightforward, but my approach had been
to run through all the permutations. It's taking far too long,
when a player owns more than one Monopoly, so I'm open to any
ideas you may have.
You are going to have to quickly prune out entire classes of possible
permutations, but you have not provided any details of your decision
making algorithm so it is impossible to judge what might represent a
class of permutations, let alone how they may quickly be eliminated form
consideration.
Let me see if I can follow your code samples, and see how it
performs in the context of my script.
Whatever happens it won't be good enough. Once the number of
permutations is in the billions it doesn't matter if the algorithm is 10
or 100 times faster the user is still not going to hang around waiting
for the result.
Richard.