CCF-CSP 201609-3-炉石传说 (Python) list模拟栈 满分实现

这篇博客详细介绍了如何使用Python模拟炉石传说的战斗过程,包括读取命令、处理命令、战场信息管理和输出结果。通过列表模拟战场状态,处理召唤、攻击、减血和战场清除等操作,并优化了命令处理顺序以确保正确性。
摘要由CSDN通过智能技术生成

201609-3-炉石传说

问题

image-20230310011537042

image-20230310010742427

image-20230310011453028

思路

模拟题:读取命令,命令处理,输出结果

处理命令:用列表存储战场信息[[[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][
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

RessMatthew

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值