Assignment 4: A Freer FreeCell
Due: Fri 10/14 at 8:59pm; self-evaluation due Sat 10/15 at 8:59pm
Starter files: code.zip
1 Purpose
In this assignment we will reap the fruits of our design, by introducing a new variant in the game of Freecell: the ability to move several cards at once. You will see how your earlier design of this program will facilitate adding this feature with (hopefully) minimal change in code.
All new classes and interfaces for this homework should be in the
cs3500.hw04
package. All classes written in previous assignments, even
if improved upon, should remain in their respective packages.
We are giving you a starter file whose sole purpose is to ensure your code is in the correct packages with the correct visibility.
2 Multi-move Freecell
A more realistic version of Freecell is one where the player can move several cards at once from one cascade pile to another (while it is also possible to move several cards from a cascade pile to a foundation pile, we will ignore this feature in this variation).
Moving multiple cards must obey two conditions. The first condition is that they should form a valid build, i.e. they should be arranged in alternating colors and consecutive, descending values in the cascade pile that they are moving from. The second condition is the same for any move to a cascade pile: these cards should form a build with the last card in the destination cascade pile.
It may be noted that the ability of moving cards (besides the two conditions above) is not a special feature, but a convenience to the player. A multi-card move is basically several single-card moves, using free open piles and empty cascade piles as “intermediate slots”. Thus a multi-card move may not be feasible even though it obeys the above two conditions, if there aren’t enough of these intermediate slots. More specifically, it can be proved that the maximum number of cards that can be moved when there are N free open piles and K empty cascade piles is (N+1)*2K. Your implementation of this variation should work within all these three conditions.
In order to use an empty cascade pile as an intermediary for multi-card moves, we will allow any card to move to an empty cascade pile (not just a king, as some Freecell versions mandate).
3 Design Constraints
In this assignment, you must introduce this new feature in your game while respecting the following constraints:
You are not allowed to change the controller interface (
IFreeCellController
) or implementation (FreeCellController
) at all from Assignment 3.You are not allowed to change the interface of the model (
IFreeCellModel<K>
) at all from Assignment 3.You must create a separate model implementation while keeping
FreeCellModel
from Assignment 3 unchanged. That is, models that represent both variations of the Freecell game (single and multiple card moves) must co-exist. You are free to name the model implementation whatever you like.You must provide a factory class
FreeCellModelCreator
, that works as specified below.
You may have to refactor your earlier design to do this. This is OK, but should be properly documented and justified. Again, you are not allowed to change existing interfaces or add new public methods.
4 The Free
Cell
Model
Creator
class
Write a class with the above name. The class should define a public enum
GameType
with two possible values SINGLEMOVE
and MULTIMOVE
. It should offer
a static factory method create(GameType type)
that returns either
a FreeCellModel
or an object of your multi-card-move model, depending on the value of
the parameter. HINT: Think carefully about the return type of this factory method.
5 Deliverables
Your new “multi-card move model” class
Your factory class
Your controller and model classes and related interfaces from Assignment 2 and Assignment 3 (possibly modified only to remove bugs and design limitations)
Tests for your multi-card move model and the related game in a JUnit test class. It is a good idea to include your earlier tests as well, for regression testing. We will.
All new classes and interfaces for this homework should be in the cs3500.hw04
package. All classes written in previous assignments, even if improved upon, should be in their own packages.
6 Grading standards
For this assignment, you will be graded on
Whether you had to modify any previously written interfaces,
whether your code implements the specifications (functional correctness),
the clarity of your code,
the comprehensiveness of your test coverage, and
how well you follow the style guide.
Please submit your homework to https://cs3500.ccs.neu.edu/ by the above deadline. Then be sure to complete your self evaluation by its deadline.