示例#1
0
文件: logic.py 项目: CezCz/Chlew
 def check(game):
     """
     Checks, who won a particular game. If there is extra time to round the players are entered overtime.
     :param game: game state
     :return:
     """
     winners = []
     round = game["round"]
     best_card = game["table"][round[0]][-1]
     for player in round:
         card = game["table"][player][-1]
         if Cards.cmp(card, best_card) > 0:
             best_card = card
     for player in round:
         card = game["table"][player][-1]
         if Cards.cmp(card, best_card) == 0:
             winners.append(player)
     if len(winners) == 1:
         for cards in game["table"]:
             game["players"][winners[0]] += cards
             game["table"] = [[] for i in range(len(game["players"]))]
             game["round"] = [i for i in range(len(game["players"])) if game["players"][i] is not None]
             game["queue"] = game["round"].copy()
     else:
         game["round"] = winners
         game["queue"] = []
         for player in winners:
             game["queue"].append(player)
             game["queue"].append(player)
示例#2
0
文件: logic.py 项目: CezCz/Chlew
 def new_game(players):
     """
     Creates new game state
     :param players: number of players
     :return: new game state
     """
     if players < 2 or players > 4:
         print("The number of players from 2 to 4.")
     else:
         deck = Cards.new_deck()
         Cards.shuffle(deck)
         x = len(deck) // players
         return {
             "players": [deck[i * x:x * (i + 1)] for i in range(players)],
             "table": [[] for i in range(players)],
             "round": list(range(players)),
             "queue": list(range(players)),
         }