Due date: Saturday, April 20th, 11:59pm
(* A group of young pigs is a "drift", and a group of older pigs is a "sounder".)
The goal of this project is to analyze some simple games of chance using theoretical and empirical methods, and exposure to basic simulation as a tool. You start with a simple coin-flip game, progressing on to single-die and multi-dice games. For each, you analyze elementary and compound probability events and run repeated games with different game strategies, recording the outcome. You will modify basic scripts that are provided to provide data needed for analysis, using analytics skills to create statistics and charts, with appropriate explanatory text. Results are presented in a report.
Piglet is a one player game where the goal is to get 10 points in a few turns as possible.
Find a coin and play Piglet (with a friend) to get a feel for the game.
Answer the following questions:
Flips Chance Not Busting Pot Expected Points 1 0.5 2 ??? 2 0.5^2 4 ??? 3 0.5^3 6 ??? ...
Copy and paste the below Python script (into a file or a Jupyter notebook) and run it. Study what it does. Run it some more until you mostly understand it.
#
# Piglet - a single-player coin-flip game.
# v1.0
#
import random
# Game settings.
WIN = 10 # Number of points to win one game
OUTCOMES = 2 # Number of outcomes (e.g., 2 for coin, 6 for d6)
NUM_GAMES = 1 # Number of games to play
#######################################
# Pick random integer from 1 to OUTCOMES.
# Add number to pot.
# If pick 1, pot empties.
# Return pot.
def go(pot):
number = random.randint(1,OUTCOMES)
if number == 1:
print("Bust!")
pot = 0
else:
print(number)
pot += number
return pot
#######################################
# Players - Return True if go, False if stay.
# Human has choice.
def HUMAN() :
while True:
choice = input()
if choice == '1':
return True
if choice == '2':
return False
# Brave bot always goes.
def BRAVE_BOT(points, pot) :
if points + pot > WIN:
return False
return True
# Timid bot always stays.
def TIMID_BOT(points, pot) :
if pot == 0:
return True
return False
#######################################
# Play one game.
# Return number of turns it took to win.
def play():
turn, pot, points = 1, 0, 0
while points < WIN :
print("Turn:", turn, " ", end="")
print("Points:", points, " ", end="")
print("Pot:", pot, " ", end="")
print(" 1-Go or 2-Stay? ", end="")
## Uncomment one of the below players.
choice = HUMAN()
#choice = TIMID_BOT(points, pot)
#choice = BRAVE_BOT(points, pot)
if choice == False:
print("STAY")
points += pot
turn += 1
pot = 0
continue
if choice == True:
print("GO: ", end="")
pot = go(pot)
if pot == 0: # Bust
turn += 1
continue
return turn-1
########################################
# Play game(s).
game = []
for x in range(NUM_GAMES):
print("------------------")
print("Playing game:", x)
game.append(play())
# Print results.
print("------------------------------------")
for x in range(NUM_GAMES):
print("Game", x, "turns:", game[x])
The game defaults to being played with a person (HUMAN). However, there are two different bots (TIMID_BOT or BRAVE_BOT) that can play the game instead. Playing the game with a bot provides for a way of simulating gameplay without having to do the same testing with people.
Query: Which bot is better, TIMID_BOT or BRAVE_BOT?
Pig is like Piglet, but instead of flipping a coin, players roll one 6-sided die.
Find a die and play Pig (with a friend) to get a feel for the game.
Answer the following questions:
Modify the Piglet Python script from Part 1 to play Pig.
Query: Which bot is better, TIMID_BOT or BRAVE_BOT?
Develop a BETTER_BOT, one that wins in fewer rolls than either TIMID_BOT or BRAVE_BOT.
Swine is like Pig, but instead of rolling one die, players roll two 6-sided dice.
Find two dice and play Swine (with a friend) to get a feel for the game.
Modify the Pig Python script from Part 2 to play Swine. Compare performance of TIMID_BOT, BRAVE_BOT and BETTER_BOT.
Query: Which bot is best?
Bonus
Provide Python code for a BEST_BOT - a Bot that wins in the fewest number of turns on average.
Describe the logic behind your BEST_BOT.
Provide experimental results as per above that show BEST_BOT performance.
Participate in a user study.
There are two options - you must participate in one (but it would be appreciated by your fellow students if you did both):
https://docs.google.com/spreadsheets/d/1uvQeRNc4Iah9PD4jole-IQIcUGFbOjMhO_4UaoKIms0/edit#gid=0
https://docs.google.com/spreadsheets/d/1TJNv_zGQoBiRYW6hTbcbWJsgFc8U3l3YW-HgmLV5YwA/edit
Grab a timeslot and participate in the study.
Data is provided here periodically. Here are the cumulative data sets:
Download the latest data set.
Use Lag
as the independent variable. Analyze a dependent variable for some or all of the data (e.g., Time Survived
versus Lag
) for some or all of the data. Draw an appropriate chart, with a brief interpretation.
Note, there are two kinds of lag compensation algorithms being tested in the Is Using Lag Compensation
column. This may matter for the analysis.
Note: for this part of your report, you do not need to describe the user study methodology. However, you should provide a few summary statistics (e.g., number of games/players) about the data set you analyze.
Writeup a single, short report for all three sections.
Include appropriate descriptions of your methodology, avoid redundancy by separating out methodology that is common to each section.
Be sure to include responses to all required questions, indicating how you came up with your answers.
Be sure to include conclusions on all queries, providing appropriate analysis of the game data. You do not need to include your complete code listing. However, you should include the BOT functions you have written.
All dissemination guidelines for presenting and describing charts should be adhered to.
The assignment is to be submitted electronically via Canvas by 11:59pm on the day due.
The submission is a report in PDF, named:
proj4-lastname.pdf
with your name in place of "lastname" above, of course.
To submit your assignment (proj4-lastname.pdf
):
Open: IMGD2905-D19-D01
Navigate to:Assignments
->Project 4
Click:Submit Assignment
Click:Choose File
Select the pdf file:proj4-lastname.pdf
Click:Submit Assignment
Important - you must click the Submit Assignment
button at the end or your file will not be submitted!
When successfully submitted, you should see a message similar to:
Submission
- Submitted!
Apr 20 at 10:50pm
Bonus - if you did the bonus part (BEST_BOT) in Part 3, in addition to including the code in your report, email professor Claypool just your bot code so he can run it.
All accomplishments are shown through the report. The point break down does not necessarily reflect effort or time on task. Rather, the scale is graduated to provide for increasingly more effort required for the same reward (points).
Part 1 (Piglet) - 35% : Analysis of the Piglet game.
Part 2 (Pig) - 30% : Analysis of the Pig game.
Part 3 (Swine) - 25% : Analysis of the Swine game.
Part 4 (User Study) - 10% : Participating in the User Study.
Bonus extra 1% : Providing a working, optimal BEST_BOT for Swine.
100-90. The submission clearly exceeds requirements. All Parts of the project have been completed or nearly completed. The report is clearly organized and well-written, with questions answered correctly with work shown. All charts and tables are clearly labeled and described, with measures of central tendency and spread properly computed and explained.
89-80. The submission meets requirements. Parts 1-4 of the project have been completed or nearly completed. The report is organized and well-written, with questions answered mostly correctly and with most work shown. All charts and tables are labeled and described, with measures of central tendency and spread properly computed and explained.
79-70. The submission barely meets requirements. Parts 1-2 of the project have been completed or nearly completed, and some of Part 3, and maybe not Part 4. The report is semi-organized and semi-well-written, but some question answers are incorrect and/or work is not shown. Charts and tables are mostly labeled and described, but parts may be missing or unclear. Measures of central tendency and spread may not be always computed or adequately explained.
69-60. The project fails to meet requirements in some places. Part 1 of the project has been completed or nearly completed, and some of Part 2, but not Parts 3 or 4. The report is not well-organized nor well-written, charts and tables are not labeled or may be missing. Many question answers are incorrect and/or work is not shown. Measures of central tendency and spread may not be always computed or explained or may even be misused. Messages are not always provided for the analysis.
59-0. The project does not meet requirements. Many parts of the project are incomplete or poorly done. The report is not well-organized nor well-written, charts and tables are not labeled and/or are missing. Many answers to questions are missing or incorrect with work not shown. Measures of central tendency and spread are missing of, if in place, are misused.
The comments below are in response to graded projects. They are not provided in any particular order.
Most of the probability analysis was correctly done and clearly explained. Well done.
The basic expected value tables and charts for the 3 games were correctly interpreted. This provided reasoning for making a "Better Bot", most of which worked quite well.
Remember, inferring behavior (e.g., effectiveness of a Bot or play strategy) is best done over many trials. At least 30, then the central limit theorem applies and statistical significance can be determined. So, have a sample size of 30+ if possible (for this project, run at least 30 games for a given bot).
Also remember, that the standard error (and confidence intervals) get smaller with an increasing sample size (n). So, if possible, run more games than 30. For this project, it is pretty "cheap" to run 1000 games for each bot. That's an advantage of automated game playing - it is relatively easy to collect data compared to a users study.
Having a chart with the game number on the x-axis is not particularly useful. There is no dependence between games, so the x-axis value has no meaning. Yes, the games could be ordered high to low, in an attempt to show a distribution. But even here, while it could be useful to see spread across games, there are better ways of doing this (e.g., histogram or CDF).
Return to the IMGD 2905 home page