johnnywycliffe

GFVCcalc

Jun 13th, 2018
492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.11 KB | None | 0 0
  1. #!/usr/bin/env python
  2. """ GFEvent.py
  3.    
  4.    Finds out how likely you are to fill the grid.
  5.    Author: Johnny Wycliffe
  6.    Date modified: 6/13/18
  7.    Liscense:
  8.    Copyright (c) 2018 Johnny Wycliffe
  9.    
  10.    Permission is hereby granted, free of charge, to any person obtaining a copy
  11.    of this software and associated documentation files (the "Software"), to deal
  12.    in the Software without restriction, including without limitation the rights
  13.    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14.    copies of the Software, and to permit persons to whom the Software is
  15.    furnished to do so, subject to the following conditions:
  16.    
  17.    The above copyright notice and this permission notice shall be included in all
  18.    copies or substantial portions of the Software.
  19.    
  20.    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21.    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22.    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  23.    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24.    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  25.    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  26.    SOFTWARE.
  27. """
  28. import math, random, csv
  29.  
  30. #consts
  31. KH = 36 # 6 x 6 grid equals 36 keyholes
  32. DAYS = 20.0 #might be 19, I only looked at the dates.
  33. INC = 0.1 #How much to increment the keys-per-day by. Smaller is more precise, but slower.
  34. numOfIter = 100000 #Change to suit needs
  35. VERBOSE = False #Recommend piping the result to a file, or it will flood your console
  36. MAXKEYS = 9 #Maximum number of keys that could be obtained in a day.
  37.  
  38. #init
  39. random.seed()
  40.  
  41. def vPrint(string):
  42.     """Prints out detailed information if VERBOSE is True"""
  43.     if VERBOSE:
  44.         print string
  45.  
  46. def run(totalKeys):
  47.     """Simulates one account over the course of the event."""
  48.     unlocked = [] #Unlocked cells. 0 = 36, arrays start at zero, blah blah blah
  49.     bPoints = 0 #Number of points for choosing
  50.     for i in range(totalKeys):
  51.         key = random.randint(0,KH) #Random value between 0 ans 35
  52.         if key not in unlocked:
  53.             #If the key is new
  54.             vPrint(str(key) + " has been unlocked!")
  55.             unlocked.append(key)
  56.         else:
  57.             #We already have this key, get some points instead
  58.             vPrint(str(key) + " has already been unlocked, earned 10 points!")
  59.             bPoints += 10
  60.     return (unlocked, bPoints)
  61.  
  62. def avg(avgKeys):
  63.     """Gets the average random unlock and choices given a aveage mount of keys
  64.       gotten per day
  65.    """
  66.     totalKeys = int(math.floor(float(avgKeys)*DAYS)) #total number of keys earned at expected rate
  67.     resultList = [] #list of results of accounts
  68.     avgRandom = 0 #Average of the randomly selected values
  69.     avgChoose = 0 #Average number of picks obtained
  70.     vPrint("The total expected number of keys is: " + str(totalKeys))
  71.  
  72.     #Simulate a bunch of games
  73.     for i in range(numOfIter):
  74.         result = run(totalKeys)
  75.         vPrint("Total random unlocks: " + str(len(result[0])))
  76.         vPrint("Total chosen unlocks: " + str(result[1]/100.0))
  77.         avgRandom+=len(result[0])
  78.         avgChoose+=(result[1]/100.0)
  79.  
  80.     #Calculate averages
  81.     avgRandom = avgRandom / numOfIter
  82.     avgChoose = avgChoose / numOfIter
  83.     vPrint("The average number of randomly selected keyholes is " + \
  84.         str(avgRandom) + ", and the average number of keyholes to choose is " + \
  85.         str(avgChoose) + ". This equals " + str(avgRandom+avgChoose) + " of " + \
  86.         str(KH) + " keyholes unlocked.")
  87.     return (avgKeys,avgRandom,avgChoose,avgRandom+avgChoose)
  88.  
  89. def outputCSV():
  90.     """Puts data in easy to use CSV for graphing"""
  91.     with open("output.csv", "w") as f:
  92.         writer = csv.writer(f, dialect="excel")
  93.         i = 1
  94.         while i <= MAXKEYS:
  95.             result = avg(i)
  96.             writer.writerow(result)
  97.             i += INC
  98.         print "Done"
  99.  
  100. #MAIN
  101. #num=raw_input("Enter average # of keys earned per day: ")
  102. #avg(num)
  103. outputCSV()
Advertisement
Add Comment
Please, Sign In to add comment