Settlers of Catan
1. Settlers of Catan
Settlers of Catan is a popular board game that was introduced much more recently than Yahtzee, in 1995.2. Introduction to the game
Several of the game rules are beyond the scope of this lesson. Here, we will focus on the fact that each turn involves rolling two ordinary 6-sided dice, and a typical game involves approximately 60 rolls. Each spot on the board is labeled with a roll value from 2 through 12. Players choose positions based on the labeled value of a position. Basic strategy suggests choosing positions with the highest likelihood and avoiding positions with the lowest likelihood. When rolling two dice, 2 and 12 are the most unlikely values to occur, since there is only one way to obtain these values. The only way to roll a 2 is if both dice equal 1 and the value of 12 requires both dice landing on 6. So, how surprised should we be if 2 or 12 comes up several times throughout the course of a game?3. Simulating dice rolls
Let's answer this question using simulation. Recall the roll underscore dice function that we wrote in Chapter 1. It will be used in this chapter to conveniently simulate dice rolls. Here we roll two dice, take the sum, and obtain a value of 7. We also learned about using loops to perform a task repeatedly. Another way to accomplish this is to use the replicate function. If we want to perform a task some number of times, we can provide the replicate function with that number, followed by the task we want to perform. Here, we roll two dice 10 times.4. The table function
It can also be beneficial to summarize the output in terms of how many times each value was rolled. To accomplish this, we can use the table function. The first row of the output is the values rolled, and the second row is the number of times that each value occurred. Note that if a roll value does not appear in the table, such as 3, 9 and 12, it did not occur in the trial.5. Counting the number of occurrences
Let's discuss counting the number of occurrences of particular rolls using the sum function. Here, we roll a single die 100 times and check how many times it landed on 3. In this simulation, it occurred 22 times. Next, we check if this count is greater than a particular value. Suppose we want to know if the value of 3 was rolled more than 17 times, which is approximately what we would expect theoretically. We check using code and find that 22 is greater than 17, and print the appropriate phrase within the if statement. Suppose we want to know if either a 3 or 4 was rolled more than 17 times. Now, we would have a compound condition, using the or operator, designated by a vertical line. When either condition is true, the phrase will be printed.6. Let's try it!
Now it's your turn.Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.