diff --git a/card/card.py b/card/card.py index 7a617ad..b1f0107 100644 --- a/card/card.py +++ b/card/card.py @@ -50,6 +50,9 @@ class Card: def get_cost(self): return self.__cost + def get_purchase_power(self): + return self.__coin + def set_owner(self, owner): self.__owner = owner diff --git a/card/militia.py b/card/militia.py index 89b69f4..acdb418 100644 --- a/card/militia.py +++ b/card/militia.py @@ -12,16 +12,13 @@ class Militia(Card): def __force_discard(self, chances, player): if player.get_hand().get_remaining() > 3 and chances > 0: - hand_index = self.__get_index("\nPlease identify a card from hand you would like to discard by providing " - "its index 0 to " + str(player.get_hand().get_remaining() - 1) + ": ") + hand_index = player.militia_input("\nPlease provide an index to identify a card from hand you would like to" + " discard (0 to " + str(player.get_hand().get_remaining() - 1) + "): ") self.__check_discard(hand_index, player, chances) elif self._Card__owner.get_hand().get_remaining() > 3 and chances <= 0: print("You're out of chances to select a valid card to discard, randomly selecting for you.") player.discard_from_hand(randint(0, self.__hand.get_remaining() - 1)) - def __get_index(self, message): - return int(input(message)) - def __check_discard(self, index, player, chances): if 0 > index or index >= self._Card__owner.get_hand().get_remaining(): print("Valid inputs range from 0 to " + str(player.get_hand().get_remaining() - 1) + ". 1 chance lost.") diff --git a/game.py b/game.py index b236589..2b03095 100644 --- a/game.py +++ b/game.py @@ -1,6 +1,6 @@ from table.table import Table -from player.player import Player -from player.bot import Bot +from player.human import Human +from player.bots.pure_big_money import Pure_Big_Money from card.card import Card from card.militia import Militia from card.moat import Moat @@ -42,13 +42,13 @@ def setup_new_game(game_list, parameter, card_info): index += 1 for i in range(humans): - human = Player(True, t) + human = Human(t) human.draw_deck(t, get_starting_deck()) human.draw_hand() t.add_player(human) for i in range(bots): - bot = Bot(False, t) + bot = Pure_Big_Money(t) bot.draw_deck(t, get_starting_deck()) bot.draw_hand() t.add_player(bot) @@ -107,7 +107,7 @@ def get_card_info(): def get_starting_deck(): - return [["Copper", 7], ["Estate", 3]] + return [["Copper", 7], ["Militia", 3]] # return [["Market", 2], ["Merchant", 2], ["Smithy", 2], ["Village", 2], ["Moat", 2]] # return [["Militia", 4], ["Cellar", 3], ["Moat", 3]] # return [["Silver", 7], ["Merchant", 3]] diff --git a/player/bots/pure_big_money.py b/player/bots/pure_big_money.py index b7a63f9..525b484 100644 --- a/player/bots/pure_big_money.py +++ b/player/bots/pure_big_money.py @@ -2,7 +2,7 @@ from player.player import Player from card.card import Card -class Bot(Player): +class Pure_Big_Money(Player): def take_action(self): print("\nAs a BIG MONEY BOT, I'm skipping this unnecessary action phase. Beep-boop, bow to me humans!") @@ -32,3 +32,25 @@ class Bot(Player): print(message + str(choice)) return choice + + #This will pick either the first or the first least effective purchasing card as this bot doesn't care about that + def militia_input(self, message): + choice = self.__get_first_non_Treasure() + min_coin = self.get_hand().get_supply()[choice].get_purchase_power() + + for c in self.get_hand().get_supply(): + if c.get_purchase_power() < min_coin and c.get_type() != Card.CardType.Treasure: + min_coin = c.get_purchase_power() + choice = self.get_hand().get_supply().index(c) + + print(message + str(choice)) + return choice + + def __get_first_non_Treasure(self): + for c in self.get_hand().get_supply(): + if c.get_type() != Card.CardType.Treasure: + return self.get_hand().get_supply().index(c) + return 0 + + def __str__(self): + return "Player " + str(self.get_player_index()) + " (pure big money bot)" diff --git a/player/human.py b/player/human.py new file mode 100644 index 0000000..9486eb9 --- /dev/null +++ b/player/human.py @@ -0,0 +1,9 @@ +from player.player import Player + + +class Human(Player): + def __str__(self): + return "Player " + str(self.get_player_index()) + " (human)" + + def militia_input(self, message): + return self.get_general_input(message) diff --git a/player/player.py b/player/player.py index 4715903..5e23599 100644 --- a/player/player.py +++ b/player/player.py @@ -6,7 +6,7 @@ from card.card import Card class Player: - def __init__(self, human, table): + def __init__(self, table): self.__std_chances = 3 self.__deck = Deck() self.__discard = Discard() @@ -14,7 +14,6 @@ class Player: self.__purchase_power = 0 self.__actions = Counter(0) self.__buys = 0 - self.__is_human = human self.__table = table def add_actions(self, n): @@ -186,9 +185,15 @@ class Player: # The following two methods are identical under different names so they can be overridden by bot classes later def get_play_input(self, message): - return int(input(message)) + return self.get_general_input(message) def get_buy_input(self, message): + return self.get_general_input(message) + + def militia_input(self, message): + return self.get_general_input(message) + + def get_general_input(self, message): return int(input(message)) def __print_discard(self): @@ -214,10 +219,4 @@ class Player: self.__purchase_power = 0 def __str__(self): - result = "Player " + str(self.get_player_index()) - - if self.__is_human: - result += " (human)" - else: - result += " (bot)" - return result + return "Player " + str(self.get_player_index()) diff --git a/table/table.py b/table/table.py index c42d44d..6cbaeee 100644 --- a/table/table.py +++ b/table/table.py @@ -60,6 +60,7 @@ class Table: turn += 1 else: self.print() + print("Game had " + str(turn) + " turns in " + str(turn/len(self.__player)) + " rounds.") for p in self.__player: print("" + str(p) + " scored " + str(p.get_score()) + " points.") if p.get_score() > self.__winning_score: