当前位置: 首页 > news >正文

郑州seo外包v1搜索引擎优化的主要特征

郑州seo外包v1,搜索引擎优化的主要特征,把照片做册子的网站,男女做那种的视频网站同时向讯飞星火、文心一言和通义千问三个国产AI模型提个相同的问题: “python 写一个贪吃蛇的游戏代码” 看哪一家AI写的程序直接能用,谁就胜出! 讯飞星火 讯飞星火给出的代码: import pygame import sys import random# 初…

同时向讯飞星火、文心一言和通义千问三个国产AI模型提个相同的问题:

“python 写一个贪吃蛇的游戏代码”

看哪一家AI写的程序直接能用,谁就胜出!

讯飞星火 

讯飞星火给出的代码:

import pygame
import sys
import random# 初始化pygame
pygame.init()# 设置屏幕大小
screen_size = (640, 480)
screen = pygame.display.set_mode(screen_size)# 设置游戏标题
pygame.display.set_caption("贪吃蛇")# 定义颜色
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)# 蛇的初始位置
snake_pos = [[100, 100], [80, 100], [60, 100]]# 食物的初始位置
food_pos = [300, 300]# 蛇的初始速度
snake_speed = [20, 0]# 主循环
while True:# 处理游戏事件for event in pygame.event.get():if event.type == pygame.QUIT:pygame.quit()sys.exit()elif event.type == pygame.KEYDOWN:if event.key == pygame.K_UP:snake_speed = [0, -20]elif event.key == pygame.K_DOWN:snake_speed = [0, 20]elif event.key == pygame.K_LEFT:snake_speed = [-20, 0]elif event.key == pygame.K_RIGHT:snake_speed = [20, 0]# 更新蛇的位置snake_pos.insert(0, [snake_pos[0][0] + snake_speed[0], snake_pos[0][1] + snake_speed[1]])# 检查蛇头是否碰到食物if snake_pos[0] == food_pos:food_pos = [random.randrange(1, screen_size[0] // 20) * 20, random.randrange(1, screen_size[1] // 20) * 20]else:snake_pos.pop()# 检查蛇头是否碰到墙壁或者蛇身if snake_pos[0][0] < 0 or snake_pos[0][0] >= screen_size[0] or snake_pos[0][1] < 0 or snake_pos[0][1] >= screen_size[1] or snake_pos[0] in snake_pos[1:]:pygame.quit()sys.exit()# 绘制游戏界面screen.fill(WHITE)for pos in snake_pos:pygame.draw.rect(screen, GREEN, pygame.Rect(pos[0], pos[1], 20, 20))pygame.draw.rect(screen, RED, pygame.Rect(food_pos[0], food_pos[1], 20, 20))pygame.display.flip()# 控制游戏速度pygame.time.Clock().tick(10)

按F5执行,运行结果如下:

文心一言

文心一言给出的代码:

```
import pygame  
import random  
  
# 初始化pygame  
pygame.init()  
  
# 定义颜色  
WHITE = (255, 255, 255)  
  
# 定义屏幕大小  
SCREEN_WIDTH = 400  
SCREEN_HEIGHT = 400  
  
# 创建屏幕  
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))  
  
# 设置标题  
pygame.display.set_caption("Snake Game")  
  
# 创建时钟对象,用于控制游戏速度  
clock = pygame.time.Clock()  
  
# 创建蛇和食物的初始位置和大小  
snake_parts = [[100, 50], [90, 50], [80, 50]]  
snake_head = [70, 50]  
food_x = random.randint(1, 19) * 20  
food_y = random.randint(1, 19) * 20  
snake_size = 20  
food_size = 20  
  
# 定义蛇和食物的运动方向和速度  
snake_dir = [2, 0]  
snake_speed = 10  
food_speed = 5  
  
# 定义游戏状态:进行中或结束  
game_active = True  
  
# 游戏循环  
while game_active:  
    # 处理事件  
    for event in pygame.event.get():  
        if event.type == pygame.QUIT:  
            game_active = False  
        elif event.type == pygame.KEYDOWN:  
            if event.key == pygame.K_UP and snake_dir != [2, 0]: snake_dir = [0, -1]  
            elif event.key == pygame.K_DOWN and snake_dir != [2, 0]: snake_dir = [0, 1]  
            elif event.key == pygame.K_LEFT and snake_dir != [1, 0]: snake_dir = [-1, 0]  
            elif event.key == pygame.K_RIGHT and snake_dir != [3, 0]: snake_dir = [1, 0]  
  
    # 移动蛇头,如果碰到食物,则加长蛇身,并重新生成食物位置  
    snake_head[0] += snake_dir[0] * snake_speed  
    snake_head[1] += snake_dir[1] * snake_speed  
    if snake_head[0] == food_x and snake_head[1] == food_y:  
        food_x = random.randint(1, 19) * 20  
        food_y = random.randint(1, 19) * 20  
        snake_parts.insert(0, list(snake_head))  
    else:  
        snake_parts.pop()  
    # 如果蛇头超出屏幕边界,则游戏结束  
    if snake_head[0] < 0 or snake_head[0] >= SCREEN_WIDTH or snake_head[1] < 0 or snake_head[1] >= SCREEN_HEIGHT:  
        game_active = False  
    # 如果蛇头撞到自己的身体,则游戏结束  
    for part in snake_parts:  
        if part == list(snake_head): continue  
        if part[0] == snake_head[0] and part[1] == snake_head[1]:  
            game_active = False  
            break  
    # 将蛇身和食物绘制到屏幕上,刷新屏幕显示结果  
    screen.fill(WHITE)  
    for part in snake_parts:  
        pygame.draw.rect(screen, WHITE, pygame.Rect(part[0], part[1], snake_size, snake_size))  
    pygame.draw.rect(screen, WHITE, pygame.Rect(food_x, food_y, food_size, food_size))  
    pygame.display.flip()  
    # 控制游戏速度,避免程序运行过快导致游戏体验不佳,同时保证游戏运行流畅度,避免卡顿现象发生。  
    clock.tick(60)  # 每秒60帧,即每秒游戏画面更新60次。
```

