12 c++版本的坦克大战

前言

呵呵 这大概是 大学里面的 c++ 贪吃蛇了吧 

有一些 面向对象的理解, 但是不多 

这里 具体的实现 就不赘述, 仅仅是 发一下代码 以及 具体的使用 

 

 

坦克大战

#include<iostream>
#include<windows.h>
#include<conio.h>
#include<ctime>
#include<string>
#include<list>
using namespace std;
#define N 4
class Tank_War;
void set_pos(int x, int y);
class Object
{	
protected:
	int x, y;
	int dir;
	int life;

public:
	Object() : x(0), y(0), dir(-1),life(1)	{}
	Object(int x, int y, int dir, int life) : x(x), y(y), dir(dir), life(life) {}	 
	void move();
	void paint()  {	}
	void reduce_blood()	{	life -= 1; 	}
	void increase_blood()	{	life += 1; 	}
	bool is_failure();
	virtual void print(){cout<<x<<"--"<<y<<"=="<<life<<"--"<<endl;}
};

class Missile : public Object
{
public:
	Missile() : Object() {}
	Missile(int x, int y, int dir, int life) : Object(x, y, dir, life) {}
	bool move();
	void paint(string icon);
	int get_x()const	{	return x;	}
	int get_y()const	{	return y;	}
	void set_info(int x, int y, int dir) {	this -> x = x; this -> y = y; this -> dir = dir;	};
	bool operator==(const Missile&_x){return (x==_x.x && y==_x.y&&dir==_x.dir);		}		//list中remove是需要重载==
};

class Tank : public Object
{
private:
	int pre_dir;
	list<Missile> missile_list;

public:
	Tank() : Object(), pre_dir(-1) {}
	Tank(int x, int y, int dir, int life) : Object(x, y, dir,life) {pre_dir = dir;};
	void del_before_move();
	void move(Tank_War &game, string name);
	void paint(string icon);
	int get_x()	const	{	return x;	}
	int get_y()	const	{	return y;	}
	int get_dir()const	{	return dir;	}
	void set_dir(int dir){	pre_dir = this -> dir;	this -> dir = dir;	}
	void set_location(int x, int y){	this -> x = x;	this -> y = y;	}
	void emission_missile();
	void missile_move();
	void check_missile(Tank_War &game, string name);
	bool check_missile_strike(Missile& missile, Tank& tank);
//	bool check_is_right(int x, int y, int dir);
	int distance_squre(int x_1, int y_1, int x_2, int y_2);
	int distance_squre(Tank& tank_2);
	bool operator==(const Tank&_x){return (x==_x.x && y==_x.y&&dir==_x.dir);		}
};


class Tank_War
{
private:
	Tank lead;
	list<Tank> enemy_list;
	int tot;
	int grade;
	bool over;

public:
	Tank_War():lead(28, 21, -1, 4), grade(0), tot(0), over(false) {};
	int game();
	void game_over()	{	over = true;	}
	int draw_menu();
	void draw_game_interface();
	Tank* get_lead()	{	return &lead;	}
	list<Tank>::iterator get_enemy_list_begin()	{	return enemy_list.begin();	}
	list<Tank>::iterator get_enemy_list_end()	{	return enemy_list.end();	}
	Tank* create_enemy();
	void enemy_move();
//	bool check_is_right(int x, int y, int dir);
	bool can_move(Tank &tank, string name);
	bool can_move(Tank& x, Tank& y);
	void check_missile(string name);
	void supply_enemy();
	int get_random_direction();
	list<Tank>::iterator remove_from_enemy_list(list<Tank>::iterator it)	{	return enemy_list.erase(it);		}
	void reduce_tot()	{	tot--;	}
	void increase_grade()	{	grade+=5;set_pos(68, 3);cout<<grade;	}
};


int main()
{
	Tank_War g;
	g.game();

	system("pause");
	return 0;
}


