講解:Stats 102A荚斯、R埠居、R、script fileR|SPSS

Stats 102A - Homework 4 Instructions: MonopolyHomework questions and instructions copyright Miles Chen, Do not post, share, or distribute without permission.Homework 4 RequirementsYou 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 homeworkassignment. Write comments as necessary.2. 102a_hw_04_output_First_Last.Rmd Take the provided R Markdown file and make the necessary edits sothat it generates the requested output. The first line of your .Rmd file should be to source the R script file youwrote.3. 102a_hw_04_output_First_Last.pdf Your output PDF file. This is the primary file that will be graded. Makesure all requested output is visible in the output file.Failure to submit all files will result in an automatic 40 point penalty.Academic IntegrityAt the top of your R markdown file, be sure to include the following statement after modifying it with your name.“By including this statement, I, Joe Bruin, declare that all of the work in this assignment is my own original work.At no time did I look at the code of other students nor did I search for code solutions online. I understand thatplagiarism on any single part of this assignment will result in a 0 for the entire assignment and that I will be referredto the dean of students.”If you collaborated verbally with other students, please also include the following line to credit them.“I did discuss ideas related to the homework with Josephine Bruin for parts 2 and 3, with John Wooden for part 2,and with Gene Block for part 5. At no point did I show another student my code, nor did I look at another student’scode.”Recommended Reading:a. S3 (not necessary for this HW): https://adv-r.hadley.nz/s3.htmlb. R6: https://adv-r.hadley.nz/r6.htmlMonopoly Board game simulationFor 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 whichsquares the pieces land on.You can familiarize yourself with the game board. (Taken from Amazon’s product page.)http://ecx.images-amazon.com/images/I/81oC5pYhh2L._SL1500_.jpgOfficial rules https://www.hasbro.com/common/instruct/monins.pdf1Rules for movementThe Monopoly Board is effectively a circle with 40 spaces on which a player can land. Players move from space tospace 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, landon a space, and end his turn there. If this were the entire game, the spaces would have a uniform distribution aftermany turns.There are, however, several exceptions which provide the primary source of variation in space landing.Go to JailOne space, “Go to Jail” sends players directly to jail (there is a jail space on the board). This space never counts ashaving been ‘landed upon.’ As soon as the player ‘lands’ here, he is immediately sent to jail, and the jail space getscounted as landed upon. This is the only space on the game board that moves a player’s piece. The count of howoften this space is landed on will always be 0.Rolling DoublesIf a player rolls doubles (two of the same number), the player moves his piece, and then gets to roll the dice again foranother move. However, if a player rolls doubles three times in a row, he is sent directly to jail. (The third space thatthe player would have ‘landed on’ does not count, but the jail space gets counted as landed on.)Card Decks: Chance and Community ChestA player can land on a “Chance” or “Community Chest” space. When a player lands on these spaces, he draws acard from the respective deck and follows its instructions. The instructions will sometimes give money to or takemoney from the player with no change in the player’s position on the board. Other times, the card will instruct theplayer 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 Chestdeck 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 ofjail’ 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 thesecases, the player always moves forward. So if a player is on ‘Oriental Avenue,’ the nearest railroad is ‘PennsylvaniaRailroad’ and NOT ‘Reading Railroad.’For the sake of this simulation, the Chance and Community Chest get counted as landed on when the playerlands on the Chance or Community Chest space. The player may also generate another count if the card moves theplayer to another space on the board. In those cases, a tally is counted for the Chance/Community Chest space, thetoken is moved, and then a tally is counted for the space where the player ends his turn.JailJail 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 generatesa 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, andhis turn ends immediately.2On the next turn, the player begins in jail and the player will roll the dice. If he rolls doubles on the dice, he gets outof jail and moves the number of spaces the dice show. However, even though he rolled doubles, he does NOT rollagain. 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 movesthe number of spaces the dice show no matter what.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 notimplement those rules. We will simply simulate a ‘long stay’ strategy for Jail. This means that the player will neverpay 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.The AssignmentYour assignment is to implement the rules of Monopoly movement.You must use R6 to createStats 102A作業(yè)代做事期、代做R課程設(shè)計(jì)作業(yè)滥壕、代寫R程序語(yǔ)言作業(yè)、代寫script file作業(yè) 代做R語(yǔ)言編程|代 an object class Player which will be used to keep track of a player.Part 1You will first demonstrate that you have coded the rules by showing the output of the first 20 turns using the presetdice. 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 gettallies, if they rolled doubles, etc.Part 2The next part is to run 1,000 simulations of a two-player game that lasts 150 turns. This is a total of over 3 hundredthousand 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 whichspaces are most likely to be landed upon. Advance the tokens around the board according to the rules. Keep in mindthe 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 spacename, 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 bargraph 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 CodeFor 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: showing the movement of the player for 20 turns? 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, andeach 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.Please take the time to read through these R6 class definitions. Understanding the definitions, and what the methodsdo will be helpful in completing the assignment.3TipsAt 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 thispart 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 itbehaves the way you want it to.? The PresetDice reference class will be very helpful in your testing. For example, you can intentionally createsome dice rolls to test certain situations. What to test if Chance is working correctly? Set your dice to causethe player to land on Chance. Want to test if doubles is working correctly? Set the PresetDice to producedoubles. If you had purely random dice, you might have to wait for the computer to produce many manyrandom 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 inmind that some cards have no effect on player movement, while other cards do.? Add code to allow players to move again after doubles.? Add code to implement the rules for Jail. You’ll need to keep track of whether the player is actually in jail ornot, how many turns the player has been in jail, and the rules for getting out.Grading1. 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 theentire simulation for all students.3. We will check the output of the 20 preset turns.These are the point values of each turn. I also specify the rule implementation that we are looking for in each of theseturns.? Turn 4 (8 pts) Roll three sets of doubles, third doubles sends player to jail, also drawing community chest? Turn 6 (4 pts) Rolling doubles exits jail? Turn 8 (4 pts) Go to jail space sends player to jail? Turn 11 (4 pts) Third turn. No doubles roll. Player exits jail.? Turn 14 (4 pts) Chance card advances to nearest railroad. Take a ride on Reading Railroad.? Turn 15 (4 pts) Chance card that doesn’t move and rolling doubles.? Turn 16 (4 pts) Chance card that sends player to jail.? Turn 19 (4 pts) Rolled doubles on third turn in jail. Gets out of jail.? The other 12 turns are worth 2 points each.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 20 turn output and table output matches what we are looking for, you will get full credit.46. If your outputs do not match, We will skim your code to see if certain functions or chunks of code exist to see ifyou can recover some (up to half) of the points you lost.We will check for the following sections. Because your code will be quite long, it is VERY IMPORTANT youCLEARLY mark these sections for the grader if you want to recover points.a. drawing chance cardb. drawing community chest cardc. landing on “go to jail”d. roll again for rolling doublese. going to jail for rolling three doublesf. jail functionalityYou 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 goif(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 pleaseindicate what you were able to implement and what you were not able to implement. You will be graded on what youwere able to complete.You are encouraged to talk with other students currently enrolled in Stats 102A.Best wishes!5轉(zhuǎn)自:http://www.6daixie.com/contents/18/4921.html

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末兽泣,一起剝皮案震驚了整個(gè)濱河市绎橘,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌唠倦,老刑警劉巖称鳞,帶你破解...
    沈念sama閱讀 217,826評(píng)論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異稠鼻,居然都是意外死亡冈止,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,968評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門枷餐,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)靶瘸,“玉大人,你說(shuō)我怎么就攤上這事毛肋≡惯洌” “怎么了?”我有些...
    開封第一講書人閱讀 164,234評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵润匙,是天一觀的道長(zhǎng)诗眨。 經(jīng)常有香客問(wèn)我,道長(zhǎng)孕讳,這世上最難降的妖魔是什么匠楚? 我笑而不...
    開封第一講書人閱讀 58,562評(píng)論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮厂财,結(jié)果婚禮上芋簿,老公的妹妹穿的比我還像新娘。我一直安慰自己璃饱,他們只是感情好与斤,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,611評(píng)論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般撩穿。 火紅的嫁衣襯著肌膚如雪磷支。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,482評(píng)論 1 302
  • 那天食寡,我揣著相機(jī)與錄音雾狈,去河邊找鬼。 笑死抵皱,一個(gè)胖子當(dāng)著我的面吹牛善榛,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播叨叙,決...
    沈念sama閱讀 40,271評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼锭弊,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了擂错?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,166評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤樱蛤,失蹤者是張志新(化名)和其女友劉穎钮呀,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體昨凡,經(jīng)...
    沈念sama閱讀 45,608評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡爽醋,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,814評(píng)論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了便脊。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片蚂四。...
    茶點(diǎn)故事閱讀 39,926評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖哪痰,靈堂內(nèi)的尸體忽然破棺而出遂赠,到底是詐尸還是另有隱情,我是刑警寧澤晌杰,帶...
    沈念sama閱讀 35,644評(píng)論 5 346
  • 正文 年R本政府宣布跷睦,位于F島的核電站,受9級(jí)特大地震影響肋演,放射性物質(zhì)發(fā)生泄漏抑诸。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,249評(píng)論 3 329
  • 文/蒙蒙 一爹殊、第九天 我趴在偏房一處隱蔽的房頂上張望蜕乡。 院中可真熱鬧,春花似錦梗夸、人聲如沸层玲。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,866評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)称簿。三九已至扣癣,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間憨降,已是汗流浹背父虑。 一陣腳步聲響...
    開封第一講書人閱讀 32,991評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留授药,地道東北人士嚎。 一個(gè)月前我還...
    沈念sama閱讀 48,063評(píng)論 3 370
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像悔叽,于是被迫代替她去往敵國(guó)和親莱衩。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,871評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容

  • k1ic閱讀 249評(píng)論 0 0
  • 這個(gè)世界上有許多事情娇澎,仿佛真的是命中注定一樣笨蚁。比如我和蔣小瑞。 記得第一次見她是在大一軍訓(xùn)的第一天趟庄,她...
    安碧落閱讀 196評(píng)論 0 0
  • 在我們學(xué)習(xí)字節(jié)流與字符流的時(shí)候戚啥,大家都進(jìn)行過(guò)讀取文件中數(shù)據(jù)的操作奋单,讀取數(shù)據(jù)量大的文件時(shí),讀取的速度會(huì)很慢猫十,很影響我...
    圣賢與無(wú)賴閱讀 155評(píng)論 0 0
  • 央視頻 菜鳥教程(編程) 鯡魚罐頭(小情緒圖片) 免費(fèi)證件照 世界名著精選 book 英語(yǔ)翻譯 文獻(xiàn)鳥stork ...
    烏素吱吱吱閱讀 31評(píng)論 0 0