1 Star 1 Fork 0

surkaa/AISnake2

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Tools.cpp 1.35 KB
一键复制 编辑 原始数据 按行查看 历史
wining Y 提交于 2022-03-21 16:12 . 新算法最高可达%99完成度!
#include"snake.h"
int ManHaadun_x(int a, int b) {
return a % pmapW - b % pmapW;
}
int ManHaadun_y(int a, int b) {
return a / pmapW - b / pmapW;
}
int TrunSnake_byPlayer(int dir) {
int result = dir;
if (_kbhit())
switch (_getch())
{
case 77:case'a':case'A':case'3':
if (dir != right)
result = left;
break;
case 72:case'w':case'W':case'1':
if (dir != down)
result = up;
break;
case 80:case's':case'S':case'2':
if (dir != up)
result = down;
break;
case 75:case'd':case'D':case'4':
if (dir != left)
result = right;
break;
default:
system("pause");
TrunSnake_byPlayer(result);
break;
}
return result;
}
void MoveSnake_Head(SnakeMap* map, int* tempdir, int* head) {
map[*head].dir = *tempdir;
*head += *tempdir;
map[*head].adr = SnakeBody;
}
void MoveSnake_Tail(SnakeMap* map, int* tail) {
int temp = *tail;
*tail += map[temp].dir;
map[temp].adr = none;
map[temp].dir = unkown;
}
int _condition(int head) {
int result =
8 * isSnakeBody(head + left) +
4 * isSnakeBody(head + up) +
2 * isSnakeBody(head + down) +
1 * isSnakeBody(head + right);
return result;
}
void SpeedSnake(bool op, SnakeRelevant* absnake) {
//为使分数达满时得到速度 speed = 1 计算得系数 SpeedRelationship 如下
if(!op)
absnake->speed = (initspeed * pow(2, -absnake->score * SpeedRelationship));
Sleep((DWORD)absnake->speed);
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/surkaa/AISnake2.git
git@gitee.com:surkaa/AISnake2.git
surkaa
AISnake2
AISnake2
master

搜索帮助