Skip to content

Instantly share code, notes, and snippets.

@qoh
Last active December 14, 2015 16:29
Show Gist options
  • Save qoh/5115662 to your computer and use it in GitHub Desktop.
Save qoh/5115662 to your computer and use it in GitHub Desktop.
from __future__ import division
import random, time, math
class Director(object):
cards = [
{
'name': 'Lizard',
'cost': 8
},
{
'name': 'Golem',
'cost': 29
},
{
'name': 'Jelly',
'cost': 27
},
{
'name': 'Wisp',
'cost': 30
},
{
'name': 'Wisp G',
'cost': 140
},
{
'name': 'Giant Jelly',
'cost': 720
},
{
'name': 'Worm',
'cost': 760
},
{
'name': 'Golem Giant',
'cost': 720
}
]
def __init__(self):
self.points = random.randint(20, 40)
self.count = 0
self.time_add = time.time()
self.time_total = 0
self.bonus_rate = 1
self.diff_level = 1
self._new_choice()
def _new_choice(self):
self.choice_index = random.randrange(len(self.cards))
def death(self):
if self.count:
self.count -= 1
def pop(self):
if time.time() - self.time_add >= 1:
self.time_total += 1
self.time_add = time.time()
fac1 = math.floor(min(self.diff_level - 0.2, 1) * self.time_total / 60)
fac2 = max(1, (2 * (self.diff_level == 3)))
self.points += 2 + fac1 * fac2
delay = (random.random() * 6 + 3) / self.bonus_rate
choice = self.cards[self.choice_index]
cost_raw = choice['cost']
cost_mod = cost_raw * (1 + (self.count * 0.2))
if cost_raw < self.points / 50:
self._new_choice()
self.count = 0
return None, False, 0.25
if self.count >= 4 or cost_mod >= self.points:
self._new_choice()
self.count = 0
return None, False, delay
self.points -= cost_mod
self.count += 1
if random.random() < 0.5 and cost_raw * 4 <= self.points:
self.points -= cost_raw * 4
return choice, True, delay
return choice, False, delay
if __name__ == '__main__':
director = Director()
while True:
choice, elite, delay = director.pop()
if choice:
if elite:
print 'spawn Elite', choice['name']
else:
print 'spawn', choice['name']
time.sleep(delay)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment