Skip to content

Commit

Permalink
Added expected center calculator.
Browse files Browse the repository at this point in the history
  • Loading branch information
obi1kenobi committed Dec 10, 2014
1 parent 4c67c0f commit 5012532
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/card_decoder/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ def read_card_counts():


class CardDecoder(object):
def decode_cards(self):
def __init__(self):
# We pad with an empty string because the effect indices are one-indexed
self.effects = [''] + files.read_lines('input/effects.txt')

def decode_cards(self):
return CardDictionary(self._decode_acquirables() + self._decode_defeatables())

def _decode_acquirables(self):
Expand Down
Empty file added src/tools/__init__.py
Empty file.
106 changes: 106 additions & 0 deletions src/tools/expected_center_calculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import itertools
from src.card_decoder.decoder import CardDecoder

# itertools.combinations(iterable, count)

def make_card(runes_to_buy, honor_from_runes, power_to_defeat, honor_from_power):
return (float(runes_to_buy), \
float(honor_from_runes), \
float(power_to_defeat), \
float(honor_from_power))

def get_monsters():
mephits = [(0, 0, 3, 2)] * 3
tormented_souls = [(0, 0, 3, 1)] * 3
tricksters = [(0, 0, 3, 1)] * 4

mistakes = [(0, 0, 4, 4)] * 4
widows = [(0, 0, 4, 3)] * 4

sea_tyrants = [(0, 0, 5, 5)] * 3
wind_tyrants = [(0, 0, 5, 3)] * 3

earth_tyrants = [(0, 0, 6, 5)] * 2
xerons = [(0, 0, 6, 3)]

avatars = [(0, 0, 7, 4)]

monsters = mephits + \
tormented_souls + \
tricksters + \
mistakes + \
widows + \
sea_tyrants + \
wind_tyrants + \
earth_tyrants + \
xerons + \
avatars

return monsters

def get_acquirables():
acquirables = CardDecoder()._decode_acquirables()
return [make_card(c.cost, c.honor, 0, 0) for c in acquirables]

###
# Output:
# **************************************************
# Expected center:
#
# expected runes to buy: 14.143
# expected honor from runes: 8.486
# expected honor / rune: 0.600
#
# expected power to defeat: 10.029
# expected honor from power: 7.029
# expected honor / power: 0.701
#
###
def calculate_expected_center(center_cards):
total_combinations = 0
total_runes_to_buy = 0.0
total_honor_from_runes = 0.0
total_power_to_defeat = 0.0
total_honor_from_power = 0.0

center_size = 6

for card in center_cards:
runes_to_buy, honor_from_runes, power_to_defeat, honor_from_power = card
total_combinations += 1
total_runes_to_buy += runes_to_buy
total_honor_from_runes += honor_from_runes
total_power_to_defeat += power_to_defeat
total_honor_from_power += honor_from_power

expected_runes_to_buy = total_runes_to_buy / total_combinations * center_size
expected_honor_from_runes = total_honor_from_runes / total_combinations * center_size
expected_power_to_defeat = total_power_to_defeat / total_combinations * center_size
expected_honor_from_power = total_honor_from_power / total_combinations * center_size

expected_honor_per_rune = expected_honor_from_runes / expected_runes_to_buy
expected_honor_per_power = expected_honor_from_power / expected_power_to_defeat

print "**************************************************"
print "Expected center:"
print ""
print " expected runes to buy: %.03f" % expected_runes_to_buy
print " expected honor from runes: %.03f" % expected_honor_from_runes
print " expected honor / rune: %.03f" % expected_honor_per_rune
print ""
print " expected power to defeat: %.03f" % expected_power_to_defeat
print " expected honor from power: %.03f" % expected_honor_from_power
print " expected honor / power: %.03f" % expected_honor_per_power
print ""

def main():
cards = []
acquirables = get_acquirables()
monsters = get_monsters()
cards.extend(acquirables)
cards.extend(monsters)

calculate_expected_center(cards)

if __name__ == "__main__":
main()

0 comments on commit 5012532

Please sign in to comment.