Skip to content

Commit

Permalink
some improvements in non-player files
Browse files Browse the repository at this point in the history
  • Loading branch information
fpvandoorn committed Apr 4, 2020
1 parent 7d0c156 commit c3850fc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
27 changes: 22 additions & 5 deletions bot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,30 @@

from hanabi_classes import *

def number_of_copies(card):
"""Returns the number of copies that exists of the card"""
if card[1] == BLACK_SUIT or card[0] == '5':
return 1
if card[0] == '1':
return 3
return 2

def names(cards):
"""Returns the names of a list of cards"""
"""Returns the names of a list of cards; call only on visible cards!"""
return [card['name'] for card in cards]

def get_plays(cards, progress):
"""Return a list of plays (subset of input); call only on visible cards!"""
return [card for card in cards if is_playable(card, progress)]

def get_usefuls(cards, progress):
"""Return the cards in `cards` that are not yet played; call only on visible cards!"""
return [card for card in cards if not has_been_played(card, progress)]

def get_criticals(cards, r):
"""Return the cards in `cards` that are critical; call only on visible cards!"""
return [card for card in cards if is_critical(card['name'], r)]

def is_cardname_playable(cardName, progress):
return progress[cardName[1]] + 1 == int(cardName[0])

Expand Down Expand Up @@ -143,8 +159,9 @@ def count_unplayed_playable_cards(r, progress):
unplayable because they are already discarded"""
n = 0
for suit in r.suits:
for i in range(progress[suit]+1,int(SUIT_CONTENTS[-1])+1):
if r.discardpile.count(str(i) + suit) < SUIT_CONTENTS.count(str(i)):
for i in range(progress[suit]+1,MAX_VALUE+1):
s = str(i) + suit
if r.discardpile.count(s) < number_of_copies(s):
n += 1
else:
break
Expand All @@ -158,12 +175,12 @@ def get_all_useful_cardnames(r):
"""Gets all cards that could be playable in future"""
l = []
for suit in r.suits:
for i in range(r.progress[suit]+1,int(SUIT_CONTENTS[-1])+1):
for i in range(r.progress[suit]+1,MAX_VALUE+1):
s = str(i) + suit

# If we've already gotten rid of this card
# then we don't add it or any numbers afterwards
if r.discardpile.count(s) == SUIT_CONTENTS.count(str(i)):
if r.discardpile.count(s) == number_of_copies(s):
break
l.append(s)
return l
Expand Down
1 change: 1 addition & 0 deletions hanabi_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

VANILLA_SUITS = 'rygbw'
SUIT_CONTENTS = '1112233445' # must be ascending
MAX_VALUE = 5 # maximum number in SUIT_CONTENTS
BLACK_SUIT_CONTENTS = '12345' # must be ascending
N_HINTS = 8
N_LIGHTNING = 3
Expand Down
2 changes: 1 addition & 1 deletion hanabi_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def std_err(lst):
args.n_rounds = i
break
if args.verbosity in ('verbose', 'log'):
logger.info('\n' + 'ROUND {}:'.format(i))
logger.info('\n' + 'ROUND {}:'.format(i+1))
score = play_one_round(args.game_type, players, names, args.verbosity,
args.loss_score, args.police, args.output, debug)
scores.append(score)
Expand Down
3 changes: 1 addition & 2 deletions play_hanabi.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def play_one_round(gameType, players, names, verbosity, lossScore, isPoliced, wr
if gameType == 'rainbow': variant = "Rainbow (6 Suits)"
if gameType == 'purple': variant = "Six Suits"
if gameType == 'vanilla': variant = "No Variant"
if gameType == 'black': variant = "Six Suits (One of Each Rank)"
if gameType == 'black': variant = "Black (6 Suits)"
output = { "actions": actions, "deck": startDeck, "notes": notes, "players": players, "variant": variant }
with io.open('log.json', 'a', encoding='utf-8') as f:
f.write(json.dumps(output, ensure_ascii=False))
Expand All @@ -72,7 +72,6 @@ def play_one_round(gameType, players, names, verbosity, lossScore, isPoliced, wr
for c in range(total_cards(gameType)):
debug[('note', i, c)] = ''


if r.lightning == N_LIGHTNING and lossScore == 'zero':
return 0 # Award no points for a loss
return sum(r.progress.values()) # Final score
Expand Down

0 comments on commit c3850fc

Please sign in to comment.