int Tank_War::game()
{
	bool is_move = true;
	int speed = draw_menu();
	system("cls");
	draw_game_interface();
	supply_enemy();
	while(!over)
	{
		if(!lead.is_failure())
		{
			if(tot<N) 	supply_enemy();
			if(GetAsyncKeyState(VK_UP))	lead.set_dir(-1);
			else if(GetAsyncKeyState(VK_DOWN))	lead.set_dir(1);
			else if(GetAsyncKeyState(VK_LEFT))	lead.set_dir(-2);
			else if(GetAsyncKeyState(VK_RIGHT))	lead.set_dir(2);
			else is_move = false;
			if(is_move) lead.move(*this, "lead");	
			enemy_move();
			if(GetAsyncKeyState(VK_RETURN))	lead.emission_missile();	
			if(enemy_list.size() != 0)
			{
			check_missile("lead");
			check_missile("enemy");
			}		
		}
		is_move = true;
		lead.missile_move();

		Sleep(100);
	}

	return 0;
}

void set_pos(int x, int y)
{
	HANDLE cursor = GetStdHandle(STD_OUTPUT_HANDLE);
	COORD position = {x, y};
	SetConsoleCursorPosition(cursor, position);
}

void draw_rect(int x_1, int y_1, int x_2, int y_2, string icon)
{
	if(x_1 > x_2)	swap(x_1, x_2);
	if(y_1 > y_2)	swap(y_1, y_2);
	int n_1 = y_2 - y_1 + 1;
	int n_2 = (x_2 - x_1)/icon.size() + 1;
	for(int i=0; i<n_1; i++)
	{
		set_pos(x_1, y_1+i);
		for(int j=0; j<n_2; j++)
			cout<<icon;
	}
} 

int Tank_War::draw_menu()
{
	int speed = 0;

	draw_rect(0, 3, 79, 3, "-");
	draw_rect(0, 5, 79, 5, "-");
	set_pos(25, 2);
	cout<<"welcome to airplane war games ";
	set_pos(25, 4);
	cout<<"↑ up   ↓ down   enter confirm";
	set_pos(20, 10);
	cout<<"1.easy		easy mode enemy move slow";
	set_pos(20, 14);
	cout<<"2.difficult		difficult mode enemy move fast";
	set_pos(20, 20);
	cout<<"made by He Xiong .   begin at 2014_01_08";
	draw_rect(0, 19, 79, 19, "-");
	draw_rect(0, 22, 79, 22, "-");

	set_pos(18, 10);
	cout<<"->";
	int y = 10;
	while(true)
	{
		if(GetAsyncKeyState(VK_UP) || GetAsyncKeyState(VK_DOWN))
		{
			if(y == 10)
			{
				set_pos(18, y);		cout<<"  ";
				y = 14;
				set_pos(18, y);		cout<<"->";
				speed = 1;
			}
			else if(y == 14)
			{
				set_pos(18, y);		cout<<"  ";
				y = 10;
				set_pos(18, y);		cout<<"->";
				speed = 0;
			}
		}
		else if(GetAsyncKeyState(VK_RETURN))		break;
		Sleep(200);
	}
	return speed;
}

void Tank_War::draw_game_interface()
{
	draw_rect(0, 0, 78, 0, "◆");
	draw_rect(0, 23, 78, 23, "◆");
	draw_rect(0, 1, 0, 22, "◆");
	draw_rect(58, 1, 58, 22, "◆");
	draw_rect(78, 1, 78, 22, "◆");
	int x = 62;
	set_pos(x, 3);		cout<<"GRADE:0";
	set_pos(x, 5);		cout<<"LEVEL:1";
	set_pos(62, 7);		cout<<"↑ UP";
	set_pos(x, 9);		cout<<"↓ down";
	set_pos(x, 11);		cout<<"← left";
	set_pos(x, 13);		cout<<"→ right";
	set_pos(x, 17);		cout<<"life:■■";
	set_pos(x+5, 18);	cout<<"■■";
	lead.set_location(28, 10);
	lead.paint("■");
	set_pos(0, 0);
}

