Skip to content

Instantly share code, notes, and snippets.

@fyr91
Last active October 3, 2019 06:50
Show Gist options
  • Save fyr91/703cda744229a9ffd416f88fb5634bcd to your computer and use it in GitHub Desktop.
Save fyr91/703cda744229a9ffd416f88fb5634bcd to your computer and use it in GitHub Desktop.
dummy ga
# dummy battle class
class Battle:
def __init__(self, lineup_a, lineup_b, result=None):
self.lineup_a = lineup_a
self.lineup_b = lineup_b
self.result = result
# fight - compare number of 1s in the gene
def fight(pair):
# save battle info for evaluation
battle = Battle(pair[0], pair[1])
if pair[0].combat_power > pair[1].combat_power:
battle.result = 'win'
else:
battle.result = 'loss'
return battle
# evaluation
def evaluate(battle):
if battle.result == "win":
battle.lineup_a.score += 1
battle.lineup_b.score -= 1
else:
battle.lineup_a.score -= 1
battle.lineup_b.score += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment