Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- """ GFEvent.py
- Finds out how likely you are to fill the grid.
- Author: Johnny Wycliffe
- Date modified: 6/13/18
- Liscense:
- Copyright (c) 2018 Johnny Wycliffe
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in all
- copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- SOFTWARE.
- """
- import math, random, csv
- #consts
- KH = 36 # 6 x 6 grid equals 36 keyholes
- DAYS = 20.0 #might be 19, I only looked at the dates.
- INC = 0.1 #How much to increment the keys-per-day by. Smaller is more precise, but slower.
- numOfIter = 100000 #Change to suit needs
- VERBOSE = False #Recommend piping the result to a file, or it will flood your console
- MAXKEYS = 9 #Maximum number of keys that could be obtained in a day.
- #init
- random.seed()
- def vPrint(string):
- """Prints out detailed information if VERBOSE is True"""
- if VERBOSE:
- print string
- def run(totalKeys):
- """Simulates one account over the course of the event."""
- unlocked = [] #Unlocked cells. 0 = 36, arrays start at zero, blah blah blah
- bPoints = 0 #Number of points for choosing
- for i in range(totalKeys):
- key = random.randint(0,KH) #Random value between 0 ans 35
- if key not in unlocked:
- #If the key is new
- vPrint(str(key) + " has been unlocked!")
- unlocked.append(key)
- else:
- #We already have this key, get some points instead
- vPrint(str(key) + " has already been unlocked, earned 10 points!")
- bPoints += 10
- return (unlocked, bPoints)
- def avg(avgKeys):
- """Gets the average random unlock and choices given a aveage mount of keys
- gotten per day
- """
- totalKeys = int(math.floor(float(avgKeys)*DAYS)) #total number of keys earned at expected rate
- resultList = [] #list of results of accounts
- avgRandom = 0 #Average of the randomly selected values
- avgChoose = 0 #Average number of picks obtained
- vPrint("The total expected number of keys is: " + str(totalKeys))
- #Simulate a bunch of games
- for i in range(numOfIter):
- result = run(totalKeys)
- vPrint("Total random unlocks: " + str(len(result[0])))
- vPrint("Total chosen unlocks: " + str(result[1]/100.0))
- avgRandom+=len(result[0])
- avgChoose+=(result[1]/100.0)
- #Calculate averages
- avgRandom = avgRandom / numOfIter
- avgChoose = avgChoose / numOfIter
- vPrint("The average number of randomly selected keyholes is " + \
- str(avgRandom) + ", and the average number of keyholes to choose is " + \
- str(avgChoose) + ". This equals " + str(avgRandom+avgChoose) + " of " + \
- str(KH) + " keyholes unlocked.")
- return (avgKeys,avgRandom,avgChoose,avgRandom+avgChoose)
- def outputCSV():
- """Puts data in easy to use CSV for graphing"""
- with open("output.csv", "w") as f:
- writer = csv.writer(f, dialect="excel")
- i = 1
- while i <= MAXKEYS:
- result = avg(i)
- writer.writerow(result)
- i += INC
- print "Done"
- #MAIN
- #num=raw_input("Enter average # of keys earned per day: ")
- #avg(num)
- outputCSV()
Advertisement
Add Comment
Please, Sign In to add comment