def main(argv): try: opts, args = getopt.getopt(argv, "ha:d:g:", ["attacker=", "defender=", "game="]) except getopt.GetoptError: print('big2.py -a <attacker> -d <defender> -g <game>') sys.exit(2) Tom = Jack = game = None for opt, arg in opts: if opt == '-h': print('big2.py -a <attacker> -d <defender> -g <game>') sys.exit() elif opt in ("-a", "--attacker"): Tom = choosePlayer(arg) elif opt in ("-d", "--defender"): Jack = choosePlayer(arg) elif opt in ("-g", "--game"): game = int(arg) if not Tom or not Jack or not game: print('big2.py -a <attacker> -d <defender> -g <game>') sys.exit(3) Annie = Dealer("Version1") cards = Annie.deal(game) Tom.newGame(copy.copy(cards[0]), copy.copy(cards[1]), Jack.teamName()) Jack.newGame(copy.copy(cards[1]), copy.copy(cards[0]), Tom.teamName()) print("{:<80}".format(Tom.teamName())) print("{:<80}".format(str(cards[0]))) print("{:>80}".format(Jack.teamName())) print("{:>80}".format(str(cards[1]))) print("-" * 80) #Tom.play(['A', 'J', '2', '3', '3', '5', '10'], [7, 7, 8], [8])) t, player, score = [], None, None while not score: # Tom 先手,然后轮流出牌 player = Tom if not player or player is Jack else Jack t = player.play(t) score, t = Annie.check(t) output = "{:<80}" if player is Tom else "{:>80}" print(output.format(str(t) if t else "pass")) player.ack(t) # player获知Annie的裁定 else: print("{} is the winner! score={}".format(player.teamName(), score))
def main(argv): try: opts, args = getopt.getopt(argv, "ha:d:g:", ["attacker=", "defender=", "game="]) except getopt.GetoptError: print('big2.py -a <attacker> -d <defender> -g <game>') sys.exit(2) Tom = Jack = game = None for opt, arg in opts: if opt == '-h': print('big2.py -a <attacker> -d <defender> -g <game>') sys.exit() elif opt in ("-a", "--attacker"): Tom = choosePlayer(arg) elif opt in ("-d", "--defender"): Jack = choosePlayer(arg) elif opt in ("-g", "--game"): game = int(arg) if not Tom or not Jack or not game: print('big2.py -a <attacker> -d <defender> -g <game>') sys.exit(3) Annie = Dealer("Version1") cards = Annie.deal(game) Tom.newGame(copy.copy(cards[0]), copy.copy(cards[1]), Jack.teamName()) Jack.newGame(copy.copy(cards[1]), copy.copy(cards[0]), Tom.teamName()) print("{:<80}".format(Tom.teamName())) print("{:<80}".format(str(cards[0]))) print("{:>80}".format(Jack.teamName())) print("{:>80}".format(str(cards[1]))) print("-" * 80) #Tom.play(['A', 'J', '2', '3', '3', '5', '10'], [7, 7, 8], [8])) t, player, score = [], None, None while not score: # Tom 先手,然后轮流出牌 player = Tom if not player or player is Jack else Jack try: # t = player.play(t.copy()) time_out = RunWithTimeout(player.play, t.copy()) t = time_out.run(33) if len(t) == 1 and (t[0] == 'timeout' or t[0] == 'error'): print(t[0]) t = [] score, t = Annie.check(t) except: print('error2') score, t = Annie.check([]) output = "{:<80}" if player is Tom else "{:>80}" print(output.format(str(t) if t else "pass")) try: player.ack(t.copy()) # player获知Annie的裁定 except: pass else: print("{} is the winner! score={}".format(player.teamName(), score)) with open('result/%s.txt' % game, 'a+') as f: f.write(Tom.teamName()) if player.teamName() == Tom.teamName(): f.write(' win ') else: f.write(' loss ') score = -score f.write(Jack.teamName()) f.write(' ') f.write(str(score)) f.write('\n') print('write')