Tank* Tank_War::create_enemy()
{
	int n = 0, k = 0;
	int x = 0, y = 0, dir = 0;
	Tank *p = NULL;
	srand((unsigned)time(NULL));
	while(k != 4)
	{
		n = rand()%2;
		if(n%2 == 0)
		{
			x = 4;			n = rand()%2;
			if(n%2 == 0)	y = 2;
			else			y = 21;
		}
		else
		{
			x = 54;			n = rand()%2;
			if(n%2 == 0)	y = 2;
			else			y = 21;
		}
		dir = get_random_direction();
		p = new Tank(x, y, dir, 1);
		enemy_list.push_back(*p);
		if(can_move(*p, "enemy")){	break;	}
		else	{	enemy_list.pop_back();	delete p;	p = NULL;	}
		k++;
	}
	return p;
}
/*
bool Tank::check_is_right(int x, int y, int dir)
{
	if(distance_squre(x, y, this -> x, this -> y) > 9)
	return true;
	else return false;
}
*//*
bool Tank_War::check_is_right(int x, int y, int dir)
{
	int flag = 0;
	if(!lead.check_is_right(x, y, dir))	++flag;
	list<Tank>::iterator it = NULL;
	for(it=enemy_list.begin(); it!=enemy_list.end(); ++it)
		if(!it -> check_is_right(x, y, dir))	++flag;
	if(flag == 0)	return true;
	else			return false;
}
*/
void Tank_War::supply_enemy()
{
	int n = N - tot;
	Tank *p = NULL;
	for(int i=0; i<n; i++)
	{
		if((p = create_enemy()) != NULL)
		{
		tot++;			p -> paint("■");
		delete p;		p = NULL;
		}
	}
}

void Missile::paint(string icon)
{
	set_pos(x, y);	cout<<icon;
}

void Tank::paint(string icon)
{
	draw_rect(x-2, y, x+2, y, icon);
	draw_rect(x, y-1, x, y+1, icon);
	if((dir+2)%2 == 0)
	{
		set_pos(x-dir, y-1);	cout<<icon;
		set_pos(x-dir, y+1);	cout<<icon;
	}
	else if((dir+2)%2 == 1)
	{
		set_pos(x-2, y-dir);	cout<<icon;
		set_pos(x+2, y-dir);	cout<<icon;
	}

/*					//不是很好,前面两点的会闪
	set_pos(x-2, y-1);
	cout<<"■■■";
	set_pos(x-2, y);
	cout<<"■■■";
	set_pos(x-2, y+1);
	cout<<"■■■";
	if((dir+2)%2 == 0)
	{
		set_pos(x+dir, y-1);	cout<<"  ";
		set_pos(x+dir, y+1);	cout<<"  ";
		draw_rect(x-dir, y-1, x-dir, y+1);
	}
	else if((dir+2)%2 == 1)
	{
		set_pos(x-1, y+dir);	cout<<"  ";
		set_pos(x+1, y+dir);	cout<<"  ";
		draw_rect(x-2, y-dir, x+2, y-dir);
	}
*/
}

bool Missile::move()
{
	if(x>2 && x<56 && y>1 && y <22)
	{
	if((dir+2)%2 == 0)
	{
		set_pos(x, y);	cout<<"  ";
		x += dir;		paint("●");
	}
	else if((dir+2)%2 == 1)
	{
		set_pos(x, y);	cout<<"  ";
		y += dir;		paint("●");
	}
	return true;
	}
	else
	{
		if(x==0 || x==58 || y==0 || y==23)	;
		else
		{	
			set_pos(x, y);	cout<<"  ";
		}
		return false;
	}
}

void Tank::move(Tank_War& game, string name)
{
	if(x>2 && x<56 && y>1 && y <22)
	if((dir+2)%2 == 0)
	{
		Tank p(x+dir, y, dir, 1);
		if(x+dir>2 && x+dir<56)
		{
		if(game.can_move(p, name))
		{
		//draw_rect(x-dir, y-1, x-dir, y+1, "  ");
		//draw_rect(x+dir, y, x+dir, y, "  ");	//为了解决在角落是的BUG
		del_before_move();
		x+=dir;
		paint("■");
		}
		}
		else 
		{
			if(pre_dir > 0)	draw_rect(x+dir, y-1, x+dir, y-1, "  ");
			else	draw_rect(x+dir, y+1, x+dir, y+1, "  ");
			paint("■");
		}
	}
	else
	{
		Tank p(x, y+dir, dir, 1);
		if(y+dir>1 && y+dir<22)
		{
		if(game.can_move(p, name))
		{
		del_before_move();
		y+=dir;
		paint("■");
		}
		}
		else 
		{
			if(pre_dir > 0)	draw_rect(x-2, y+dir, x-2, y+dir, "  ");
			else	draw_rect(x+2, y+dir, x+2, y+dir, "  ");
			paint("■");
		}
	}

}

void Tank::del_before_move()
{
	if(pre_dir == dir)	
		if((dir + 2) % 2 == 0)	draw_rect(x-dir, y-1, x-dir, y+1, "  ");
		else	draw_rect(x-2 , y-dir, x+2, y-dir, "  ");
	else if(pre_dir == -dir)	
		if((dir + 2) % 2 == 0)	draw_rect(x+pre_dir, y, x+pre_dir, y, "  ");
		else	draw_rect(x , y+pre_dir, x, y+pre_dir, "  ");
	else if(pre_dir == 2/dir)	
		if((dir + 2) % 2 == 0)	draw_rect(x-dir, y, x-dir, y-pre_dir, "  ");
		else	draw_rect(x, y-dir, x-pre_dir, y-dir, "  ");
	else
		if((dir + 2) % 2 == 0)	draw_rect(x-dir, y, x-dir, y-pre_dir, "  ");
		else	draw_rect(x, y-dir, x-pre_dir, y-dir, "  ");
}

bool Tank_War::can_move(Tank& tank, string name)
{
	if(name == "lead")
	{
		list<Tank>::iterator it = NULL;
		if(enemy_list.size() != 0)
		{
			for(it=enemy_list.begin(); it!=enemy_list.end(); it++)
			{
				if(!can_move(*it, tank))	return false;
			}
		}
	}
	else
	{
		int flag = 0;
		if(!can_move(lead, tank))	return false;
		list<Tank>::iterator it = NULL;
		if(enemy_list.size() != 0)
		{
			for(it=enemy_list.begin(); it!=enemy_list.end(); it++)
			{	
				if(!can_move(*it, tank)) flag++;
				/*
				if(tank == *it)	
				{
					if(flag)	flag = false;
					else		return false;
				}
				else
				{
					if(!can_move(tank,tank.get_dir() , *it))	return false;
				}
				*/
			}
			if(flag!=1) return false;
			else return true;
		}
	}

	return true;
}

