Permalink
Browse files

make game state iterator easier to interrogate, do a little pep8 refa…

…ctoring of Name -> name
  • Loading branch information...
1 parent 2816a85 commit 2af9be65e434d546b066da5e5b3115518d45d158 @rrenaud rrenaud committed Jun 23, 2011
Showing with 18 additions and 11 deletions.
  1. +11 −3 card_info/__init__.py
  2. +4 −3 parse_game.py
  3. +3 −3 query_matcher.py
  4. +0 −2 utils.py
View
@@ -1,14 +1,18 @@
import csv
import os
-_cardlist_reader = csv.DictReader(open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'card_list.csv')))
+_cardlist_reader = csv.DictReader(open(
+ os.path.join(
+ os.path.dirname(os.path.abspath(__file__)), 'card_list.csv')))
_to_singular = {}
_to_plural = {}
_card_index = {}
_card_info_rows = {}
-#the way this file is being used, it seems like a good candidate for some sort
-#of Card class with properties, etc
+_card_names = []
+
+# the way this file is being used, it seems like a good candidate for some sort
+# of Card class with properties, etc
def _init():
for idx, cardlist_row in enumerate(_cardlist_reader):
single, plural = cardlist_row['Singular'], cardlist_row['Plural']
@@ -19,6 +23,7 @@ def _init():
_card_index[single] = idx
_card_info_rows[single] = cardlist_row
+ _card_names.append(single)
_init()
@@ -82,3 +87,6 @@ def num_copies_per_game(card_name, num_players):
def card_index(singular):
return _card_index[singular]
+
+def card_names():
+ return _card_names
View
@@ -778,7 +778,7 @@ def check_game_sanity(game_val, output):
for player_deck in game_val.get_player_decks():
parsed_deck_comp = player_deck.Deck()
computed_deck_comp = last_state.get_deck_composition(
- player_deck.Name())
+ player_deck.name())
delete_keys_with_empty_vals(parsed_deck_comp)
computed_dict_comp = dict(computed_deck_comp)
@@ -797,7 +797,7 @@ def check_game_sanity(game_val, output):
computed_deck_comp.get(card, 0)))
found_something_wrong = True
if found_something_wrong:
- output.write('%s %s\n' % (player_deck.Name(), game_val.get_id()))
+ output.write('%s %s\n' % (player_deck.name(), game_val.get_id()))
output.write(' '.join(game_val.get_supply()))
output.write('\n')
return False
@@ -868,7 +868,7 @@ def annotate_game(contents, game_id, debug=False):
turn.get_turn_no(),
turn.get_player().TurnOrder(), turn.get_poss_no(),
turn.turn_dict.get('poss', False),
- turn.get_player().Name())
+ turn.get_player().name())
import cStringIO as StringIO
output_buf = StringIO.StringIO()
@@ -898,6 +898,7 @@ def annotate_game(contents, game_id, debug=False):
show_turn_id = '%s-show-turn-%d' % (player, turn_no + 1)
poss_num = 0
elif 'pname' in parsed_header:
+ # port the turn labeller back to game.py?
turn_id = '%s-poss-turn-%d-%d' % (player, turn_no,
poss_num)
show_turn_id = '%s-show-poss-turn-%d-%d' % (
View
@@ -48,7 +48,7 @@ def __init__(self, player_deck, query_matcher):
self.kingdom_match_score = (kingdom_total_matched * 10 +
(has_all * 100))
- _score = query_matcher.name_match(player_deck.Name()) * 10000
+ _score = query_matcher.name_match(player_deck.name()) * 10000
self.name_match_score = _score
def deck_match_score(self):
@@ -67,10 +67,10 @@ def display_player_deck(self):
ret = ''
ret += '%s: %d points: ' % (
game.PlayerDeck.PlayerLink(
- pd.Name(),
+ pd.name(),
'<font color="%s">%s</font>' % (
self.player_deck.GameResultColor(),
- self._maybe_highlight_name(pd.Name()))
+ self._maybe_highlight_name(pd.name()))
),
pd.Points())
card_freqs = pd.Deck().items()
View
@@ -32,9 +32,7 @@ def get_mongo_database():
config.read('conf.ini')
db = connection[config.get('mongo', 'database')]
- #FIXME: this is too broad
except:
- # Might still err if test does not exist
db = connection['test']
return db

0 comments on commit 2af9be6

Please sign in to comment.