LoginSignup
4
4

More than 5 years have passed since last update.

ドミニオン圧縮プレイをモンテカルロ法で分析

Last updated at Posted at 2012-03-16
dominion_chapel_strategy.py
#coding: UTF-8
#ドミニオンの圧縮戦略で、5枚以上のカードの情報(銀、金、属州礼拝堂)を与えると、その状態から属州を5枚買うまでの平均ターン数を返すプログラム。
#適宜手動で実験してみてください。かなり理想化しているので、参考程度にどうぞ。
#下記のプログラムによれば、結論としては、「属州を買えるときは常に属州を買おう。そうでないときは、マナブースト(この場合は金)を買おう」となりそう。
#これは、圧縮戦略によらなそうな気もしているが、そこは自分でかんがえろ。
#chokudaiが解析的に解いた結果、G3枚買ってから、上記の戦略に移るのが正しいとのこと。
import random

moto = ['s','s','s','g','z']#sは銀貨、gは金貨、zは属州と礼拝堂
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
4
4
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4