bool Tank_War::can_move(Tank& tank_1, Tank& tank_2)
{
	int x_1 = 0, x_2 = 0, y_1 = 0, y_2 = 0;
	int dis = tank_1.distance_squre(tank_2);
	if(dis > 8)	return true;

	else if(dis == 8)
	{
		if((tank_1.get_dir()+2)%2 == 0)
		{
		if(tank_1.get_dir() > 0)	
		{
			x_1 = tank_1.get_x();	x_2 = tank_2.get_x();
			y_1 = tank_1.get_y();	y_2 = tank_2.get_y();
		}
		else
		{
			x_1 = tank_2.get_x();	x_2 = tank_1.get_x();
			y_1 = tank_2.get_y();	y_2 = tank_1.get_y();
		}
		if(x_1 > x_2)
		{
			if(y_1 > y_2)
			{
			if(tank_2.get_dir() == tank_1.get_dir() || tank_2.get_dir() == 2/tank_1.get_dir())	return true;
			else	return false;
			}
			else
			{
			if(tank_2.get_dir() == tank_1.get_dir() || tank_2.get_dir() == -2/tank_1.get_dir())	return true;
			else	return false;
			}
		}
		else		return true;

		}
		else
		{
		if(tank_1.get_dir() > 0)	
		{
			x_1 = tank_1.get_x();	x_2 = tank_2.get_x();
			y_1 = tank_1.get_y();	y_2 = tank_2.get_y();
		}
		else
		{
			x_1 = tank_2.get_x();	x_2 = tank_1.get_x();
			y_1 = tank_2.get_y();	y_2 = tank_1.get_y();
		}
		if(y_1 > y_2)
		{
			if(x_1 > x_2)
			{
			if(tank_2.get_dir() == tank_1.get_dir() || tank_2.get_dir() == 2/tank_1.get_dir())	return true;
			else	return false;
			}
			else
			{
			if(tank_2.get_dir() == tank_1.get_dir() || tank_2.get_dir() == -2/tank_1.get_dir())	return true;
			else	return false;
			}
		}
		else		return true;
		}
	}

	else if(dis == 5)	
	{	//static int d=0;d++;set_pos(20,20+d);cout<<dis<<"D"<<endl;
		if((tank_1.get_dir()+2)%2 == 0)
		{
		if(tank_1.get_dir() > 0)	
		{
			x_1 = tank_2.get_x();	x_2 = tank_1.get_x();
			y_1 = tank_2.get_y();	y_2 = tank_1.get_y();
		}
		else
		{
			x_1 = tank_1.get_x();	x_2 = tank_2.get_x();
			y_1 = tank_1.get_y();	y_2 = tank_2.get_y();
		}
		if(x_1 > x_2)
		{
			if(y_1 > y_2)
			{
			if(tank_2.get_dir() == -tank_1.get_dir() || tank_2.get_dir() == -2/tank_1.get_dir())	return true;
			else	return false;
			}
			else
			{
			if(tank_2.get_dir() == -tank_1.get_dir() || tank_2.get_dir() == -2/tank_1.get_dir())	return true;
			else	return false;
			}
		}
		else		return false;

		}
		else
		{
		if(tank_1.get_dir() < 0)	
		{
			x_1 = tank_1.get_x();	x_2 = tank_2.get_x();
			y_1 = tank_1.get_y();	y_2 = tank_2.get_y();
		}
		else
		{
			x_1 = tank_2.get_x();	x_2 = tank_1.get_x();
			y_1 = tank_2.get_y();	y_2 = tank_1.get_y();
		}
		if(y_1 > y_2)
		{
			if(x_1 > x_2)
			{
			if(tank_2.get_dir() == -tank_1.get_dir() || tank_2.get_dir() == -2/tank_1.get_dir())	return true;
			else	return false;
			}
			else
			{
			if(tank_2.get_dir() == -tank_1.get_dir() || tank_2.get_dir() == 2/tank_1.get_dir())	return true;
			else	return false;
			}
		}
		else		return false;
		}
	}

	else		return false;
}

bool Object::is_failure()
{
	if(life != 0)	return false;
	else			return true;
}

void Tank::emission_missile()
{
		Missile p;
		if((dir+2)%2 == 0)
			p.set_info(x+2*dir, y, dir);
		else if((dir+2)%2 == 1)
			p.set_info(x, y+2*dir, dir);
		missile_list.push_back(p);
		if(p.get_x()==0 || p.get_x()==58 || p.get_y()==0 || p.get_y()==23)	;
		else			p.paint("■");
		Sleep(100);
}

void Tank::missile_move()
{
	list<Missile>::iterator it = NULL;
	if(missile_list.size() != 0)			//这里一定要判空
	for(it=missile_list.begin(); it!=missile_list.end(); it++)
	{
	if(!it -> move())
		it = missile_list.erase(it);		//删除此步后当前迭代器会“失效”
	}
}

void Tank_War::check_missile(string name)
{
	if(name == "lead")
		lead.check_missile(*this, "lead");
	else
	{
		list<Tank>::iterator it = NULL;
		for(it = enemy_list.begin(); it != enemy_list.end(); it++)
		it -> check_missile(*this, "enemy");
	}
}

