Change input method

master
En Yi 2019-06-04 22:34:41 +01:00
parent 1e71e4aff9
commit 66ee06452b
4 changed files with 56 additions and 43 deletions

View File

@ -30,9 +30,10 @@ class RandomAI:
if self.player: if self.player:
current_round_bid = self.table_status["bid"] // 10 current_round_bid = self.table_status["bid"] // 10
current_suit_bid = self.table_status["bid"] % 10 current_suit_bid = self.table_status["bid"] % 10
gen_bid = random.randint(11, 75) bid_threshold = int(current_round_bid*1.5 + current_suit_bid*0.5)
gen_bid = random.randint(1, bid_threshold)
print(gen_bid) print(gen_bid)
if gen_bid > self.table_status["bid"]: if gen_bid == 1:
if current_suit_bid == 5: if current_suit_bid == 5:
return (current_round_bid+1)*10 + 1 return (current_round_bid+1)*10 + 1
else: else:

View File

@ -13,8 +13,12 @@ from enum import Enum
CARDS_SYMBOLS = {14: "A", 2: "2", 3: "3", 4: "4", 5: "5", 6: "6", 7: "7", CARDS_SYMBOLS = {14: "A", 2: "2", 3: "3", 4: "4", 5: "5", 6: "6", 7: "7",
8: "8", 9: "9", 10: "10", 11: "J", 12: "Q", 13: "K", 8: "8", 9: "9", 10: "10", 11: "J", 12: "Q", 13: "K",
100: "Clubs", 200: "Diamonds", 300: "Hearts", 400: "Spades", 500: "No Trump", 100: "Clubs", 200: "Diamonds", 300: "Hearts", 400: "Spades", 500: "No Trump",
"C": 100, "D": 200, "H": 300, "S": 400, "A": 14} }
INPUT_SYMBOLS = {"c": 100, "d": 200, "h": 300, "s": 400, "n":500, "a": 14,
"2": 2, "3": 3, "4": 4, "5": 5, "6": 6, "7": 7,
"8": 8, "9": 9, "10": 10, "j": 11, "q": 12, "k": 13,
}
class DeckReveal(Enum): class DeckReveal(Enum):
SHOW_ALL = 1 SHOW_ALL = 1
@ -314,6 +318,21 @@ def get_suit_string(value):
return CARDS_SYMBOLS[value*100] return CARDS_SYMBOLS[value*100]
def convert_input_string(string):
try:
return INPUT_SYMBOLS[string[0:-1]] + INPUT_SYMBOLS[string[-1]]
except KeyError:
return -1
def convert_bid_string(string):
try:
return int(string[0])*10 + INPUT_SYMBOLS[string[1]]//100
except KeyError:
return -1
except ValueError:
return -1
class test_screen(view.PygView): class test_screen(view.PygView):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):

View File

@ -5,7 +5,7 @@ import random
import pickle import pickle
import sys import sys
AUTOPLAY = True AUTOPLAY = False
class GameScreen(view.PygView): class GameScreen(view.PygView):

View File

@ -73,8 +73,8 @@ class Table:
self.width = width self.width = width
self.height = height self.height = height
self.table_font = pygame.font.SysFont("None", 30) self.table_font = pygame.font.SysFont("None", 25)
self.player_font = pygame.font.SysFont("None", 30) self.player_font = pygame.font.SysFont("None", 25)
# For gameplay # For gameplay
self.game_state = GameState.DEALING self.game_state = GameState.DEALING
@ -138,7 +138,7 @@ class Table:
self.player_stats = [[], [], [], []] self.player_stats = [[], [], [], []]
# TODO: change surface to use colorkey # TODO: change surface to use colorkey, maybe, if the performance is tanked
for i in range(4): for i in range(4):
vert = i % 2 == 1 vert = i % 2 == 1
self.players.append(Player(playerx[i], playery[i], self.players.append(Player(playerx[i], playery[i],
@ -569,31 +569,25 @@ class Player(cards.Deck):
:return: A valid bid number :return: A valid bid number
""" """
while True: while True:
# TODO: Make a more natural input parsing
bid = input("Please input a bid in the format 'number' + 'suit' \n" bid = input("Please input a bid in the format 'number' + 'suit' \n"
"To pass, enter nothing. \n" "To pass, enter nothing. \n"
"i.e. 42 is 4 Diamond, 65 is 6 No Trump \n" "e.g 4d is 4 Diamond, 6n is 6 No Trump \n")
"Suit Number: 1-Club 2-Diamond 3-Hearts 4-Spades 5-NoTrump\n")
if not bid: if not bid:
return 0 return 0
try:
bid = int(bid) bid = cards.convert_bid_string(bid)
except ValueError: if bid < 0:
print("Please enter integer only") print("Please enter integer only")
if self._table_status["bid"] < bid and self.bid_check(bid): continue
if self._table_status["bid"] < bid:
return bid return bid
else: else:
if bid > 75: if bid > 75:
print("You cannot bid beyond 7 No Trump") print("You cannot bid beyond 7 No Trump")
else: else:
print("Invalid bid") print("You might need to bid higher")
@staticmethod
def bid_check(value):
rounds = value // 10
suit = value % 10
return rounds <= 5 and 1 <= suit <= 5
def call_partner(self): def call_partner(self):
""" """
@ -603,18 +597,16 @@ class Player(cards.Deck):
current_card_values = self.get_deck_values() current_card_values = self.get_deck_values()
while True: while True:
# TODO: Make a more natural input parsing # TODO: Make a more natural input parsing
partner = input("Please call your partner card. Enter suit number + card number\n" partner = input("Please call your partner card. Enter card number + suit number \n"
"i.e 412 is Spade Queen, 108 is Clubs 8, 314 is Hearts Ace\n") "e.g. qs is Queen Spade, 8c is 8 Clubs, ah is Ace Hearts\n")
try:
partner = int(partner) partner = cards.convert_input_string(partner)
if partner in current_card_values: if partner in current_card_values:
print("Please call a card outside of your hand") print("Please call a card outside of your hand")
elif cards.card_check(partner): elif cards.card_check(partner):
return partner return partner
else: else:
print("Invalid card call") print("Invalid card call")
except ValueError:
print("Please enter integer only")
def make_a_play(self, substate): def make_a_play(self, substate):
""" """
@ -623,12 +615,13 @@ class Player(cards.Deck):
""" """
while True: while True:
# TODO: Make a more natural input parsing # TODO: Make a more natural input parsing
play = input("Please play a card. Enter suit number + card number\n" play = input("Please play a card.Enter card number + suit number \n"
"i.e 412 is Spade Queen, 108 is Clubs 8, 314 is Hearts Ace\n") "e.g. qs is Queen Spade, 8c is 8 Clubs, ah is Ace Hearts\n")
if play == "v": if play == "v":
pprint.pprint(self._table_status) pprint.pprint(self._table_status)
else: else:
play = int(play) play = cards.convert_input_string(play)
if play > 0:
if substate == 0: if substate == 0:
valid = self.check_for_valid_plays(play, True) valid = self.check_for_valid_plays(play, True)
else: else: