Add files via upload

This commit is contained in:
Brad Stein 2018-01-05 03:42:13 -06:00 committed by GitHub
parent 6420860a5e
commit ff84748af9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 52 additions and 21 deletions

View File

@ -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

View File

@ -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.")

10
game.py
View File

@ -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]]

View File

@ -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)"

9
player/human.py Normal file
View File

@ -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)

View File

@ -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())

View File

@ -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: