奇怪的小游戏

看了一眼自己的代码,我…哭了…

#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <cstdio>
#include <cctype>
#include <string>
#include <vector>
#include <cstring>
#include <climits>
#include <cstdlib>
#include <sstream>
#include <utility>
#include <iostream>
#include <algorithm>

#include <windows.h>
#include <conio.h>
#include <time.h>

using namespace std;

int n, m;

struct player {
   
	int x, y;
	int weight, size;
}a[10];

struct food {
   
	int x, y;
	int weight;
}b[100];

player grow(player x) {
   
	x.size = sqrt(sqrt(x.weight)) - 1; 
	return x;
}

food reset(food x) {
   
//	while(1);
	srand((unsigned)time(0));
	x.x = rand() % 30;
	x.y = rand() % 30;
	x.weight = rand() % 2 + 1;
	return x;
}

bool eat(player x, player y) {
   
	return x.size >= y.size && (x.size - y.size >= abs(x.x - y.x) + abs(x.y - y.y));
}

bool eatt(player x, food y) {
   
	return x.size >= abs(x.x - y.x) + abs(x.y - y.y);
}

player AI(player x) {
   
	if (! x.weight) return x;
	int idx;
	int minx = 25;
	for (int i = 0; i < 30; i ++) {
   
		if (abs(b[i].x - x.x) + abs(b[i].y - x.y) < minx) {
   
			minx = abs(b[i].x - x.x) + abs(b[i].y - x.y);
			idx = i;
		}
	}
	if (eatt(x, b[idx])) {
   
		x.weight += b[idx].weight;
		x = grow(x)
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值