CSP-201609-3-炉石传说

本文详细解析了一段游戏战斗模拟的代码实现,包括英雄和随从的召唤、攻击逻辑、死亡处理及游戏胜负判断。通过具体示例展示了如何使用C++进行游戏状态管理,以及如何运用stringstream进行字符串处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目

在这里插入图片描述在这里插入图片描述在这里插入图片描述

注意事项

1.英雄死后血量清零
2.注意每次状态改变后更改个数组的值
3.掌握stringstream,可以用于格式转换、读取字符串

代码

//英雄死后血量清零
//注意每次状态改变后更改个数组的值 
#include<iostream>
#include<sstream>
#include<string>
#include<string.h>
using namespace std;

struct player
{
	int h,a;
	player(){
	} 
	player(int _a,int _h)
	{
		a=_a;
		h=_h;
	}
}players[5][10];//一维:先手后手,二维:角色 

int pos[5][10];//表示位置是否有角色 
int tot[5];//双方玩家的随从数目 
int winner=2;//未决出胜负

void hero()
{
	tot[1]=tot[2]=0;
	player p(0,30);
	players[1][0]=p;
	players[0][0]=p;

	
	
}
void scgodie(int xh,int poss)
{
	for(int i=poss+1;i<=tot[xh];i++)
		players[xh][i-1]=players[xh][i];
	pos[xh][tot[xh]]=0;
	tot[xh]--;
	
}
int hgodie(int xh,int poss)
{
	int flag=0;
	if(poss==0)//英雄死了
	{
		//游戏结束 
		flag=1;
		//把英雄的血量=0
		players[xh][0].h=0; 
		winner=(xh+1)%2;
	} 
	else
	{
		for(int i=poss+1;i<=tot[xh];i++)
			players[xh][i-1]=players[xh][i];
		pos[xh][tot[xh]]=0;
		tot[xh]--;
		
	}
	return flag;
}
void output()
{
	if(winner==0)//先手赢
		cout<<1<<endl;
	else if(winner==1)
		cout<<-1<<endl;
	else cout<<0<<endl;
	
	for(int k=0;k<=1;k++)
	{
		
		cout<<players[k][0].h<<endl<<tot[k]<<' ';
		for(int i=1;i<=tot[k];i++)
			cout<<players[k][i].h<<' ';
		cout<<endl;
	}
}
int main()
{
	int n;int xianhou=0;//1表示先手, 2后手 
	cin>>n;
	string str;
	getchar();//吸收换行符,不然getline会获取缓冲区里的换行符 
	
	
	//设置英雄
	hero(); 
	
	while(n--)
	{
		getline(cin,str);//对于 string,getline可以获取含有空格的字符串,遇到换行自动结束
		if(str=="end")
		{
			xianhou++;
			xianhou%=2;
			continue;
		}
		stringstream sstream(str);
		string tmp;
		sstream>>tmp;//读入第一个操作符 
		if(tmp=="summon")
		{
			int t1,t2,t3;
			sstream>>t1>>t2>>t3;
			player p(t2,t3);
			if(pos[xianhou][t1]==1)//该位置已有角色
			{
				for(int i=tot[xianhou]+1;i>=t1+1;i--)
				{
					players[xianhou][i]=players[xianhou][i-1];
				}
				pos[xianhou][tot[xianhou]+1]=1;//最右边的位置 
			}
			else
			{
				pos[xianhou][t1]=1;
				
			} 
			tot[xianhou]++;
			players[xianhou][t1]=p;
		}
		else if(tmp=="attack")
		{
			int t1,t2;
			sstream>>t1>>t2;
			int other=(xianhou+1)%2;//对方 
			//生命力down down 
			players[xianhou][t1].h-=players[other][t2].a;
			players[other][t2].h-=players[xianhou][t1].a;
			//如果有角色失血过多go die,判断他是英雄还是随从(但攻击的一方肯定是随从) 
			int f;
			if(players[xianhou][t1].h<=0)scgodie(xianhou,t1);//此方随从死了 
			if(players[other][t2].h<=0)f=hgodie(other,t2);
			if(f==1)//游戏结束
				break;
		}

		
	}
	output();	
	return 0;
 } 
 
 
 
 
 
 
### LlamaIndex 多模态 RAG 实现 LlamaIndex 支持多种数据类型的接入与处理,这使得它成为构建多模态检索增强生成(RAG)系统的理想选择[^1]。为了实现这一目标,LlamaIndex 结合了不同种类的数据连接器、索引机制以及强大的查询引擎。 #### 数据连接器支持多样化输入源 对于多模态数据的支持始于数据收集阶段。LlamaIndex 的数据连接器可以从多个异构资源中提取信息,包括但不限于APIs、PDF文档、SQL数据库等。这意味着无论是文本还是多媒体文件中的内容都可以被纳入到后续的分析流程之中。 #### 统一化的中间表示形式 一旦获取到了原始资料之后,下一步就是创建统一而高效的内部表达方式——即所谓的“中间表示”。这种转换不仅简化了下游任务的操作难度,同时也提高了整个系统的性能表现。尤其当面对复杂场景下的混合型数据集时,良好的设计尤为关键。 #### 查询引擎助力跨媒体理解能力 借助于内置的强大搜索引擎组件,用户可以通过自然语言提问的形式轻松获得所需答案;而对于更复杂的交互需求,则提供了专门定制版聊天机器人服务作为补充选项之一。更重要的是,在这里实现了真正的语义级关联匹配逻辑,从而让计算机具备了一定程度上的‘认知’功能去理解和回应人类意图背后所蕴含的意义所在。 #### 应用实例展示 考虑到实际应用场景的需求多样性,下面给出一段Python代码示例来说明如何利用LlamaIndex搭建一个多模态RAG系统: ```python from llama_index import GPTSimpleVectorIndex, SimpleDirectoryReader, LLMPredictor, PromptHelper, ServiceContext from langchain.llms.base import BaseLLM import os def create_multi_modal_rag_system(): documents = SimpleDirectoryReader(input_dir='./data').load_data() llm_predictor = LLMPredictor(llm=BaseLLM()) # 假设已经定义好了具体的大型预训练模型 service_context = ServiceContext.from_defaults( chunk_size_limit=None, prompt_helper=PromptHelper(max_input_size=-1), llm_predictor=llm_predictor ) index = GPTSimpleVectorIndex(documents, service_context=service_context) query_engine = index.as_query_engine(similarity_top_k=2) response = query_engine.query("请描述一下图片里的人物表情特征") print(response) ``` 此段脚本展示了从加载本地目录下各类格式文件开始直到最终完成一次基于相似度排序后的top-k条目返回全过程。值得注意的是,“query”方法接收字符串参数代表使用者想要询问的内容,而在后台则会自动调用相应的解析模块并结合先前准备好的知识库来进行推理计算得出结论。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值