[PYTHON] Dominion compression play analyzed by Monte Carlo method

dominion_chapel_strategy.py


#coding: UTF-8
#Information on 5 or more cards with Dominion's compression strategy(Silver, gold, province chapel)A program that returns the average number of turns from that state to buying 5 provinces.
#Experiment manually as appropriate. It is quite idealized, so please use it as a reference.
#According to the program below, the conclusion is, "Whenever you can buy a province, buy it. If not, mana boost.(Gold in this case)Let's buy it. "
#I think this depends on the compression strategy, but think about it yourself.
#As a result of chokudai's analytical solution, it is correct to move to the above strategy after buying 3 Gs.
import random

moto = ['s','s','s','g','z']#s is a silver coin, g is a gold coin, z is a province and chapel
lib = moto[:]

answer = 0.0
division = 0.0
turn = 0.0

while division < 3000:
  if lib.count('z') == 6:
    answer = answer + turn
    division = division + 1.0
    lib = moto[:]
    turn = 0
  list = random.sample(lib,5)
  point = 3 * list.count('g') + 2 * list.count('s')
  if point >= 8:
    lib.append('z')
  if point == 6 or point == 7:
    lib.append('g')
  turn = turn + 1

print answer / division


Recommended Posts

Dominion compression play analyzed by Monte Carlo method
Estimating π by Monte Carlo method
Monte Carlo method
The first Markov chain Monte Carlo method by PyStan
Speed comparison of each language by Monte Carlo method
Introduction to Monte Carlo Method
Simulate Monte Carlo method in Python
Find the ratio of the area of Lake Biwa by the Monte Carlo method
Gomoku AI by Monte Carlo tree search
[Statistics] Let's explain sampling by Markov chain Monte Carlo method (MCMC) with animation.
#Monte Carlo method to find pi using Python
Try implementing the Monte Carlo method in Python
Calculation of the shortest path using the Monte Carlo method