def verify_prediction(self, hands, limit, turn, trump, predictions, row, score): while hands == limit or not CLI.is_number(hands): CLI.overview(turn, trump, predictions, row, score, self._cards) print('You are the last, '+ self._name + ', \ select number, different from ', limit, ': ') hands = input('==> ') self._prediction = int(hands) return int(hands)
def give_card(self, cards_on_table, trump, turn, row, score): CLI.situation(cards_on_table, trump, turn, row, score, self._cards) print('Please, select a card to give, ' + self._name + ': ') selected_card = input('==> ') card = self.verify_choice(selected_card, cards_on_table, trump, turn, row, score) self._cards.remove(card) return card
def prediction_without_limit(self, turn, trump, predictions, row, score): CLI.overview(turn, trump, predictions, row, score, self._cards) print('How many hands you think you will make, ' + self._name + '?') hands = input('==> ') while not CLI.is_number(hands): CLI.overview(turn, trump, predictions, row, score, self._cards) print('Please, enter a number,' + self._name + '!') hands = input('==> ') self._prediction = int(hands) return int(hands)
def verify_prediction(self, hands, limit, turn, trump, predictions, row, score): while hands == limit or not CLI.is_number(hands): CLI.overview(turn, trump, predictions, row, score, self._cards) print( 'You are the last, ' + self._name + ', \ select number, different from ', limit, ': ') hands = input('==> ') self._prediction = int(hands) return int(hands)
def single_deal(self, row, trump, turn): cards_on_table = OrderedDict() for player in row: card = player.give_card(cards_on_table, trump, turn, row, self._score) cards_on_table[card] = player winner = self.define_winner(cards_on_table, trump) CLI.end_of_turn(cards_on_table, trump, turn, row, self._score, [], winner) winner._hands += 1 self._last_hand = winner
def prediction_with_limit(self, turn, trump, predictions, row, score): all_hands = sum( [value for value in predictions.values() if value != None]) if all_hands > turn: limit = -1 else: limit = turn - all_hands if limit == -1: return self.prediction_without_limit(turn, trump, predictions, row, score) CLI.overview(turn, trump, predictions, row, score, self._cards) hands = input('==> ') while not CLI.is_number(hands): CLI.overview(turn, trump, predictions, row, score, self._cards) print('Please, enter a number, ' + self._name + '!') hands = input('==> ') return self.verify_prediction(int(hands), limit, turn, trump, predictions, row, score)
def prediction_with_limit(self, turn, trump, predictions, row, score): all_hands = sum([value for value in predictions.values() if value != None]) if all_hands > turn: limit = -1 else: limit = turn - all_hands if limit == -1: return self.prediction_without_limit(turn, trump, predictions, row, score) CLI.overview(turn, trump, predictions, row, score, self._cards) hands = input('==> ') while not CLI.is_number(hands): CLI.overview(turn, trump, predictions, row, score, self._cards) print('Please, enter a number, ' + self._name + '!') hands = input('==> ') return self.verify_prediction(int(hands), limit, turn, trump, predictions, row, score)
def verify_choice(self, card, cards_on_table, trump, turn, row, score): rank, suite = self.parse_input(card) while not self.is_card(rank, suite): CLI.situation(cards_on_table, trump, turn, row, score, self._cards) print('Please, select a card, ' + self._name + ': ') selected_card = input('==> ') return self.verify_choice(selected_card, cards_on_table, trump, turn, row, score) while not self.is_card_from_hand(rank, suite): CLI.situation(cards_on_table, trump, turn, row, score, self._cards) print('Please, select a card from your hand, ' + \ self._name + ': ') selected_card = input('==> ') return self.verify_choice(selected_card, cards_on_table, trump, turn, row, score) while not self.is_right_suite(suite, cards_on_table): CLI.situation(cards_on_table, trump, turn, row, score, self._cards) print('Please, select a card with proper suite, ' + \ self._name + ': ') selected_card = input('==> ') return self.verify_choice(selected_card, cards_on_table, trump, turn, row, score) return self.the_card(rank, suite)
def start(): CLI.clear_window() print() print('Hi, you might want to play Ohio?!') print() print('OK, how many people will play? (from 1 to 4)') number = input('==> ') while not CLI.is_number(number) or int(number) not in range(0, 5): CLI.clear_window() print() print('Hi, you might want to play Ohio?!') print() print('Please, enter a number from 1 to 4!') number = input('==> ') players = [] number = int(number) for n in range(1, number + 1): CLI.clear_window() print() print('Please, enter a name for the ' + str(n) + ' player: ') name = input('==> ') players.append(RealPlayer(name)) for n in range(1, 5 - number): players.append(AIPlayer('AIRobot' + str(n))) CLI.clear_window() print() print('Players are ready to play!') print() for player in players: print(player._name) game = Game(players) print() ok = input('Press any key to start the game...') game.start()
def _setup_cli(self): option_sep = str(self.option_sep)[0] name_sep = str(self.name_sep)[0] cli = CLI(option_sep, name_sep) #Setting home_conf_path to a valid path will enable reading home options #from a file other than the default file. #self.home_conf_path = cli.arguments(ui_name.home_conf_path) self.operation = cli.arguments[ui_name.operation] self.ui_arguments = cli.arguments self.ticket_id = cli.arguments.get(ui_name.ticket_id) self.source_dir = cli.arguments.get(ui_name.source_dir) self.include = cli.arguments.get(ui_name.include) self.context = cli.arguments.get(ui_name.context) self.target = cli.arguments.get(ui_name.target) project_code = cli.arguments.get(ui_name.project_code) self.project_code = project_code and project_code.strip().upper()
import numpy as np import random from game import Joueur from game import Jeu from ui import CLI if __name__ == "__main__": ###################### Test de la fonction distribuer et de la fonction afficherJeu ################ ui = CLI() A = Joueur("jen1", 1, 1) B = Joueur("jen2", 1, 1) C = Joueur("jen3", 1, 1) D = Joueur("jen4", 1, 1) jeu = Jeu(A, B, C, D, ui) # jeu.distribuerCarte(5) # jeu.afficherJeu() jeu.jouer(1) ###################### Fin du Test ######################################## #A faire: Gestion de l'initialisation des joueurs avec la création du jeu (de la partie).