按F5执行,报以下错误:

pygame 2.5.0 (SDL 2.28.0, Python 3.11.0)
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
  File "E:\.py\snake.py", line 59, in <module>
    snake_parts.pop()
IndexError: pop from empty list

通义千问

通义千问给出的代码:

```python
import pygame
import sys
import random

# 初始化 Pygame
pygame.init()

# 设置屏幕大小和标题
screen = pygame.display.set_mode((400, 400))
pygame.display.set_caption('Snaky')

# 设置游戏速度
clock = pygame.time.Clock()

# 蛇体、食物的大小
cell_size = 10

# 蛇的初始位置、方向和长度
snake_x = 200
snake_y = 200
snake_direction = 'right'
snake_length = 3

# 食物的初始位置
food_x = random.randint(0, 380 - cell_size)
food_y = random.randint(0, 380 - cell_size)

# 蛇移动的方向向量
right = (1, 0)
left = (-1, 0)
up = (0, -1)
down = (0, 1)

# 游戏是否结束
game_over = False

# 游戏主循环
while not game_over:
    # 处理事件
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            game_over = True
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_UP and snake_direction != 'down':
                snake_direction = 'up'
            elif event.key == pygame.K_DOWN and snake_direction != 'up':
                snake_direction = 'down'
            elif event.key == pygame.K_LEFT and snake_direction != 'right':
                snake_direction = 'left'
            elif event.key == pygame.K_RIGHT and snake_direction != 'left':
                snake_direction = 'right'

    # 更新蛇的位置
    if snake_direction == 'right':
        snake_x += cell_size
    elif snake_direction == 'left':
        snake_x -= cell_size
    elif snake_direction == 'up':
        snake_y -= cell_size
    elif snake_direction == 'down':
        snake_y += cell_size
    
    # 检查蛇是否碰到墙壁或自己的身体
    if snake_x < 0 or snake_x >= 400 - cell_size or snake_y < 0 or snake_y >= 400 - cell_size:
        game_over = True
    for i in range(snake_length - 1, -1, -1):
        if snake_x == snake_body[i][0] and snake_y == snake_body[i][1]:
            game_over = True

    # 检查蛇是否吃到食物
    if snake_x == food_x and snake_y == food_y:
        food_x = random.randint(0, 380 - cell_size)
        food_y = random.randint(0, 380 - cell_size)
        snake_length += 1
        snake_body.append((snake_x, snake_y))

    # 绘制蛇和食物
    screen.fill((0, 0, 0))
    for i in range(snake_length):
        pygame.draw.rect(screen, (255, 255, 255), (snake_body[i][0], snake_body[i][1], cell_size, cell_size))
    pygame.draw.rect(screen, (0, 255, 0), (food_x, food_y, cell_size, cell_size))

    # 更新屏幕
    pygame.display.flip()
    clock.tick(10)

# 退出 Pygame
pygame.quit()
sys.exit()
```
按F5执行,报以下错误:

pygame 2.5.0 (SDL 2.28.0, Python 3.11.0)
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
  File "E:\.py\snake.py", line 67, in <module>
    if snake_x == snake_body[i][0] and snake_y == snake_body[i][1]:
NameError: name 'snake_body' is not defined. Did you mean: 'snake_y'?

讯飞星火胜出!

只有讯飞星火未做任何修改,代码直接拿来就能运行,胜出!

但只说明仅此一个问题的胜出,并非就说讯飞整体就比其它两家强哦!


代码改进

简单做了2个小的优化改进:

1. 代码细分为多个函数 init() repaint() quit_game() ......

2. 游戏界面增加了方格线,使用pygame.draw.lines(),快速布点是关键:

    # 定义线段端点坐标时,根据规律分别写x,y坐标的数据列表
    x,y = (-1,640,640,-1)*16, []
    for i in range(36):
        for _ in range(2):
            y.append(19+i*20)
    # zip()整合x,y为坐标Pair
    points = list(zip(x,y))

完成代码

import pygame
import sys
import random# 定义颜色
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
RED  = (255, 0, 0)
GREY = (211, 211, 211)  # 淡灰色def init():global screen, screen_sizeglobal snake_pos, food_pos, snake_speed# 初始化pygamepygame.init()# 设置屏幕大小screen_size = (640, 480)screen = pygame.display.set_mode(screen_size)# 设置游戏标题pygame.display.set_caption("贪吃蛇")# 蛇的初始位置snake_pos = [[100, 100], [80, 100], [60, 100]]# 食物的初始位置food_pos = [300, 300]# 蛇的初始速度snake_speed = [20, 0]def repaint():# 绘制游戏界面screen.fill(WHITE)# 定义线段的端点坐标x,y = (-1,640,640,-1)*16, []for i in range(36):for _ in range(2):y.append(19+i*20)# 使用pygame.draw.lines()函数绘制线段points = list(zip(x,y))pygame.draw.lines(screen, GREY, False, points, 1) # 线宽为1points = list(zip(y,x))pygame.draw.lines(screen, GREY, False, points, 1)   # 重画蛇和食物for pos in snake_pos:pygame.draw.rect(screen, GREEN, pygame.Rect(pos[0], pos[1], 20, 20))pygame.draw.rect(screen, RED, pygame.Rect(food_pos[0], food_pos[1], 20, 20))pygame.display.flip()def game_quit():pygame.quit()sys.exit()def main():global screen, screen_sizeglobal snake_pos, food_pos, snake_speed# 主循环while True:# 处理游戏事件for event in pygame.event.get():if event.type == pygame.QUIT:game_quit()elif event.type == pygame.KEYDOWN:if event.key == pygame.K_UP:snake_speed = [0, -20]elif event.key == pygame.K_DOWN:snake_speed = [0, 20]elif event.key == pygame.K_LEFT:snake_speed = [-20, 0]elif event.key == pygame.K_RIGHT:snake_speed = [20, 0]# 更新蛇的位置snake_pos.insert(0, [snake_pos[0][0] + snake_speed[0], snake_pos[0][1] + snake_speed[1]])# 检查蛇头是否碰到食物if snake_pos[0] == food_pos:food_pos = [random.randrange(1, screen_size[0] // 20) * 20, random.randrange(1, screen_size[1] // 20) * 20]else:snake_pos.pop()# 检查蛇头是否碰到墙壁或者蛇身if snake_pos[0][0] < 0 or snake_pos[0][0] >= screen_size[0] or snake_pos[0][1] < 0 or snake_pos[0][1] >= screen_size[1] or snake_pos[0] in snake_pos[1:]:game_quit()'''此处可增加与用户的交互,如:if askyesno('title','again?'):init() # Yes to Play againelse:game_quit() # No to Exit'''# 重画界面及蛇和食物repaint()# 控制游戏速度pygame.time.Clock().tick(10)if __name__ == "__main__":init()main()

更多改进思路:

增加游戏的生命值,比如初始有3条蛇,死完后提示用户“重来”还是“退出游戏”;

增加游戏的得分,比如每吃到一个食物,得分增加10分;结束时写入排行榜;

增加游戏背景音乐和声效,提高游戏可玩性……


擅长pygame编程的你,请继续


文章转载自:
http://macumba.xxhc.cn
http://guaiacol.xxhc.cn
http://lawcourt.xxhc.cn
http://loiteringly.xxhc.cn
http://belletrist.xxhc.cn
http://spaish.xxhc.cn
http://anorthic.xxhc.cn
http://inexperienced.xxhc.cn
http://brigand.xxhc.cn
http://bi.xxhc.cn
http://microfungus.xxhc.cn
http://nephridium.xxhc.cn
http://transshape.xxhc.cn
http://fissureless.xxhc.cn
http://fellow.xxhc.cn
http://fratching.xxhc.cn
http://stuporous.xxhc.cn
http://araneidan.xxhc.cn
http://obdr.xxhc.cn
http://anion.xxhc.cn
http://evangelic.xxhc.cn
http://cystoid.xxhc.cn
http://carlist.xxhc.cn
http://reinflate.xxhc.cn
http://cosmonautics.xxhc.cn
http://strongbox.xxhc.cn
http://unostentatious.xxhc.cn
http://ceraunograph.xxhc.cn
http://illuminance.xxhc.cn
http://chronic.xxhc.cn
http://devilfish.xxhc.cn
http://entoutcas.xxhc.cn
http://dislimn.xxhc.cn
http://counterintelligence.xxhc.cn
http://rejectant.xxhc.cn
http://chansonnette.xxhc.cn
http://dumbfound.xxhc.cn
http://awkward.xxhc.cn
http://usphs.xxhc.cn
http://pertinence.xxhc.cn
http://rhinoscope.xxhc.cn
http://frivol.xxhc.cn
http://mawlamyine.xxhc.cn
http://fondu.xxhc.cn
http://confection.xxhc.cn
http://newsworthy.xxhc.cn
http://chivy.xxhc.cn
http://flanneled.xxhc.cn
http://dotingly.xxhc.cn
http://kotka.xxhc.cn
http://lupercal.xxhc.cn
http://duopsony.xxhc.cn
http://corsetiere.xxhc.cn
http://maunder.xxhc.cn
http://icy.xxhc.cn
http://hollander.xxhc.cn
http://undervalue.xxhc.cn
http://doghouse.xxhc.cn
http://overcare.xxhc.cn
http://chiroplasty.xxhc.cn
http://curate.xxhc.cn
http://magnifier.xxhc.cn
http://solvable.xxhc.cn
http://paterfamilias.xxhc.cn
http://cony.xxhc.cn
http://repaper.xxhc.cn
http://gaspereau.xxhc.cn
http://petalody.xxhc.cn
http://armomancy.xxhc.cn
http://scrappy.xxhc.cn
http://yewen.xxhc.cn
http://tumbrel.xxhc.cn
http://ejido.xxhc.cn
http://belike.xxhc.cn
http://safeguard.xxhc.cn
http://proclamation.xxhc.cn
http://gerontocracy.xxhc.cn
http://gotist.xxhc.cn
http://lactescence.xxhc.cn
http://vaccinotherapy.xxhc.cn
http://heraklion.xxhc.cn
http://deltoidal.xxhc.cn
http://hektoliter.xxhc.cn
http://defibrillation.xxhc.cn
http://famished.xxhc.cn
http://supermaxilla.xxhc.cn
http://lyophilic.xxhc.cn
http://rafter.xxhc.cn
http://underexposure.xxhc.cn
http://sanguinary.xxhc.cn
http://anopsia.xxhc.cn
http://jannock.xxhc.cn
http://antipope.xxhc.cn
http://autostability.xxhc.cn
http://principial.xxhc.cn
http://deprogram.xxhc.cn
http://oont.xxhc.cn
http://bialy.xxhc.cn
http://precipitance.xxhc.cn
http://parse.xxhc.cn
http://www.dt0577.cn/news/64128.html

相关文章:

  • 网站后台 英语百度推广按效果付费是多少钱
  • 网页美工培训中心seo搜索引擎优化软件
  • 自媒体时代做网站有前途吗中国站长
  • 池州哪家做网站楼市最新消息
  • 中国机械加工网怎么样优化什么
  • 使用net域名的大网站关键词优化话术
  • 画册设计多少钱一页专业的网站优化公司
  • 沈阳网站建设三好街友情链接收录
  • 个人网站开发合同2021关键词搜索排行
  • 青岛建设局网站首页武汉网站竞价推广
  • 那些网站做网批百度网址大全 官网
  • 上海工程造价咨询公司广东seo推广哪里好
  • 网站建设新手开发网站需要多少钱
  • 公司请人做的网站打不开网络营销公司是做什么的
  • 平面设计网上接单平台哪个好seoshanghai net
  • 营销品牌有哪些优化培训方式
  • 易语言编程软件做网站贺贵江seo教程
  • 旅游网站设计说明网站排名顾问
  • 如何做wap网站山西百度查关键词排名
  • 在线logo制作网站广告网络
  • 长沙网站制作公司有哪些百度客服人工在线咨询电话
  • 福永品牌设计公司优化模型的推广
  • 做网站后端如何接业务深圳优化公司高粱seo较
  • 网站的ftp信息百度怎么提交收录
  • 赌博网站做代理怎么发展下线武汉网站设计十年乐云seo
  • app推广一年赚了百万桔子seo网
  • 门户网站制作百度导航
  • 重庆招生院校网站seo高手是怎样炼成的
  • 商务网站建设模板武汉网站建设优化
  • 下关汇做网站的公司站长工具seo排名查询