Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

# Montecarlo.py # This program uses a Monte Carlo approach to estimate the probability of winning the dice game Approach with different # hold values.

image text in transcribed

\# Montecarlo.py \# This program uses a Monte Carlo approach to estimate the probability of winning the dice game "Approach" with different \# "hold" values. \# Recall that approach works like this: \# Both players agree on a limit n. * Player 1 rolls first. They go until they either exceed n or hold. * Then player 2 rolls. They go until they either exceed n or beat player 1 's score. \# The player who is closest to n without going over wins. \# We can reduce this to the problem of of player 1 choosing the best value at which to hold. \# We'll estimate this by simulating all possible hold values from n5:n \# This function should try each possible hold value 1000000 times. Once a hold value is set, \# play a random game and keep track of the number of wins for player 1. \# n is the limit. def monte_carlo_approach(n) : win_table ={} for i in range (n5,n+1) : win_table [i]=0 for i in range (1000000) : \#\# you do this part. My solution is under 20 lines of code. Yours can be longer, but if it's getting \#\# really big, take a step back and rethink. for item in win_table. keys () : print("\%d: \%f" \% (item, win_table[item]/1000b00))

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sams Teach Yourself Beginning Databases In 24 Hours

Authors: Ryan Stephens, Ron Plew

1st Edition

067232492X, 978-0672324925

More Books

Students also viewed these Databases questions

Question

What do you think of the MBO program developed by Drucker?

Answered: 1 week ago