void Tank::check_missile(Tank_War &game, string name)
{
	list<Missile>::iterator it_1 = NULL;
	list<Tank>::iterator it_2 = NULL;
	if(name == "lead")
	{
		if(missile_list.size() != 0)
		for(it_1=missile_list.begin(); it_1!= missile_list.end(); it_1++)
		{
			for(it_2=game.get_enemy_list_begin(); it_2!=game.get_enemy_list_end(); it_2++)
				if(it_1 != missile_list.end())
				if(check_missile_strike(*it_1, *it_2))	
				{
					it_1 = missile_list.erase(it_1);
					if(it_2 -> is_failure())
					{
					game.increase_grade();
					it_2 -> paint("  ");
					it_2 = game.remove_from_enemy_list(it_2);
					game.reduce_tot();
					}
				}	
		}
	}
	else
	{
			if(missile_list.size() != 0)
			{
				if(it_1 != missile_list.end())
				for(it_1=missile_list.begin(); it_1!= missile_list.end(); it_1++)
				if(check_missile_strike(*it_1, *(game.get_lead())))	
				{
					it_1 = missile_list.erase(it_1);
					if(game.get_lead() -> is_failure())		game.game_over();
					else 
					{
						game.get_lead() -> paint("  ");
						game.get_lead() -> set_location(28, 10);
						game.get_lead() -> paint("■");
					}
				}
				if(it_1 != missile_list.end())
				for(it_1=missile_list.begin(); it_1!= missile_list.end(); it_1++)
				{
				for(it_2=game.get_enemy_list_begin(); it_2!=game.get_enemy_list_end(); it_2++)
				if(check_missile_strike(*it_1, *it_2))	
				{
					it_1 = missile_list.erase(it_1);
					it_2 -> increase_blood();
				}
				}
			}
	}
}

bool Tank::check_missile_strike(Missile& missile, Tank& tank)
{
	int dis = 0;
	if((dis = distance_squre(missile.get_x(), missile.get_y(), tank.get_x(), tank.get_y())) <= 2)
	{
		if(dis == 2)
		{
		}
		else
		{
			missile.reduce_blood();
			tank.reduce_blood();
			missile.paint("  ");
			return true;
		}
	}
	return false;
}

void Tank_War::enemy_move()
{
	int n = 0;
	srand((unsigned)time(NULL));
	list<Tank>::iterator it = NULL;
	if(enemy_list.size() != 0)
	{
		for(it=enemy_list.begin(); it != enemy_list.end(); it++)
		{
			it -> missile_move();
			n = rand()%3;
			if(n == 0)
			if(can_move(*it, "enemy"))
			{
				n = get_random_direction();
				it -> set_dir(n);
				it->move(*this, "enemy");
			}
			n = rand()%8;
			if(n == 0)	it -> emission_missile();
		}
	}
}

int Tank::distance_squre(int x_1, int y_1, int x_2, int y_2)
{
	return (x_2 - x_1) * (x_2 - x_1) + (y_2 - y_1) * (y_2 - y_1);
}

int Tank::distance_squre(Tank& tank_2)
{
	return distance_squre(x/2, y, tank_2.get_x()/2, tank_2.get_y());
}

int Tank_War::get_random_direction()
{
	int n = 0;
	srand((unsigned)time(NULL));
	if((n = rand()%4) < 2)		n -= 2;
	else		n -= 1;
	return n;
}

 

 

程序截图

首页

6e5ec33a8cee48ec9a8b3815a83072c7.png

 

 

程序执行界面

e0bd744179ac47c89c6b96f0c347b0ba.png

 

 

 

 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/577635.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

基于FastGPT搭建知识库问答系统

什么是 FastGPT &#xff1f; FastGPT 是一个基于 LLM 大语言模型的知识库问答系统&#xff0c;提供开箱即用的数据处理、模型调用等能力。同时可以通过 Flow 可视化进行工作流编排&#xff0c;从而实现复杂的问答场景&#xff01; FastGPT 允许用户构建本地知识库&#xff0c;…

C# APS.NET CORE 6.0 WebApi在IIS部署报错

今天尝试着把基于 APS.NET CORE6.0开发的webAPI程序部署到IIS中&#xff0c;当打开网站地址时报错&#xff0c;无法打开&#xff0c;于是查找资料最终进行了解决。 打开 IIS →模块 查看列表中是否存在 AspNetCoreModuleV2&#xff0c;如下&#xff1a; 对应的应用池需要选择“…

node.js egg.js

Egg 是 Node.js 社区广泛使用的框架&#xff0c;简洁且扩展性强&#xff0c;按照固定约定进行开发&#xff0c;低协作成本。 在Egg.js框架中&#xff0c;ctx 是一个非常核心且常用的对象&#xff0c;全称为 Context&#xff0c;它代表了当前 HTTP 请求的上下文。ctx 对象封装了…

施耐德 Unity Pro 编程软件导入导出变量

适用范围 施耐德中高端PLC&#xff0c;使用的编程软件为 UnityPro &#xff08;最新版更名为 Ecostructure Control Expert&#xff09; 中端 PLC&#xff1a;Premium&#xff0c;M340高端 PLC&#xff1a;Quantum&#xff0c;M580 导出/导入变量 导出变量可导出【变量和 FB…

JavaScript进阶(十五):JS 垃圾回收机制_vue gc

内存&#xff1a;由可读写单元组成&#xff0c;表示一片可操作空间&#xff1b;管理&#xff1a;人为的去操作一片空间的申请、使用和释放&#xff1b;内存管理&#xff1a;开发者主动申请空间、使用空间、释放空间&#xff1b;管理流程&#xff1a;申请-使用-释放&#xff1b;…

社交巨头与去中心化:解析Facebook在区块链的角色

在数字化时代&#xff0c;社交媒体已经成为人们日常生活中不可或缺的一部分。作为全球最大的社交媒体平台&#xff0c;Facebook 在社交领域的影响力无可置疑。然而&#xff0c;随着区块链技术的崛起&#xff0c;Facebook 也开始探索如何将这一技术应用于其平台&#xff0c;以适…

基于LSTM算法实现交通流量预测(Pytorch版)

算法介绍 LSTM&#xff08;Long Short-Term Memory&#xff09;算法是一种特殊设计的循环神经网络&#xff08;RNN, Recurrent Neural Network&#xff09;&#xff0c;专为有效地处理和建模序列数据中的长期依赖关系而开发。由于传统RNN在处理长序列时容易遇到梯度消失和梯度…

ElasticSearch语句中must,must_not,should 组合关系

前言&#xff1a; 在实际应用中&#xff0c;发现当bool中同时使用must和should 没有达到想要的想过&#xff0c;而是只展示了must中的命中数据&#xff0c;所以打算探究一下bool中 三种逻辑关系的组合。 上述查询语句只展示了must的结果&#xff0c;没有should中的结果&#…

本地Windows主机,使用pycharm通过wsl的ubuntu来创建django项目

Windows主机在pycharm中通过wsl的ubuntu来创建django项目 需求&#xff1a;在windows主机中创建python项目再转接到linux服务器中运行&#xff0c;有点麻烦。【特别是存放日志文件或其他文件路径时需要修改为linux中的路径】 1&#xff1a;我的是windows主机 2&#xff1a;有…

基于java+springboot+vue实现的个人博客系统(文末源码+Lw)200

摘 要 随着国内市场经济这几十年来的蓬勃发展&#xff0c;突然遇到了从国外传入国内的互联网技术&#xff0c;互联网产业从开始的群众不信任&#xff0c;到现在的离不开&#xff0c;中间经历了很多挫折。本次开发的个人博客系统&#xff0c;有管理员&#xff0c;用户&#xf…

神经网络参数初始化

