猫史档案馆


求各位c++大佬们给优化方案

用户:萌新大佬萌新大佬查看:0 回复:0 评论:0 创建时间:2022-02-25T17:02:53


#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
void gotoxy(int x,int y){
	COORD pos={y,x};  
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
void hide(){
    HANDLE handle=GetStdHandle(STD_OUTPUT_HANDLE); 
    CONSOLE_CURSOR_INFO CursorInfo; 
    GetConsoleCursorInfo(handle, &CursorInfo);
    CursorInfo.bVisible = false;
    SetConsoleCursorInfo(handle, &CursorInfo);
}
void print(string a,int r,int g,int b){
	wprintf(L"\x1b[38;2;%d;%d;%dm%s",r,g,b,a.c_str());
}
struct cell{
	int g,f,s;
}c[30][30];
bool st(cell a,cell b){
	if(a.g-b.f>b.g-a.f)return 1;
	return 0;
}
void f(cell a,int i,int j){
	gotoxy(i-1,j*2-2);
	print("■",a.g,a.f,a.s);
	c[i][j]=a;
}
void att(int x,int y,int i,int j){
	int a=c[x][y].g-c[i][j].f,b=c[j][i].g-c[x][y].f;
	if(a>0)
		c[i][j].s-=a;
	if(b>0)
		c[x][y].s-=b;
	gotoxy(x-1,y*2-2);
	print("■",c[x][y].g,c[x][y].f,c[x][y].s);
	gotoxy(i-1,j*2-2);
	print("■",c[i][j].g,c[i][j].f,c[i][j].s);
}
int de[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
int main(){
    HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);
    if(hOut==INVALID_HANDLE_VALUE)return GetLastError();
    DWORD dwMode=0;
    if(!GetConsoleMode(hOut,&dwMode))return GetLastError();
    dwMode|=0x0004;
    if(!SetConsoleMode(hOut,dwMode))return GetLastError();
    hide();
	memset(c,0x3f,sizeof(c)); 
    srand(time(0));
	for(int i=1;i<=25;i++){
		for(int j=1;j<=25;j++){
			c[i][j].g=127;
			c[i][j].f=127; 
			c[i][j].s=127;
			print("■",c[i][j].g,c[i][j].f,c[i][j].s);
		}
		cout<<endl;
	}
	while(1){
		for(int i=1;i<=25;i++){
			for(int j=1;j<=25;j++){
				int p=rand()%3;
				if(p){
					for(int k=0;k<4;k++){
						if(i+de[k][0]>=1&&i+de[k][0]<=25&&j+de[k][1]>=1&&j+de[k][1]<=25){
							if(c[i+de[k][0]][j+de[k][1]].s<=0&&c[i][j].s>0)
								f(c[i][j],i+de[k][0],j+de[k][1]);
							else
								att(i,j,i+de[k][0],j+de[k][1]);
						}
					}
				}
				else{
					int q=rand()%100-49;
					c[i][j].g+=q;
					q=rand()%100-49;
					c[i][j].f+=q;
					if(c[i][j].f>255)c[i][j].f=255;
					if(c[i][j].s>255)c[i][j].s=255;
					if(c[i][j].g>255)c[i][j].g=255;
				}
				c[i][j].s++;
			}
		}
	}
	return 0;
}

想了半天只能挨个的搜,这样左上角就占优势,怎么办

代码用处:

每个格子是一个细胞

用RGB表示细胞的三种属性:攻击,防御,生命


回复

上一页1 页 / 共 0下一页