|
CS 391 Selected Topics: Game AI Homework #2 |
Due Thursday 2/4 at the beginning of class.Note: This work is to be done in groups of 2. Each group will submit one assignment. Although
you may divide the work, both team members should be able to present/describe
their partner's work upon request.
FreeCellNode
- Create a search node implementation for FreeCell that makes use of the
supplied Card and Shuffle classes to allow the initialization and play of
any Microsoft Freecell shuffle.
- Specifications for children expansion:
- When printing solutions, follow the
notation of the
FreeCell solutions site.
- Allow
supermoves.
- Implement safe autoplay to the foundation initially (upon
construction) and after each play according to NetCELL's safe autoplay
rules. From the
FreeCell FAQ:
-
A deal where all of the cards go home at the start is easy to
construct, but it is fantastically unlikely for such a deal to occur
at random, since Microsoft FreeCell or FreeCell Pro only plays an
available card to its homecell automatically when all of the
lower-ranked cards of the opposite color are already on the
homecells (except that a two is played if the corresponding ace is
on its homecell); aces are always played when available. This is one
version of what can be called safe
autoplay.
NetCELL uses a more aggressive rule, making all of the plays that MS
FreeCell makes, but also playing an available card if both homecells
of the opposite color are within two ranks of that card and the
homecell of the same color and opposite suit is within three ranks.
For example, in NetCELL 28865-5, the four of diamonds is played as
soon as the three of diamonds, both black twos, and the ace of
hearts are on the homecells. The reason for this is that the four of
diamonds is not needed on the tableau to hold either black three,
since both can go to their homecells as soon as they are available,
and the black threes are not needed to hold the two of hearts, since
it can also go to its homecell as soon as it is available. (NetCELL
plays as many cards as possible under this rule as soon as the cards
are dealt; MS FC and FCPro don't do anything until the player moves
the first card).
- If there is more than one free
cell, play to the leftmost cell only.
- If there is more than one empty cascade, play to the
leftmost empty cascade only.
It appears that the convention for a supermove to
an empty column is to move as many cards as possible. “All moves to
empty columns are column moves rather than single card moves.” (http://www.solitairelaboratory.com/solutioncatalog.html)
Presumably this does not disallow
solutions because any solution that requires a lesser card movement
could be replicated through other legal moves (e.g. single card moves in
the worst case). Thus a
column move “ij” where j is empty is presumed to be a maximal movement
of cards from i to j.
- It will be advantageous to override the hashcode method
for your node to create an int key to help with repeated state checking.
One way to do this is to define a toString method (highly recommended) and
have hashcode return toString().hashcode(). Collisions are possible,
... but are they probable?
- For different powers of 10 (until either out of default
Java memory or exceeding 2 minutes), generate and store that many random
FreeCell nodes and record the time and max size of the process.
- Call System.currentTimeMillis() before and after the
generation of nodes and compute the difference. Report results in
milliseconds.
- Store generated nodes in an ArrayList.
- Generate nodes as follows: Generate a random seed in
the range 1-1,000,000 and use it to create an initial shuffle with that
seed. Create and store the root node. While the node expansion
generates children, pick a random child, store it, and repeat for its
children. Do this for a maximum of 50 iterations or until there
are no moves, then repeat with a new random seed until the desired
number of nodes have been generated.
- Sample testing
code
- Plot the growth in time and space (e.g. using a
spreadsheet program) using reasonable scales (e.g. log-log, semi-log,
etc.).