&#x1f4bd;参数初始化是神经网络训练过程中的一个重要步骤。在构建神经网络时&#xff0c;我们需要为权重和偏置等参数赋予初始值。对于偏置&#xff0c;通常可以将其初始化为0或者较小的随机数。然而&#xff0c;对于权重w的初始化&#xff0c;我们通常会采用更加复杂的方法…

【论文笔记 | 异步联邦】PORT:How Asynchronous can Federated Learning Be?

1. 论文信息 How Asynchronous can Federated Learning Be?2022 IEEE/ACM 30th International Symposium on Quality of Service (IWQoS). IEEE, 2022&#xff0c;不属于ccf认定 2. introduction 2.1. 背景&#xff1a; 现有的异步FL文献中设计的启发式方法都只反映设计空…

《2024年绿色发展报告》:算力与电力矛盾愈加突出!

2024年4月22日&#xff0c;第55个世界地球日&#xff0c;超聚变发布《2024年绿色发展报告》&#xff0c;向社会展示超聚变面对宏观形势变化、产业趋势变化&#xff0c;推进绿色发展、科技向绿的探索与实践成果。 2023年&#xff0c;算力产业发生了深刻变化。大模型带来AI算力需…

小程序中如何快速给分类添加商品

​快速在分类下面上传商品&#xff0c;并且能够设置商品顺序&#xff0c;关系到运营效率的高低。下面就具体介绍如何快速在某个分类下面设置商品。 一、在商品管理处&#xff0c;查询某个分类下面的商品。 进入小程序管理员后台->商品管理&#xff0c;点击分类输入框&…

从零开始利用MATLAB进行FPGA设计(五)详解双口RAM

创作于谱仪算法设计过程中的数字能谱生成模块设计。 往期回顾&#xff1a; 从零开始利用MATLAB进行FPGA设计&#xff08;四&#xff09;生成优化HDL代码 从零开始利用MATLAB进行FPGA设计&#xff08;三&#xff09;将Simulink模型转化为定点数据类型 目录 1.关于双口RAM …

大模型咨询培训老师叶梓:利用知识图谱和Llama-Index增强大模型应用

大模型&#xff08;LLMs&#xff09;在自然语言处理领域取得了显著成就&#xff0c;但它们有时会产生不准确或不一致的信息&#xff0c;这种现象被称为“幻觉”。为了提高LLMs的准确性和可靠性&#xff0c;可以借助外部知识源&#xff0c;如知识图谱。那么我们如何通过Llama-In…

Web前端开发之CSS_1

CSS选择器字体属性背景属性文本属性表格属性 1. CSS 1.1 CSS简介 CSS&#xff08;Cascading Style Sheets&#xff09;层叠样式表&#xff0c;又叫级联样式表&#xff0c;简称样式表。CSS文件后缀名为 .css 。CSS用于HTML文档中元素样式的定义。使用CSS可以让网页具有美观一致…

算法 || 二分查找

目录 二分查找 在排序数组中查找元素的第一个和最后一个位置 搜索插入位置 一个数组经过划分后具有二段性的都可以用二分查找 二分查找 704. 二分查找 - 力扣&#xff08;LeetCode&#xff09; ​ 暴力解法&#xff1a;直接遍历数组&#xff0c;找到 target 便返回下标&am…

【blog项目】layui与jquery冲突导致鼠标悬停事件失效、如何调用layui.use()作用域里的方法

blog项目前台展示——查询数据库中的文章类型并展示时出现的bug 1 正常演示 2 用jquery查询数据库并添加到页面后 3 相关代码 <script src"/static/jquery-2.1.4.js"></script> <script src"/static/layui/layui.js"></script> …

排序算法-计数排序

一、计数排序 这种排序算法 是利用数组下标来确定元素的正确位置的。 如果数组中有20个随机整数&#xff0c;取值范围为0~10&#xff0c;要求用最快的速度把这20个整数从小到大进行排序。 很大的情况下&#xff0c;它的性能甚至快过那些时间复杂度为O(nlogn&#xff09;的排序。…
最新文章