首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
Stats 102A编程讲解、R留学生程序辅导、辅导R编程语言 辅导Web开发|辅导Python程序
项目预算:
开发周期:
发布时间:
要求地区:
Stats 102A - Homework 4 Instructions: Monopoly
Homework questions and instructions copyright Miles Chen, Do not post, share, or distribute without permission.
Homework 4 Requirements
You will submit three files.
The files you submit will be:
1. 102a_hw_04_script_First_Last.R Your R script file containing the functions you write for the homework
assignment. Write comments as necessary. Use the starter_code file as a starting point for the script.
2. 102a_hw_04_output_First_Last.Rmd Take the provided R Markdown file and make the necessary edits so
that it generates the requested output. The first line of your .Rmd file should be to source the R script file you
wrote.
3. 102a_hw_04_output_First_Last.pdf Your output PDF file. This is the primary file that will be graded.
Make sure all requested output is visible in the output file.
Failure to submit all files will result in an automatic 40 point penalty.
Academic Integrity
At the top of your R markdown file, be sure to include the academic integrity statement.
Recommended Reading:
a. S3 (not necessary for this HW): https://adv-r.hadley.nz/s3.html
b. R6: https://adv-r.hadley.nz/r6.html
Monopoly Board game simulation
Read through all of the instructions before getting started.
For this homework assignment, you will create a simulation of the classic board game,
Monopoly. The goal is to find out which spaces on the board get landed on the most.
You will not simulate the entire game. You will simulate only the movement of pieces, and will keep track of
which squares the pieces land on.
Official rules https://www.hasbro.com/common/instruct/monins.pdf
Familiarize yourself with the game board. (Taken from Amazon’s product page.)
1
include_graphics(’board.png’)
Rules for movement
The Monopoly Board is effectively a circle with 40 spaces on which a player can land. Players move from space to
space around the board in a circle (square).
The number of spaces a player moves is determined by the roll of 2 dice. Most often, the player will roll the dice,
move the number of spaces shown on the dice, land on a space, and end their turn there. If this were the entire
game, there would be an equal probability of landing on all 40 spaces after many turns - and the distribution of
space frequency would be uniform.
There are, however, several rules which create variation in the frequency of landing on different spaces.
Go to Jail
One space, “Go to Jail” sends players directly to jail (there is a jail space on the board). This space never counts as
having been landed upon. As soon as the player ‘lands’ here, he is immediately sent to jail, and the jail space gets
counted as landed upon. This is the only space on the game board that moves a player’s piece. The count of how
often this space is landed on will always be 0.
2
Rolling Doubles
If a player rolls doubles (two of the same number), the player moves his piece, and then gets to roll the dice again
for another move. However, if a player rolls doubles three times in a row, he is sent directly to jail. (The third space
that the player would have ‘landed on’ does not count, but the jail space gets counted as landed on.)
Card Decks: Chance and Community Chest
A player can land on a “Chance” or “Community Chest” space. When a player lands on these spaces, he draws a
card from the respective deck and follows its instructions. The instructions will sometimes give money to or take
money from the player with no change in the player’s position on the board. Other times, the card will instruct the
player to move to another space on the board. The list of cards that can be drawn from each deck is provided.
There are nine cards in the Chance deck that move the player’s token. There are two cards in the Community Chest
deck that move the player’s token. All other cards do not move the player’s token. For the sake of this simulation,
you only need to program actions for the cards that move the tokens. There is no need to do anything for ‘get out
of jail’ or any of the other cards.
A card may say ‘move to the nearest railroad’ or ‘move to the nearest utility’ or even ‘go to property . . . ’. In these
cases, the player always moves forward. So if a player is on ‘Oriental Avenue,’ the nearest railroad is ‘Pennsylvania
Railroad’ and NOT ‘Reading Railroad.’
For the sake of this simulation, the Chance and Community Chest get counted as landed on when the player
lands on the Chance or Community Chest space. The player may also generate another count if the card moves the
player to another space on the board. In those cases, a tally is counted for the Chance/Community Chest space, the
token is moved, and then a tally is counted for the space where the player ends his turn.
Jail
Jail is the most complicated aspect of this simulation.
If a player lands on space 11 (Jail) simply from rolling the dice, he is not in Jail. He is ‘just visiting’ jail. He
generates a tally for landing on jail, and his play continues on as normal.
A player can be sent to jail in several ways:
• he rolls doubles three times in a row;
• he lands on the “go to jail” space;
• he draws a card that sends hims to jail.
As soon as the player is sent to jail, his token moves to jail (space 11), he generates a count for landing on jail, and
his turn ends immediately.
On the next turn, the player begins in jail and the player will roll the dice. If he rolls doubles on the dice, he gets
out of jail and moves the number of spaces the dice show. However, even though he rolled doubles, he does NOT
roll again. He takes his move out of jail and his turn ends. If he does not roll doubles, he stays in jail.
A player cannot stay in jail for more than three turns. On the third turn he begins in jail, he rolls the dice and
moves the number of spaces the dice show no matter what. If he rolls doubles, he exits but does not roll again. If he
does not roll doubles, he still exits and does not roll again.
Play then continues as normal.
For this simulation, each time a player ends his turn in Jail, a tally will be counted as having been ‘landed upon.’
There are more rules on jail that include paying a fee to get out early, or using a get out of jail free card. We will
not implement those rules. We will simply simulate a ‘long stay’ strategy for Jail. This means that the player will
never pay the fee to get out jail early. He will roll the dice and only leave jail if he gets doubles or it is his third turn
in jail.
3
Space Definitions:
• Utilities are Electric Company and Water Works
• Railroads are: Reading Railroad, Pennsylvania Railroad, B & O Railroad, Shortline Railroad
The Assignment
Your assignment is to implement the rules of Monopoly movement.
You must use R6 to create an object class Player which will be used to keep track of a player.
Part 1
You will first demonstrate that you have coded the rules by showing the output of several test cases using preset
dice. Your output for this section should match the published results exactly.
The output should be very verbose. It should announce the player roles, where the player moves, what spaces get
tallies, if they rolled doubles, etc. Your text output should match as closely as possible.
Part 2
The next part is to run 1,000 simulations of a two-player game that lasts 150 turns. This is a total of over 3 hundred
thousand tosses of the dice - 1000 games x 150 turns x 2 players + additional rolls if the player gets doubles.
Your task is to keep track of where the players land. We ultimately want to build a distribution showing which
spaces are most likely to be landed upon. Advance the tokens around the board according to the rules. Keep in
mind the special situations involving the cards, jail, and rolling doubles. After 150 turns, reset the game and start
over. Simulate 1000 games.
Your final output will be two tables of the spaces on the board and their frequencies. Each table will show the space
name, how many times the space was landed upon, and the relative frequency of landing on that space.
The first table is arranged in descending order of frequency of landing. (Jail should be #1, Go to jail should be last.)
The second table is arrange in the order of the spaces on the board. (Go will be #1, Boardwalk will be last.)
Also print a bar graph showing the frequency of how often each space is landed on.
You do not have to simulate or track money at all in this simulation.
Starter Code
For your convenience, I have created the necessary data frames for the game board, and the two decks of cards.
I have also created several helper R6 classes for you:
• PresetDice: You will use this for Part 1: the test cases
• RandomDice: You will use this for Part 2: the simulation of 1000 games.
• CardDeck: For creating the Chance and Community Chest decks. This reference class ‘shuffles’ the deck, and
each time a player draws a card, it shows the next card drawn. When all the cards in the deck have been used,
it ‘shuffles’ the deck again.
• SpaceTracker: For keeping track of all the spaces you land on.
Please take the time to read through these R6 class definitions. Understanding the definitions and what the methods
do will be necessary for completing the assignment.
4
Tips
At first blush, the task may seem overwhelming.
• Break the task into smaller manageable parts.
• Start with a simulation that moves pieces around the board and keeps track of where they land. (I’ve done
this part for you in my example code.)
• Then add complexity one part at a time. Each time you add something, thoroughly test it to make sure it
behaves the way you want it to.
• The PresetDice reference class will be very helpful in your testing. For example, you can intentionally create
some dice rolls to test certain situations. Want to test if Chance is working correctly? Set your dice to cause
the player to land on Chance. Want to test if doubles is working correctly? Set the PresetDice to produce
doubles. If you had purely random dice, you might have to wait for the computer to produce many many
random outcomes before you see three doubles in a row.
My recommendation in terms of adding complexity:
• Add code so landing on “Go to jail” sends the player to jail.
• Add code that draws from the Chance and Community Chest decks and moves the player accordingly. Keep
in mind that some cards have no effect on player movement, while other cards do.
• Add code to allow players to roll again after doubles but goes to jail if rolling doubles three times in a row.
• Add code to implement the rules for Jail. You’ll need to keep track of whether the player is actually in jail or
not, how many turns the player has been in jail, and the rules for getting out.
Grading
1. Do NOT print the verbose version for all of 1000 games.
2. We will not run your code. The simulation will take time to run, and we do not have the luxury of running
the entire simulation for all students.
3. We will check the output of the test cases.
These are the point values of each test case.
• Test Case 1: 5 points.
– Turn 1: Player must be sent to jail.
– Tally at 11 only.
• Test Case 2: 15 points.
– Turn 1: Player ends at Go.
– Turn 2: Player ends at Reading Railroad.
– Turn 3: Player goes to Pennsylvania Railroad, goes again, player ends at Water Works.
– Turn 4: Player ends on Chance. No movement.
– Tally at: 1, 6, 8 (3), 16, 23, 29, 37
– If your Chance cards are not matching mine, make sure your R is up to date and that you are not loading
a saved work space on start up.
• Test Case 3: 10 points.
– Turn 1: Player rolls the dice a total of three times and ends at States Ave.
– Turn 2: Player lands on Community Chest. Does not move.
– Tally at: 7, 11, 14, 18
• Test Case 4: 10 points.
– Turn 1: Player ends up in Jail.
– Turn 2: Player stays in Jail
5
– Turn 3: Player stays in Jail
– Turn 4: Player exits Jail and lands on Kentucky ave.
– Tally at: 7, 11 (3), 13, 22
• Test Case 5: 10 points.
– Turn 1: Player ends in Jail. Player does not roll again, despite having rolled doubles.
– Turn 2: Player stays in Jail.
– Turn 3: Player rolls doubles and exits Jail. Player does not roll again, despite having rolled doubles.
– Tally at: 11 (2), 17
• Test Case 6: 10 points.
– Output must match the example output
That is 60 points.
4. We will check the final output of counts in the results tables.
Things we are looking for in the results tables (5 points each):
• Jail should be the most frequent space landed on.
• Jail should have a frequency between 10 and 13%.
• Spots 2 and 3 should be Illinois Ave and Go (possibly switched)
• New York Ave. and Tennessee Ave. should be in the top 10.
• Reading Railroad and B&O Railroad should be in the top 10.
• Mediterranean Ave and Baltic Ave should be in the bottom 5.
• Park Place should be very infrequent. Bottom 10.
• Go to jail should be landed on 0 times.
5. If your test cases and table output matches what we are looking for, you will get full credit.
You can ‘hard code’ the functions that handle the decks. In other words, you can write something along the lines of
## for chance deck
...
if(carddrawn == 1)
code changes player position to space 1 # advance to go
if(carddrawn == 2)
code changes player position to space 25 # advance to Illinois avenue
# etc.
...
Good luck!
I know this is a tough assignment. Like everything else in life, sometimes you have to prioritize other things (eg.
health, sleep, sanity, etc.) over the task at hand.
If you are unable to implement all parts of the solution, that is also okay. I cannot give you full credit, but please
indicate what you were able to implement and what you were not able to implement. You will be graded on what
you were able to complete.
6
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
代写dts207tc、sql编程语言代做
2024-12-25
cs209a代做、java程序设计代写
2024-12-25
cs305程序代做、代写python程序...
2024-12-25
代写csc1001、代做python设计程...
2024-12-24
代写practice test preparatio...
2024-12-24
代写bre2031 – environmental...
2024-12-24
代写ece5550: applied kalman ...
2024-12-24
代做conmgnt 7049 – measurem...
2024-12-24
代写ece3700j introduction to...
2024-12-24
代做adad9311 designing the e...
2024-12-24
代做comp5618 - applied cyber...
2024-12-24
代做ece5550: applied kalman ...
2024-12-24
代做cp1402 assignment - netw...
2024-12-24
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!