201609-3-炉石传说
问题
思路
模拟题:读取命令,命令处理,输出结果
处理命令:用列表存储战场信息
[[[0,30],], [[0,30],]]
# 先手filed_list[0]: [[攻击,生命],] 后手filed_list[1]
- summon:
insert(index)
插入来实现其它右移- attack:
- 减血
- 清除战场判断
pop(index)
删除来实现其它左移- end:当前游戏玩家切换
输出结果
实现
n = int(input()) # 操作个数
command_list = list() # 总命令列表 e-[('summon',1,3,6),]
for _ in range(n):
command_detail_list = input().strip().split() # 单条命令列表 e-['summon','1','3','6']
length = len(command_detail_list) # 命令+参数的个数
if length == 4:
command_list.append(('summon',) + tuple(map(int, command_detail_list[1:])))
elif length == 3:
command_list.append(('attack',) + tuple((map(int, command_detail_list[1:]))))
elif length == 1:
command_list.append(('end',))
# print(command_list)
filed_list = [[[0,30],], [[0,30],]] # 先手filed_list[0]: [[攻击,生命],] 后手filed_list[1]
a = 0 # 当前玩家 0-先手,1-后手
flag = 0 # 结束标志 0-平局,1-先手赢,-1-后手赢
for command in command_list: # e-('summon',1,3,6)
if command[0] == 'summon':
filed_list[a].insert(command[1], list(command[2:]))
elif command[0] == 'attack': # e-('summon',1,2)
d = 0 if a==1 else 1 # 被攻击者
attacker, defender = command[1:]
filed_list[a][attacker][