import random
from random import choice
li = [1, 2, 3]
dict1 = {1: '石头', 2: '剪刀', 3: '布'}
while True:
# 第一轮
player_lift = int(input('(石头 1, 剪刀 2, 布 3)\n请输入您的左手拳型:'))
if player_lift not in li:
print('请输入正确的拳型')
continue
computer_lift = random.randint(1, 3)
print(f'电脑出:{dict1[computer_lift]}')
# 第二轮
player_right = int(input('请输入您的右手拳型:'))
while player_right not in li:
player_right = int(input('请输入正确的拳型:'))
# 电脑根据第一次的优劣判断,也可随机,也可建立模型
# 0平局,1玩家优,-1电脑优
# outcome = 0 if player_lift == computer_lift else 1 if (player_lift - computer_lift) % 3 == 2 else -1
# 若玩家优或平,则出能胜玩家第一轮的拳型,若电脑优则出除第一轮之外的拳型
# 经大佬指点,不需要判断,随机才能保证游戏的可玩性
lis = [1, 2, 3]
lis.remove(computer_lift)
# computer_right = choice(lis) if outcome == -1 else (player_lift - 2) % 3 + 1
computer_right = choice(lis)
print(f'电脑出:{dict1[computer_right]}')
player_back = int(input(f'您: {dict1[player_lift]} {dict1[player_right]}\n电脑:{dict1[computer_lift]} {dict1[computer_right]}\n请输入您要收回的拳型:'))
while player_back not in [player_lift, player_right]:
player_back = int(input('请输入正确的拳型:'))
# 结果
computer = choice([computer_lift, computer_right])
print(f'电脑留{dict1[computer]}')
player = player_lift if player_back == player_right else player_right
print(f'您留{dict1[player]}')
print('平局' if player == computer else '玩家胜' if (player-computer) % 3 == 2 else '电脑胜')