In the next (and final) lab assignment for the course you will build on these features to allow a user to play a multi-player version of the game, with other live and/or artificial players.
Note: the details of this assignment are again intentionally somewhat under-specified, leaving you some room to choose what you think is the best way to implement them, as long as what you do is reasonable and you explain your design decisions in comments in the code and in your Readme.txt file.
//, like the first two lines
of the following sorted_dictionary_example.txt file.
direction that sequence of
letter tiles can be played, that can have either of two values:
vertical or horizontal.
GameBoard with a private
member variable that represents a 15 by 15 grid of squares, where each square can have
0 or 1 letter tiles associated with it, and the squares are indexed in the vertical
and horizontal dimensions with (0,0) denoting the center of the board,
(-7,-7) denoting the bottom left corner of the board,
(-7,7) denoting the top left corner of the board,
(7,7) denoting the top right corner of the board, and
(7,-7) denoting the bottom right corner of the board.
How you implement the member variable is up to you, but one idea is to use an STL
container whose key type is an STL pair of integers and whose data type is a pointer
to a letter tile (so that empty squares can be denoted by the pointer being 0), e.g.,
of type map<pair<int,int>,LetterTile*> >.
The public interface for this class should be:
765432101234567
7 7
6 6
5 5
4 4
3 SAY 3
2 L 2
1 WOULD 1
0 HELLO 0
1 ARE 1
2 L 2
3 D 3
4 4
5 5
6 6
7 7
765432101234567
play method that takes a reference to a const dictionary object
(as defined in the previous lab assignment), a reference to a const letter
tile collection object, a pair of integers representing the starting position
from which to play the tiles, and a
variable of the enumerated direction
type; plays the sequence of tiles on
the board according to those inputs,
and returns an unsigned integer indicating the number of points the user
earned for that play.Note that unlike the main method, the return value for this method indicates the score given for the play, so that if an error occurs the method should (after printing out an appropriate error message) return 0 to indicate no points were earned.
The first play on an empty board must intersect with the square 0,0 and any play on a non-empty board must intersect with at least one existing tile (if not, the method should generate an error message and return 0).
Assuming the above conditions hold, the method should check for a valid play as follows:
play method
should concatenate the
sequence of letter tiles that will
occur if the play is successful. To do that,
the method should check the
squares of the board in the direction
given: from left to right (a correction:
this used to say "to the left") for horizontal, and
downwards for vertical. If a square
is empty, the method should concatenate
a copy of the next unused tile from the sequence
that was given, or if the square already
has a tile in it the method should
concatenate a copy of that tile.
print method above had been the
sequence "AE" starting at position 0,
-1 and proceeding horizontally, the
method would have seen an empty square at
position 0, -1 and played the 'A' tile
there, seen the existing 'R' at
position 1, -1 and used it, and seen an
empty square at position 2, -1 and
played the 'E' tile there, resulting in
the new sequence "ARE" (and also the new
perpendicular sequence "LA").
play method should print
out an error message and return 0.
print method above had been "ARE"
then the dictionary would need to check both
the new sequence "ARE" and the new
perpendicular sequence "LA".
Dictionary
object in your main function.
LetterTileCollection object in your main function. This object will
again serve as a pool of tiles from which other collections can be drawn.
LetterTileCollection object in your main function, which will
serve as the set of tiles used by the person playing the game (the player).
GameBoard object (the board) in
your main function.
Send the zip file containing your lab 4 solution as an e-mail attachment to the course e-mail account (cse332@cec.wustl.edu) by the submission deadline for this assignment. If you need to make changes to your lab solution you are welcome to send a new zip file, and we will grade the latest one received prior to the deadline (according to the time stamp the server puts on the e-mail).