Cave of the Nadir (Guide)/Script

From Fallen London Wiki

# -*- coding: utf-8 -*-
"""
Created on Mon May  1 09:05:19 2023

@author: Gyro
"""

import random


  
def drawCard(deck):
  newCardName = random.choice(list(deck.keys()))
  newCard = deck.pop(newCardName)
  return [newCardName] + newCard

def playCard(deck, cardNumber,currentHand, echoes, Irrigo):
  playedCard = currentHand.pop(cardNumber)
  deck[playedCard[0]] = playedCard[1:3]
  echoes += playedCard[1]
  Irrigo += playedCard[2]
  return [echoes, Irrigo]
  

def caveTrip():
  Cards = {
      "Cardgame": [.6,1],
      "Familiar": [0,1],
      "Pause": [1,1],
      "Dream2": [0.0,2],
      "Dream4": [0.0,2],
      "Dream6": [0.0,2],
      "weakness": [0,1],
      "altarful": [2.25,1],
      "Garden": [20.44,2],
      "recall": [.1, 1],
      "losing": [12, 2],
      "lost": [0,1],
      "Bones": [.5,2],
      "Sins": [6.25, 1],
      "Moves": [0,1],
      "Catafalquerie": [11.5, 2],
      "End": [62.5, 2],
      "Web": [2.5,1],
      "Imprisoned" : [0,1],
      "woods": [36.5,2]
      }


  Nightmares = 6

  if Nightmares < 6:
      Cards.pop("Dream6")
  if Nightmares < 4:
      Cards.pop("Dream4")
  if Nightmares < 2:
      Cards.pop("Dream2")
  
  actions = 4 #3 to enter, 1 to clear
  Irrigo = 1 #starting irrigo
  maxIrrigo = 9  #When to bail if you have no good cards in hand.
  echoes = 0
  hand = [drawCard(Cards),drawCard(Cards),drawCard(Cards),drawCard(Cards),drawCard(Cards)]
  
  while Irrigo < 9:
      bestcard = 0
      for i in range(len(hand)-1):
          if hand[bestcard][1] < hand[i][1]:
              bestcard = 0+i
          elif hand[bestcard][1] == hand[i][1]:
              if hand[bestcard][2] < hand[i][2]:
                  bestcard = 0+i
      if hand[bestcard][2] + Irrigo > maxIrrigo and hand[bestcard][1] <6.25:
          break
      [echoes, Irrigo] = playCard(Cards, bestcard, hand, echoes, Irrigo)
      hand += [drawCard(Cards)]
      actions += 1
  epa = echoes/actions
  return epa 

sample = []
for i in range(1000000):
  sample += [caveTrip()]