支持pygame的python有哪些版本_一个贪吃蛇游戏,包括三个AI版本,采用python,pygame实现...

SnakySnaky是一个使用Python实现的蛇游戏系列,包括一个人工智能玩家版本和三个自动玩蛇的AI版本。AI策略分别基于汉密尔顿路径、BFS和结合最短及最长路径的优化策略。不同AI版本展示了不同的游戏填充和速度效果。项目需要安装pygame模块。
摘要由CSDN通过智能技术生成

Snaky

Snaky is a Snake game series including a basic one-player version and three versions of AI to play Snake automatically.

The project is implemented in Python.

If you like it, Please give it a star, Thanks!

Require

You should have pygame module installed.

Final Version Demo

snaky_ai_v3.gif

Usage

Basic function - One player

In this version, you can control the movement of the snake to eat the apple to grow.

git clone https://github.com/memoiry/Snaky

cd Snaky

python snaky.py

d9903d60e51c82247fdc4529b0956c48.gif

It was actually manually controlled by myself(hard to control while recording the gif....so it's poor..)

AI version 1 - Based on Hamiltonian path

A perfect strategy, ensuring filling the screen, but the speed is slow.

python snaky_ai_v1.py

3ac27b1c00d349b75f0395220ec5ed67.gif

AI version 2 - Based on BFS

A simple BFS strategy make the snake trapped in local optimal point and not considering future.

python snaky_ai_v2.py

25f482486f62b69aa3505a7495cc7b6e.gif

AI version 3 - Based on BFS(shortest path), forward checking and follow the tail(longest path).

In this AI version. The algorithm is constructed as follow.

To find snake S1's next moving direction D, the AI snake follows the steps below:

Compute the shortest path P1 from snake S1's head to the food. If P1 exists, go to step 2. Otherwise, go to step 4.

Move a virtual snake S2 (the same as S1) to eat the food along path P1.

Compute the longest path P2 from snake S2's head to its tail. If P2 exists, let D be the first direction in path P1. Otherwise, go to step 4.

Compute the longest path P3 from snake S1's head to its tail. If P3 exists, let D be the first direction in path P3. Otherwise, go to step 5.

Let D be the direction that makes the snake the farthest from the food.

python snaky_ai_v3.py

snaky_ai_v3.gif

Enjoy!

Reference

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值