Skip to content

Instantly share code, notes, and snippets.

@PeterJCLaw
Created July 24, 2012 19:19
Show Gist options
  • Select an option

  • Save PeterJCLaw/3172038 to your computer and use it in GitHub Desktop.

Select an option

Save PeterJCLaw/3172038 to your computer and use it in GitHub Desktop.
great balls of SR scoring script
OTHER_ZONE = -4
LEAVE_ZONE = 6
OWN_ZONE = -2
OPPONENT_BALLS = 10
SUPER_BALL = 100
OWN_BALLS = -0.2
from math import floor
def collisions(num):
return -1 * ( 2**min(0, num - 3) - 1 )
class Score(object):
def __init__(self, own_balls = 0, opponent_balls = 0, collisions = 0,
left_home = False, entered_home = False,
other_zones_entered = 0):
self.own_balls = own_balls
self.opponent_balls = opponent_balls
self.collisions = collisions
self.left_home = left_home == True
self.entered_home = entered_home == True
self.other_zones_entered = other_zones_entered
def calculate(self):
points = 0
points += self.opponent_balls * OPPONENT_BALLS
points += collisions(self.collisions)
points += self.other_zones_entered * OTHER_ZONE
if self.left_home:
points += LEAVE_ZONE
if self.entered_home:
points += OWN_ZONE
if points > 0:
points *= (1 - OWN_BALLS) ** self.own_balls
points = int(floor(points))
return points
if __name__ == '__main__':
"""Self Test"""
score = Score(3, 3, 3, True, other_zones_entered = 2)
value = score.calculate()
partial = (LEAVE_ZONE + 3*OPPONENT_BALLS + 2*OTHER_ZONE)*( (1 - OWN_BALLS) ** 3 )
assert value == int(floor( partial ))
print "Test value:", value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment