CS246留学生程序讲解、辅导Java,Python编程语言、CS编程辅导
- 首页 >> Matlab编程 CS246 FALL 2020 PROJECT – CONSTRUCTOR CS246, FALL 2020
• DO NOT EVER SUBMIT TO MARMOSET WITHOUT COMPILING AND TESTING FIRST. If your final
submission doesn’t compile, or otherwise doesn’t work, you will have nothing to show during your demo. Resist
the temptation to make last-minute changes. They probably aren’t worth it.
• This project is intended to be doable by three people in two weeks. Because the breadth of students’ abilities in
this course is quite wide, exactly what constitutes two weeks’ worth of work for three students is difficult to nail
down. Some groups will finish quickly; others won’t finish at all. We will attempt to grade this assignment in
a way that addresses both ends of the spectrum. You should be able to pass the assignment with only a modest
portion of your program working. Then, if you want a higher mark, it will take more than a proportionally
higher effort to achieve, the higher you go. A perfect score will require a complete implementation. If you
finish the entire program early, you can add extra features for a few extra marks.
• Above all, MAKE SURE YOUR SUBMITTED PROGRAM RUNS. The markers do not have time to examine
source code and give partial correctness marks for non-working programs. So, no matter what, even if your
program doesn’t work properly, make sure it at least does something.
1 The Game of Constructor
In this project, you will implement the game Constructor, which is a variant of the game Settlers of Catan (often called Settlers
for short), with the board being based on the University of Waterloo. If you are unfamiliar with Settlers, please see https:
//www.youtube.com/watch?v=8Yj0Y3GKE40 or https://www.catan.com/service/game-rules for an
overview. It may also be beneficial to play a game or two of Settlers to become familiar with the gameplay. Note that the rules
of Constructor vary from the rules of Settlers.
1.1 Gameplay Overview
You have recently decided that you are going to become a housing developer in Waterloo. You want to build housing for
the many students who attend the University. There are three different types of residences you can build. For each residence
built, you will earn a building point towards winning the game. Aside from that, residences will influence which materials
you receive, and where you and other builders will be able to build in the future.
During the setup of the game, each player selects starting vertices. Once the game begins, each builder takes turns rolling
the dice to determine which tiles produce resources. After rolling, the builder who rolled the dice has the opportunity to build
roads and residences using their resources.
The goal of the game is to be the first of the four players to obtain 10 (or more) building points.
2 Game Components
2.1 Board
The board is the visual representation of the state of the current game (see Figure 3 for a sample). The board will always
display the 19 tiles present in the game, all edges and vertices, and the roads and residences the builders have completed. The
representation for each of these components is described in their respective sections.
Page 1 of 12
CS246 FALL 2020 PROJECT – CONSTRUCTOR CS246, FALL 2020
2.2 Tiles
Each tile, displayed as a rectangle on the board, represents one type of resource in the game. The middle of each tile lists the
tile number, the type of resource and the tile value, in this order. In Figure 1, the tile number is 9, the resource is BRICK and
the tile value is 2. The tile number refers to where the tile is on the board. The tile value is used to determine which resources
are allocated when the dice are rolled (discussed later). Additionally, if geese (See Section 2.3) are present on the tile, it will
be displayed as in Figure 2. The outline of each tile is composed of the edges and vertices surrounding it.
There are 6 types of tile: BRICK, ENERGY, GLASS, HEAT, WIFI, and PARK. The Resources section (3.5) discusses
how resources and values are distributed. The PARK tile produces no resources.
Figure 1: Sample Tile
2.3 Geese
A tile can be overrun with geese, which play a similar role to that of the robber in the original game. In the event that a tile
has been overrun by geese, builders will not receive resources when the value matching the tile is rolled.
2.4 Vertices
A vertex is located at each corner and in the middle of each vertical edge of each tile. Each tile has 6 vertices. Note that most
vertices are shared by multiple tiles.
In Figure 1, the vertices are numbers 20, 21, 26, 27, 32, and 33.
2.4.1 Housing Details
A residence can be built at a vertex. Only one builder can build at each vertex. Each vertex can have at most one of 3 types
of residences on it. Once a builder has built a residence, they can improve the residence twice. When a residence is built, the
display is updated by replacing the vertex with the first character of the colour of the owner, e.g. ‘B’ for “Blue”, followed by
the first character of the name of the improvement, e.g. ‘B’ for “Basement”.
Housing must be built in the following order:
CS246 FALL 2020 PROJECT – CONSTRUCTOR CS246, FALL 2020
Basement (B) Building a basement gives the builder one resource when the value of any adjacent tile is rolled. When
acquired, a basement gives the owner one building point. A basement costs one BRICK, one ENERGY, one GLASS,
and one WIFI to build.
House (H) Building a house gives the builder two resources when the value of any adjacent tile is rolled. When acquired, a
house gives the builder one additional building point (2 in total). A house costs two GLASS, and three HEAT to build.
Tower (T) Building a tower gives the builder three resources when the value of any adjacent tile is rolled. When acquired,
a tower gives the builder one additional building point (3 in total). A tower costs three BRICK, two ENERGY, two
GLASS, one WIFI and two HEAT to build.
If a vertex currently has no residence on it, then a builder may construct a Basement there; on the same or a subsequent
turn, that same builder may upgrade the Basement to a House, and later still may upgrade the House to a Tower. Once built, a
residence cannot be removed or change owners.
2.5 Edges
Edges are located at the edges of each tile, going between vertices. Each tile has 6 edges. Most edges are shared by multiple
tiles.
For example, in Figure 1, the edges associated with the tile are numbers 27, 31, 32, 39, 40, and 44.
2.6 Roads
Each edge can have at most one road built on it. When a road is built, the display is updated by replacing the edge number
with the first character of the colour of the owner, e.g. ‘B’ for “Blue”, followed by ‘R’ for “Road”. Note that once a road has
been built on a given edge, it will stay there for the remainder of the game.
A builder can build a road if an adjacent road or residence has been built by the same builder.
The cost to build one road is one HEAT and one WIFI resource.
2.7 Builders
All builders in the game are “human” players and controlled by the commands issued on standard input. Your game must
support exactly 4 builders.
Each builder is assigned a colour at the beginning of the game with builder 0 being Blue, builder 1 being Red, builder 2
being Orange and builder 3 being Yellow.
When the status of a builder is printed, output:
has building points, brick, energy,
glass, heat, and WiFi.
When the buildings of a builder are printed, output:
has built:
followed by the following line for each building:
where is the vertex of each building that owns and is the type of building
(B, H or T).
Page 4 of 12
CS246 FALL 2020 PROJECT – CONSTRUCTOR CS246, FALL 2020
2.8 Dice
Two types of dice are supported by the game: loaded1
and fair dice. Each builder has their own set of dice to roll. When dice
are rolled, any builder who has a residence on a tile with the same value as the roll receives resources associated with the tile
and the residences present. When the game begins, all builders will have loaded dice.
For example, in Figure 1, if a builder owned residence 21 and the dice rolled were 1 and 1 (i.e. the total is 2), the builder
will receive a BRICK resource.
2.8.1 Loaded Dice
When loaded dice are chosen, the builder is prompted with the statement:
Input a roll between 2 and 12:
If the builder’s input is invalid, i.e. not an integer or out of the valid range, output the message:
Invalid roll.
followed by the previous prompt.
Once a valid roll has been entered, the entered roll is used for the turn.
2.8.2 Fair Dice
When fair dice are chosen, two numbers are randomly generated, each between 1 and 6. The sum of the two generated
numbers are used for the turn.
3 Game Rules
An important part of the game is how each of the game components interact with each other. This section describes many of
the rules explaining how pieces interact.
3.1 Building Residences
For a builder to build a residence, the following two conditions must be met:
• A residence may not be built on a vertex that is adjacent to a vertex with an existing residence.
• It is either the beginning of the game, in which case a residence can be built on any vertex, or they have built a road that
is adjacent to the vertex.
3.2 Improving Residences
A residence can be improved if the builder has already built a residence and the residence has not been improved to a tower
yet. A basement can only be improved to a house and a house can only be improved to a tower.
3.3 Building Roads
A road can be built if the builder has built either an adjacent road or residence.
3.4 Turn Order
Once the first residences are chosen, it is the Blue builder’s turn, followed by Red, then Orange and then Yellow. This sequence
then repeats until the game ends.
1Using loaded dice is a form of cheating in games. This is the only time we will encourage you to cheat in this course.
Page 5 of 12
CS246 FALL 2020 PROJECT – CONSTRUCTOR CS246, FALL 2020
3.5 Resources
3.5.1 Printing Resources
When printing owned resource types during the game, resources should always be printed in the order of BRICK, ENERGY,
GLASS, HEAT, then WIFI.
3.5.2 Obtaining Resources
When the die roll is a non-seven number, builders receive resources based upon where they have built residences, and the
types of these residences.
3.5.3 Using Resources
A builder can use any resources that they have in their possession. Attempting to complete an action that requires more
resources than the builder has causes the action to fail and the message
You do not have enough resources.
to be printed.
3.5.4 Trading Resources
The active builder can propose a trade with any other builder. When a trade is proposed, the following output will be displayed:
offers one for one .
Does accept this offer?
where is the current builder, is the colour of the builder is proposing to trade
with, is the resource is offering and is the resource is requesting.
After the prompt, player responds. The response from is either “yes” or “no”. If “yes”,
gains one and loses one , while gains one and
loses one. Otherwise, neither players’ resources change.
3.5.5 Tile Distribution
The value and resource associated with each tile is read from a file at the beginning of the game. By default, the file that is
read is named layout.txt from the current directory. A command-line option can be given to change the file that will be
read. The format of the file is described in the Board Layout (3.8) section.
There is also a command-line option to generate a random board layout. When randomly generated, the board consists of
the following resources: 3 WIFI, 3 HEAT, 4 BRICK, 4 ENERGY, 4 GLASS, and 1 PARK. The values on the board will have
the distribution of one tile with value 2, two tiles with values between 3 and 6, two tiles with values between 8 and 11 and one
tile with the value 12. Note that this makes it possible to have a board with two tiles with the same value. The tile with PARK
does not display a value.
For example, suppose a 2 was rolled with the board in Figure 3. There is only one tile on the board that has the value 2
and it has the resource BRICK. The residences on the tile are 20, 21, 26, 27, 32, 33. Each builder who has completed one of
these residences receives some BRICK resources. The number of BRICK they receive is dependent on the type of residence
they have built (one for basement, two for house, and three for tower). If a builder has completed multiple residences on a
single tile, they receive the resource(s) for each residence.
After the resources are distributed, print the following line for each builder who gained resources, in the order of builder
number:
Builder gained:
followed by the line:
Page 6 of 12
CS246 FALL 2020 PROJECT – CONSTRUCTOR CS246, FALL 2020
for each resource they received from the dice roll.
If no builders gained resources from the roll, output
No builders gained resources.
3.6 Moving Geese
When a seven is rolled, the current builder moves the geese to any tile on the board. Any builder with 10 or more resources
will automatically lose half of their resources (rounded down) to the geese. The resources lost are chosen at random and the
process is described below. For each builder who loses resources, output:
Builder loses resources to the geese. They lose:
followed by the line:
for each resource lost.
The active builder is prompted:
Choose where to place the GEESE.
The builder responds with the number of any tile except where the GEESE is currently placed. The current builder then
steals a random resource from one builder who has a residence on the tile to where the geese are moved.
If there are any players which can be stolen from, the following is output:
Builder can choose to steal from [builders].
where is the active builder and [builders] is a comma separated list of those builders, represented by their
colour, who have residences on the tile where the geese were placed, have a non-zero number of resources, and are not the
active player. The builders should be printed in the order of player number.
The active builder is prompted:
Choose a builder to steal from.
The active builder responds with the colour of the builder from whom they want to steal a random resource. Exactly one
resource is chosen. The probability of stealing/losing each type of resource is the number of the resource the builder being
stolen from has, divided by the total number of resources the builder being stolen from has.
After a resource is stolen, the following is output:
Builder steals from builder .
If the tile has no builders who can be stolen from, the following is output:
Builder has no builders to steal from.
The display is updated with the word GEESE being added below the value of the tile that the geese were placed on. If the
geese were previously on a tile, the word GEESE is removed from that tile.
After handling the geese, the active player completes their turn as normal.
For example, consider Figure 2. Say builder Blue has 5 HEAT, Red has no resources, Orange has 11 BRICK, and Yellow
has 3 GLASS. Now Blue rolls a 7. The program outputs:
Builder Orange loses 5 resources to the geese. They lose:
5 BRICK
Choose where to place the GEESE.
Blue inputs 9 to place the GEESE on tile 9. The program outputs:
Builder Blue can choose to steal from Yellow.
Choose a builder to steal from.
Blue inputs Yellow. The program outputs:
Builder Blue steals GLASS from builder Yellow.
Now Blue has 1 GLASS, 5 HEAT, Red has no resources, Orange has 6 BRICK, and Yellow has 2 GLASS.
Page 7 of 12
CS246 FALL 2020 PROJECT – CONSTRUCTOR CS246, FALL 2020
3.7 Saving a Game
When a game is saved, the following information is printed to a file in the following order:
A builder’s data is printed out as follows:
r h
where is the number of each road, separated by one space, and is the list of residences that
have been built, each represented as a pair. Each pair in the list represents the vertex of the residence followed by the letter
representing the residence on it.
For example, the row
1 2 1 2 3 r 16 36 19 h 10 B 15 T 27 H
would be the output for a player with 1 BRICK, 2 ENERGY, 1 GLASS, 2 HEAT, 3 WIFI, the roads 16, 36 and 19 and
residences at vertices 10 (a basement), 15 (a tower) and 27 (a house).
3.8 Board Layout
For loading and saving a board layout, the following format will be used.
The resources will be printed in the order of the resources on the board with 0 representing BRICK, 1 representing
ENERGY, 2 representing GLASS, 3 representing HEAT, 4 representing WIFI, and 5 representing PARK with each resource
being followed by its value
For example, the board in Figure 3 is
0 3 1 10 3 5 1 4 5 7 3 10 2 11 0 3 3 8 0 2 0 6 1 8 4 12 1 5 4 11 2 4 4 6 2 9 2 9
Note that in the provided files, a tile for PARK will always be followed by the number 7 even though it doesn’t have a value
associated.
The is a number between 0 and 18 representing the tile that contains the geese.
4 Gameplay
There are four distinct stages in the game, during which input should be handled differently.
4.1 Beginning of Game
At the beginning of the game, each builder chooses two initial basements to build. The basements will be chosen by builders
in the order Blue, Red, Orange, Yellow, Yellow, Orange, Red, Blue.
Each builder is prompted with the statement:
Builder, where do you want to build a basement?
Each builder responds with a number that represents a valid vertex.
Once a valid vertex has been entered, prompt the next builder. Once all builders have placed their two basements, print the
updated board and begin the game.
Page 8 of 12
CS246 FALL 2020 PROJECT – CONSTRUCTOR CS246, FALL 2020
4.2 Beginning of Turn
At the beginning of a turn, display the board and print the following:
Builder’s turn.
followed by the status of the builder. A builder can then enter any of the following three commands:
Command Description
load sets the dice of the current builder to be loaded dice
fair sets the dice of the current builder to be fair dice
roll rolls the current builder’s dice. This ends the ”Beginning of the turn” phase and moves the builder to ”During the turn”.
4.3 During the Turn
During the turn, a builder can input any of the following commands:
Command Description
board prints the current board
status prints the current status of all builders in order from builder 0 to 3
residences prints the residences the current builder has currently completed
build-road attempts to builds the road at
build-res attempts to builds a basement at
improve attempts to improve the residence at
trade attempts to trade with builder giving one resource of type and receiving one
resource of type
next passes control onto the next builder in the game. This ends the ”During the Turn” phase.
save saves the current game state to
help prints out the list of commands
The help command prints the following
Valid commands:
board
status
residences
build-road
build-res
improve
trade
next
save
help
4.4 End of Game
The game ends when a builder has a total of at least 10 building points. The first builder to have 10 building points is the
winner. At this point, the builders are prompted:
Would you like to play again?
If the response is “yes”, the game starts over from the beginning. If the response is “no”, the game exits.
Page 9 of 12
CS246 FALL 2020 PROJECT – CONSTRUCTOR CS246, FALL 2020
4.5 Handling Input
When waiting for a response from standard input, the program prints ¿ .
If a builder attempts to improve or build a residence, or build a road, and the space is invalid (for any reason), output:
You cannot build here.
If a builder attempts to build anything and they do not have the required resources, output:
You do not have enough resources.
If an unrecognized command is entered, output:
Invalid command.
If the game receives an end-of-file signal at any point, the game ends with no winner, and saves the current game state to
backup.sv.
5 Command-line Interface
Note: Command-line options are important to implement as they aid in easy testing of the correctness of your program.
Programs which do not implement all command line options will not be fully tested and will receive low marks.
Your program must support the following options on the command line:
Command Description
-seed xxx sets the random number generator’s seed to xxx. If you don’t set the seed, you always get the same random sequence every time
you run the program. It is good for testing, but not much fun.
-load xxx loads the game saved in file xxx. You may assume that the file being loaded was saved as a valid game state as described in the
Saving section. Note: loading from a saved file will be heavily used during the testing of the
project and should be considered a priority while implementing the project.
-board xxx loads the game with the board specified in the file xxx instead of using random generation. This file will contain the order of the tiles
for the game as described in the saving the game section. The number of each tile present does not have to match
the random generation. e.g. it is valid to have a board which is entirely WIFI resources with the value 122
.
-random-board starts a game with a randomly generated board. If a game is being loaded, this command is ignored and the layout specified in the
saved game is used instead.
The command-line options can be given in any order.
6 Questions
These questions are to be answered as described in the project guidelines.pdf. We recommend reading and thinking about
these questions while you are designing you project.
You must answer questions 1 and 2, AND any 3 of questions 3-7.
1. You have to implement the ability to choose between randomly setting up the resources of the board and reading the
resources used from a file at runtime. What design pattern could you use to implement this feature? Did you use this
design pattern? Why or why not?
2. You must be able to switch between loaded and fair dice at run-time. What design pattern could you use to implement
this feature? Did you use this design pattern? Why or why not?
3. We have defined the game of Constructor to have a specific board layout and size. Suppose we wanted to have different
game modes (e.g. rectangular tiles, a graphical display, different sized board for a different numbers of players). What
design pattern would you consider using for all of these ideas?
Page 10 of 12
CS246 FALL 2020 PROJECT – CONSTRUCTOR CS246, FALL 2020
4. At the moment, all Constructor players are humans. However, it would be nice to be able to allow a human player to
quit and be replaced by a computer player. If we wanted to ensure that all player types alway followed a legal sequence
of actions during their turn, what design pattern would you use? Explain your choice.
5. What design pattern would you use to allow the dynamic change of computer players, so that your game could support
computer players that used different strategies, and were progressively more advanced/smarter/aggressive?
6. Suppose we wanted to add a feature to change the tiles’ production once the game has begun. For example, being able
to improve a tile so that multiple types of resources can be obtained from the tile, or reduce the quantity of resources
produced by the tile over time. What design pattern(s) could you use to facilitate this ability?
7. Did you use any exceptions in your project? If so, where did you use them and why? If not, give an example of a place
that it would make sense to use exceptions in your project and explain why you didn’t use them.
7 If Things Go Wrong
If you run into trouble and find yourself unable to complete the entire project, please do your best to submit something that
works, even if it doesn’t solve the entire project. For example:
• only one housing type exists
• does not recognize the full command syntax
• building points are not calculated correctly
You will get a higher mark for fully implementing some of the requirements than for a program that attempts all of the
requirements, but doesn’t run.
A well-documented, well-designed program that has all of the deficiencies listed above, but still runs, can still potentially
earn a passing grade.
8 Plan for the Worst
Even the best programmers have bad days, and the simplest pointer error can take hours to track down. So be sure to have a
plan of attack in place that maximizes your chances of always at least having a working program to submit. Prioritize your
goals to maximize what you can demonstrate at any given time. One of the first things you should probably do is write a
routine to draw the game board (probably a Board class with an overloaded friend operator<<). It can start out blank, and
become more sophisticated as you add features. You should also do the command interpreters early, so that you can interact
with your program. You can then add commands one-by-one, and separately work on supporting the full command syntax.
Take the time to work on a test suite at the same time as you are writing your project. Although we are not asking you to
submit a test suite, having one on hand will speed up the process of verifying your implementation.
Note that for testing purposes, it is more important to have the non-randomized features, e.g. loaded dice, reading a saved
game from a file, working than the randomized features, e.g. fair dice, random generation.
You will be asked to submit a plan, with projected completion dates and divided responsibilities, as part of your documentation
for Due Date 1.
9 If Things Go Well
If you complete the entire project, you can earn up to 10% extra credit for implementing extra features. These must be outlined
in your design document, and markers will judge the value of your extra features.
Page 11 of 12
CS246 FALL 2020 PROJECT – CONSTRUCTOR CS246, FALL 2020
10 A Note on Random Generation
To complete this project, you will require the random generation (or rather, pseudo-random) of numbers. See the provided
shuffle.cc for an example of declaring a random number generator that is used to randomly shuffle a vector of integers.
The random number generator is seeded once with the (possibly global variable) seed, and then used in std::shuffle.
Games that are started with the same seed value have the same sequences of random numbers generated.
Due Dates
Due Date 1: Due on due date 1 is your plan of attack, plan.pdf, and initial UML diagram, uml.pdf, for your implementation
of Constructor on Marmoset, CS246_PROJECT.
Due Date 2: Due on due date 2 is your actual implementation of Constructor. All .h, .cc and any other files needed
for your project to compile and run should be included in constructor.zip. The ZIP file must contain a suitable
Makefile such that typing make will compile your code and produce an executable named constructor. In addition,
your constructor.zip must also contain demo.pdf and all necessary files to run your demo (such as saved input,
either with a fixed seed or loaded game files, but not the program executable, which will be compiled from the files submitted
in constructor.zip), uml-final.pdf and design.pdf to the appropriate place on Marmoset, CS246_PROJECT.
If you have implemented any bonus features, make sure that your submitted demo plan includes a list of all of the described
bonus features, and how to run the game to see the effect of the bonus features.
See project guidelines.pdf for instructions about what should be included in your plan of attack and final design document.
Page 12 of 12
• DO NOT EVER SUBMIT TO MARMOSET WITHOUT COMPILING AND TESTING FIRST. If your final
submission doesn’t compile, or otherwise doesn’t work, you will have nothing to show during your demo. Resist
the temptation to make last-minute changes. They probably aren’t worth it.
• This project is intended to be doable by three people in two weeks. Because the breadth of students’ abilities in
this course is quite wide, exactly what constitutes two weeks’ worth of work for three students is difficult to nail
down. Some groups will finish quickly; others won’t finish at all. We will attempt to grade this assignment in
a way that addresses both ends of the spectrum. You should be able to pass the assignment with only a modest
portion of your program working. Then, if you want a higher mark, it will take more than a proportionally
higher effort to achieve, the higher you go. A perfect score will require a complete implementation. If you
finish the entire program early, you can add extra features for a few extra marks.
• Above all, MAKE SURE YOUR SUBMITTED PROGRAM RUNS. The markers do not have time to examine
source code and give partial correctness marks for non-working programs. So, no matter what, even if your
program doesn’t work properly, make sure it at least does something.
1 The Game of Constructor
In this project, you will implement the game Constructor, which is a variant of the game Settlers of Catan (often called Settlers
for short), with the board being based on the University of Waterloo. If you are unfamiliar with Settlers, please see https:
//www.youtube.com/watch?v=8Yj0Y3GKE40 or https://www.catan.com/service/game-rules for an
overview. It may also be beneficial to play a game or two of Settlers to become familiar with the gameplay. Note that the rules
of Constructor vary from the rules of Settlers.
1.1 Gameplay Overview
You have recently decided that you are going to become a housing developer in Waterloo. You want to build housing for
the many students who attend the University. There are three different types of residences you can build. For each residence
built, you will earn a building point towards winning the game. Aside from that, residences will influence which materials
you receive, and where you and other builders will be able to build in the future.
During the setup of the game, each player selects starting vertices. Once the game begins, each builder takes turns rolling
the dice to determine which tiles produce resources. After rolling, the builder who rolled the dice has the opportunity to build
roads and residences using their resources.
The goal of the game is to be the first of the four players to obtain 10 (or more) building points.
2 Game Components
2.1 Board
The board is the visual representation of the state of the current game (see Figure 3 for a sample). The board will always
display the 19 tiles present in the game, all edges and vertices, and the roads and residences the builders have completed. The
representation for each of these components is described in their respective sections.
Page 1 of 12
CS246 FALL 2020 PROJECT – CONSTRUCTOR CS246, FALL 2020
2.2 Tiles
Each tile, displayed as a rectangle on the board, represents one type of resource in the game. The middle of each tile lists the
tile number, the type of resource and the tile value, in this order. In Figure 1, the tile number is 9, the resource is BRICK and
the tile value is 2. The tile number refers to where the tile is on the board. The tile value is used to determine which resources
are allocated when the dice are rolled (discussed later). Additionally, if geese (See Section 2.3) are present on the tile, it will
be displayed as in Figure 2. The outline of each tile is composed of the edges and vertices surrounding it.
There are 6 types of tile: BRICK, ENERGY, GLASS, HEAT, WIFI, and PARK. The Resources section (3.5) discusses
how resources and values are distributed. The PARK tile produces no resources.
Figure 1: Sample Tile
2.3 Geese
A tile can be overrun with geese, which play a similar role to that of the robber in the original game. In the event that a tile
has been overrun by geese, builders will not receive resources when the value matching the tile is rolled.
2.4 Vertices
A vertex is located at each corner and in the middle of each vertical edge of each tile. Each tile has 6 vertices. Note that most
vertices are shared by multiple tiles.
In Figure 1, the vertices are numbers 20, 21, 26, 27, 32, and 33.
2.4.1 Housing Details
A residence can be built at a vertex. Only one builder can build at each vertex. Each vertex can have at most one of 3 types
of residences on it. Once a builder has built a residence, they can improve the residence twice. When a residence is built, the
display is updated by replacing the vertex with the first character of the colour of the owner, e.g. ‘B’ for “Blue”, followed by
the first character of the name of the improvement, e.g. ‘B’ for “Basement”.
Housing must be built in the following order:
CS246 FALL 2020 PROJECT – CONSTRUCTOR CS246, FALL 2020
Basement (B) Building a basement gives the builder one resource when the value of any adjacent tile is rolled. When
acquired, a basement gives the owner one building point. A basement costs one BRICK, one ENERGY, one GLASS,
and one WIFI to build.
House (H) Building a house gives the builder two resources when the value of any adjacent tile is rolled. When acquired, a
house gives the builder one additional building point (2 in total). A house costs two GLASS, and three HEAT to build.
Tower (T) Building a tower gives the builder three resources when the value of any adjacent tile is rolled. When acquired,
a tower gives the builder one additional building point (3 in total). A tower costs three BRICK, two ENERGY, two
GLASS, one WIFI and two HEAT to build.
If a vertex currently has no residence on it, then a builder may construct a Basement there; on the same or a subsequent
turn, that same builder may upgrade the Basement to a House, and later still may upgrade the House to a Tower. Once built, a
residence cannot be removed or change owners.
2.5 Edges
Edges are located at the edges of each tile, going between vertices. Each tile has 6 edges. Most edges are shared by multiple
tiles.
For example, in Figure 1, the edges associated with the tile are numbers 27, 31, 32, 39, 40, and 44.
2.6 Roads
Each edge can have at most one road built on it. When a road is built, the display is updated by replacing the edge number
with the first character of the colour of the owner, e.g. ‘B’ for “Blue”, followed by ‘R’ for “Road”. Note that once a road has
been built on a given edge, it will stay there for the remainder of the game.
A builder can build a road if an adjacent road or residence has been built by the same builder.
The cost to build one road is one HEAT and one WIFI resource.
2.7 Builders
All builders in the game are “human” players and controlled by the commands issued on standard input. Your game must
support exactly 4 builders.
Each builder is assigned a colour at the beginning of the game with builder 0 being Blue, builder 1 being Red, builder 2
being Orange and builder 3 being Yellow.
When the status of a builder is printed, output:
When the buildings of a builder are printed, output:
followed by the following line for each building:
where
(B, H or T).
Page 4 of 12
CS246 FALL 2020 PROJECT – CONSTRUCTOR CS246, FALL 2020
2.8 Dice
Two types of dice are supported by the game: loaded1
and fair dice. Each builder has their own set of dice to roll. When dice
are rolled, any builder who has a residence on a tile with the same value as the roll receives resources associated with the tile
and the residences present. When the game begins, all builders will have loaded dice.
For example, in Figure 1, if a builder owned residence 21 and the dice rolled were 1 and 1 (i.e. the total is 2), the builder
will receive a BRICK resource.
2.8.1 Loaded Dice
When loaded dice are chosen, the builder is prompted with the statement:
Input a roll between 2 and 12:
If the builder’s input is invalid, i.e. not an integer or out of the valid range, output the message:
Invalid roll.
followed by the previous prompt.
Once a valid roll has been entered, the entered roll is used for the turn.
2.8.2 Fair Dice
When fair dice are chosen, two numbers are randomly generated, each between 1 and 6. The sum of the two generated
numbers are used for the turn.
3 Game Rules
An important part of the game is how each of the game components interact with each other. This section describes many of
the rules explaining how pieces interact.
3.1 Building Residences
For a builder to build a residence, the following two conditions must be met:
• A residence may not be built on a vertex that is adjacent to a vertex with an existing residence.
• It is either the beginning of the game, in which case a residence can be built on any vertex, or they have built a road that
is adjacent to the vertex.
3.2 Improving Residences
A residence can be improved if the builder has already built a residence and the residence has not been improved to a tower
yet. A basement can only be improved to a house and a house can only be improved to a tower.
3.3 Building Roads
A road can be built if the builder has built either an adjacent road or residence.
3.4 Turn Order
Once the first residences are chosen, it is the Blue builder’s turn, followed by Red, then Orange and then Yellow. This sequence
then repeats until the game ends.
1Using loaded dice is a form of cheating in games. This is the only time we will encourage you to cheat in this course.
Page 5 of 12
CS246 FALL 2020 PROJECT – CONSTRUCTOR CS246, FALL 2020
3.5 Resources
3.5.1 Printing Resources
When printing owned resource types during the game, resources should always be printed in the order of BRICK, ENERGY,
GLASS, HEAT, then WIFI.
3.5.2 Obtaining Resources
When the die roll is a non-seven number, builders receive resources based upon where they have built residences, and the
types of these residences.
3.5.3 Using Resources
A builder can use any resources that they have in their possession. Attempting to complete an action that requires more
resources than the builder has causes the action to fail and the message
You do not have enough resources.
to be printed.
3.5.4 Trading Resources
The active builder can propose a trade with any other builder. When a trade is proposed, the following output will be displayed:
Does
where
with,
After the prompt, player
loses one
3.5.5 Tile Distribution
The value and resource associated with each tile is read from a file at the beginning of the game. By default, the file that is
read is named layout.txt from the current directory. A command-line option can be given to change the file that will be
read. The format of the file is described in the Board Layout (3.8) section.
There is also a command-line option to generate a random board layout. When randomly generated, the board consists of
the following resources: 3 WIFI, 3 HEAT, 4 BRICK, 4 ENERGY, 4 GLASS, and 1 PARK. The values on the board will have
the distribution of one tile with value 2, two tiles with values between 3 and 6, two tiles with values between 8 and 11 and one
tile with the value 12. Note that this makes it possible to have a board with two tiles with the same value. The tile with PARK
does not display a value.
For example, suppose a 2 was rolled with the board in Figure 3. There is only one tile on the board that has the value 2
and it has the resource BRICK. The residences on the tile are 20, 21, 26, 27, 32, 33. Each builder who has completed one of
these residences receives some BRICK resources. The number of BRICK they receive is dependent on the type of residence
they have built (one for basement, two for house, and three for tower). If a builder has completed multiple residences on a
single tile, they receive the resource(s) for each residence.
After the resources are distributed, print the following line for each builder who gained resources, in the order of builder
number:
Builder
followed by the line:
Page 6 of 12
CS246 FALL 2020 PROJECT – CONSTRUCTOR CS246, FALL 2020
for each resource they received from the dice roll.
If no builders gained resources from the roll, output
No builders gained resources.
3.6 Moving Geese
When a seven is rolled, the current builder moves the geese to any tile on the board. Any builder with 10 or more resources
will automatically lose half of their resources (rounded down) to the geese. The resources lost are chosen at random and the
process is described below. For each builder who loses resources, output:
Builder
followed by the line:
for each resource lost.
The active builder is prompted:
Choose where to place the GEESE.
The builder responds with the number of any tile except where the GEESE is currently placed. The current builder then
steals a random resource from one builder who has a residence on the tile to where the geese are moved.
If there are any players which can be stolen from, the following is output:
Builder
where
colour, who have residences on the tile where the geese were placed, have a non-zero number of resources, and are not the
active player. The builders should be printed in the order of player number.
The active builder is prompted:
Choose a builder to steal from.
The active builder responds with the colour of the builder from whom they want to steal a random resource. Exactly one
resource is chosen. The probability of stealing/losing each type of resource is the number of the resource the builder being
stolen from has, divided by the total number of resources the builder being stolen from has.
After a resource is stolen, the following is output:
Builder
If the tile has no builders who can be stolen from, the following is output:
Builder
The display is updated with the word GEESE being added below the value of the tile that the geese were placed on. If the
geese were previously on a tile, the word GEESE is removed from that tile.
After handling the geese, the active player completes their turn as normal.
For example, consider Figure 2. Say builder Blue has 5 HEAT, Red has no resources, Orange has 11 BRICK, and Yellow
has 3 GLASS. Now Blue rolls a 7. The program outputs:
Builder Orange loses 5 resources to the geese. They lose:
5 BRICK
Choose where to place the GEESE.
Blue inputs 9 to place the GEESE on tile 9. The program outputs:
Builder Blue can choose to steal from Yellow.
Choose a builder to steal from.
Blue inputs Yellow. The program outputs:
Builder Blue steals GLASS from builder Yellow.
Now Blue has 1 GLASS, 5 HEAT, Red has no resources, Orange has 6 BRICK, and Yellow has 2 GLASS.
Page 7 of 12
CS246 FALL 2020 PROJECT – CONSTRUCTOR CS246, FALL 2020
3.7 Saving a Game
When a game is saved, the following information is printed to a file in the following order:
A builder’s data is printed out as follows:
where
have been built, each represented as a pair. Each pair in the list represents the vertex of the residence followed by the letter
representing the residence on it.
For example, the row
1 2 1 2 3 r 16 36 19 h 10 B 15 T 27 H
would be the output for a player with 1 BRICK, 2 ENERGY, 1 GLASS, 2 HEAT, 3 WIFI, the roads 16, 36 and 19 and
residences at vertices 10 (a basement), 15 (a tower) and 27 (a house).
3.8 Board Layout
For loading and saving a board layout, the following format will be used.
The resources will be printed in the order of the resources on the board with 0 representing BRICK, 1 representing
ENERGY, 2 representing GLASS, 3 representing HEAT, 4 representing WIFI, and 5 representing PARK with each resource
being followed by its value
For example, the board in Figure 3 is
0 3 1 10 3 5 1 4 5 7 3 10 2 11 0 3 3 8 0 2 0 6 1 8 4 12 1 5 4 11 2 4 4 6 2 9 2 9
Note that in the provided files, a tile for PARK will always be followed by the number 7 even though it doesn’t have a value
associated.
The
4 Gameplay
There are four distinct stages in the game, during which input should be handled differently.
4.1 Beginning of Game
At the beginning of the game, each builder chooses two initial basements to build. The basements will be chosen by builders
in the order Blue, Red, Orange, Yellow, Yellow, Orange, Red, Blue.
Each builder is prompted with the statement:
Builder
Each builder responds with a number that represents a valid vertex.
Once a valid vertex has been entered, prompt the next builder. Once all builders have placed their two basements, print the
updated board and begin the game.
Page 8 of 12
CS246 FALL 2020 PROJECT – CONSTRUCTOR CS246, FALL 2020
4.2 Beginning of Turn
At the beginning of a turn, display the board and print the following:
Builder
followed by the status of the builder. A builder can then enter any of the following three commands:
Command Description
load sets the dice of the current builder to be loaded dice
fair sets the dice of the current builder to be fair dice
roll rolls the current builder’s dice. This ends the ”Beginning of the turn” phase and moves the builder to ”During the turn”.
4.3 During the Turn
During the turn, a builder can input any of the following commands:
Command Description
board prints the current board
status prints the current status of all builders in order from builder 0 to 3
residences prints the residences the current builder has currently completed
build-road
build-res
improve
trade
resource of type
next passes control onto the next builder in the game. This ends the ”During the Turn” phase.
save
help prints out the list of commands
The help command prints the following
Valid commands:
board
status
residences
build-road
build-res
improve
trade
next
save
help
4.4 End of Game
The game ends when a builder has a total of at least 10 building points. The first builder to have 10 building points is the
winner. At this point, the builders are prompted:
Would you like to play again?
If the response is “yes”, the game starts over from the beginning. If the response is “no”, the game exits.
Page 9 of 12
CS246 FALL 2020 PROJECT – CONSTRUCTOR CS246, FALL 2020
4.5 Handling Input
When waiting for a response from standard input, the program prints ¿ .
If a builder attempts to improve or build a residence, or build a road, and the space is invalid (for any reason), output:
You cannot build here.
If a builder attempts to build anything and they do not have the required resources, output:
You do not have enough resources.
If an unrecognized command is entered, output:
Invalid command.
If the game receives an end-of-file signal at any point, the game ends with no winner, and saves the current game state to
backup.sv.
5 Command-line Interface
Note: Command-line options are important to implement as they aid in easy testing of the correctness of your program.
Programs which do not implement all command line options will not be fully tested and will receive low marks.
Your program must support the following options on the command line:
Command Description
-seed xxx sets the random number generator’s seed to xxx. If you don’t set the seed, you always get the same random sequence every time
you run the program. It is good for testing, but not much fun.
-load xxx loads the game saved in file xxx. You may assume that the file being loaded was saved as a valid game state as described in the
Saving section. Note: loading from a saved file will be heavily used during the testing of the
project and should be considered a priority while implementing the project.
-board xxx loads the game with the board specified in the file xxx instead of using random generation. This file will contain the order of the tiles
for the game as described in the saving the game section. The number of each tile present does not have to match
the random generation. e.g. it is valid to have a board which is entirely WIFI resources with the value 122
.
-random-board starts a game with a randomly generated board. If a game is being loaded, this command is ignored and the layout specified in the
saved game is used instead.
The command-line options can be given in any order.
6 Questions
These questions are to be answered as described in the project guidelines.pdf. We recommend reading and thinking about
these questions while you are designing you project.
You must answer questions 1 and 2, AND any 3 of questions 3-7.
1. You have to implement the ability to choose between randomly setting up the resources of the board and reading the
resources used from a file at runtime. What design pattern could you use to implement this feature? Did you use this
design pattern? Why or why not?
2. You must be able to switch between loaded and fair dice at run-time. What design pattern could you use to implement
this feature? Did you use this design pattern? Why or why not?
3. We have defined the game of Constructor to have a specific board layout and size. Suppose we wanted to have different
game modes (e.g. rectangular tiles, a graphical display, different sized board for a different numbers of players). What
design pattern would you consider using for all of these ideas?
Page 10 of 12
CS246 FALL 2020 PROJECT – CONSTRUCTOR CS246, FALL 2020
4. At the moment, all Constructor players are humans. However, it would be nice to be able to allow a human player to
quit and be replaced by a computer player. If we wanted to ensure that all player types alway followed a legal sequence
of actions during their turn, what design pattern would you use? Explain your choice.
5. What design pattern would you use to allow the dynamic change of computer players, so that your game could support
computer players that used different strategies, and were progressively more advanced/smarter/aggressive?
6. Suppose we wanted to add a feature to change the tiles’ production once the game has begun. For example, being able
to improve a tile so that multiple types of resources can be obtained from the tile, or reduce the quantity of resources
produced by the tile over time. What design pattern(s) could you use to facilitate this ability?
7. Did you use any exceptions in your project? If so, where did you use them and why? If not, give an example of a place
that it would make sense to use exceptions in your project and explain why you didn’t use them.
7 If Things Go Wrong
If you run into trouble and find yourself unable to complete the entire project, please do your best to submit something that
works, even if it doesn’t solve the entire project. For example:
• only one housing type exists
• does not recognize the full command syntax
• building points are not calculated correctly
You will get a higher mark for fully implementing some of the requirements than for a program that attempts all of the
requirements, but doesn’t run.
A well-documented, well-designed program that has all of the deficiencies listed above, but still runs, can still potentially
earn a passing grade.
8 Plan for the Worst
Even the best programmers have bad days, and the simplest pointer error can take hours to track down. So be sure to have a
plan of attack in place that maximizes your chances of always at least having a working program to submit. Prioritize your
goals to maximize what you can demonstrate at any given time. One of the first things you should probably do is write a
routine to draw the game board (probably a Board class with an overloaded friend operator<<). It can start out blank, and
become more sophisticated as you add features. You should also do the command interpreters early, so that you can interact
with your program. You can then add commands one-by-one, and separately work on supporting the full command syntax.
Take the time to work on a test suite at the same time as you are writing your project. Although we are not asking you to
submit a test suite, having one on hand will speed up the process of verifying your implementation.
Note that for testing purposes, it is more important to have the non-randomized features, e.g. loaded dice, reading a saved
game from a file, working than the randomized features, e.g. fair dice, random generation.
You will be asked to submit a plan, with projected completion dates and divided responsibilities, as part of your documentation
for Due Date 1.
9 If Things Go Well
If you complete the entire project, you can earn up to 10% extra credit for implementing extra features. These must be outlined
in your design document, and markers will judge the value of your extra features.
Page 11 of 12
CS246 FALL 2020 PROJECT – CONSTRUCTOR CS246, FALL 2020
10 A Note on Random Generation
To complete this project, you will require the random generation (or rather, pseudo-random) of numbers. See the provided
shuffle.cc for an example of declaring a random number generator that is used to randomly shuffle a vector of integers.
The random number generator is seeded once with the (possibly global variable) seed, and then used in std::shuffle.
Games that are started with the same seed value have the same sequences of random numbers generated.
Due Dates
Due Date 1: Due on due date 1 is your plan of attack, plan.pdf, and initial UML diagram, uml.pdf, for your implementation
of Constructor on Marmoset, CS246_PROJECT.
Due Date 2: Due on due date 2 is your actual implementation of Constructor. All .h, .cc and any other files needed
for your project to compile and run should be included in constructor.zip. The ZIP file must contain a suitable
Makefile such that typing make will compile your code and produce an executable named constructor. In addition,
your constructor.zip must also contain demo.pdf and all necessary files to run your demo (such as saved input,
either with a fixed seed or loaded game files, but not the program executable, which will be compiled from the files submitted
in constructor.zip), uml-final.pdf and design.pdf to the appropriate place on Marmoset, CS246_PROJECT.
If you have implemented any bonus features, make sure that your submitted demo plan includes a list of all of the described
bonus features, and how to run the game to see the effect of the bonus features.
See project guidelines.pdf for instructions about what should be included in your plan of attack and final design document.
Page 12 of 12