分享

不懂代码的小白通过Deepseek写一个游戏

 风声之家 2024-05-12 发布于江苏

原文地址链接

https://mp.weixin.qq.com/s/QEId53_7tpt3BnGar6sxiA 

不懂代码的小白通过Deepseek写一个游戏

原创 Road Hero 路上侠客 2024-05-12 19:30  听全文

Deepseek家族最后一个成员DeepSeek Coder

官方网页端:

​https://chat./coder 

注册账户后登录即可免费使用。

今天我们尝试写一个贪食蛇的Python代码。

提示词:

写一个贪食蛇的Python程序

将生成的代码复制到VS Code中报错。

将错误信息直接复制到DeepSeek Coder让其识别并进行修改。

import pygameimport random
# 初始化pygamepygame.init()
# 设置屏幕大小screen_width = 800screen_height = 600screen = pygame.display.set_mode((screen_width, screen_height))
# 设置颜色white = (255, 255, 255)yellow = (255, 255, 102)black = (0, 0, 0)red = (213, 50, 80)green = (0, 255, 0)blue = (50, 153, 213)
# 设置蛇的初始位置和大小snake_block = 10snake_speed = 15
# 设置字体font_style = pygame.font.SysFont(None, 30)

def message(msg, color): mesg = font_style.render(msg, True, color) screen.blit(mesg, [screen_width / 6, screen_height / 3])

def game_loop(): game_over = False game_close = False
x1 = screen_width / 2 y1 = screen_height / 2
x1_change = 0 y1_change = 0
snake_list = [] length_of_snake = 1
foodx = round(random.randrange(0, screen_width - snake_block) / 10.0) * 10.0 foody = round(random.randrange(0, screen_height - snake_block) / 10.0) * 10.0
while not game_over:
while not game_over:
while game_close: screen.fill(black) message("You Lost! Press Q-Quit or C-Play Again", red) pygame.display.update()
for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_q: game_over = True game_close = False if event.key == pygame.K_c: game_loop()
for event in pygame.event.get(): if event.type == pygame.QUIT: game_over = True if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: x1_change = -snake_block y1_change = 0 elif event.key == pygame.K_RIGHT: x1_change = snake_block y1_change = 0 elif event.key == pygame.K_UP: y1_change = -snake_block x1_change = 0 elif event.key == pygame.K_DOWN: x1_change = 0

if x1 >= screen_width or x1 < 0 or y1 >= screen_height or y1 < 0: game_close = True
x1 += x1_change y1 += y1_change screen.fill(blue) pygame.draw.rect(screen, green, [foodx, foody, snake_block, snake_block])

这次修正后游戏正常,最后的按键也没有问题了。




snake_head = [] snake_head.append(x1) snake_head.append(y1) snake_list.append(snake_head) if len(snake_list) > length_of_snake: del snake_list[0]
for x in snake_list[:-1]: if x == snake_head: game_close = True
our_snake(snake_block, snake_list) your_score(length_of_snake - 1)
pygame.display.update()
if x1 == foodx and y1 == foody: foodx = round(random.randrange(0, screen_width - snake_block) / 10.0) * 10.0 foody = round(random.randrange(0, screen_height - snake_block) / 10.0) * 10.0 length_of_snake += 1
pygame.time.Clock().tick(snake_speed)
pygame.quit() quit()

def our_snake(snake_block, snake_list): for x in snake_list: pygame.draw.rect(screen, black, [x[0], x[1], snake_block, snake_block])

def your_score(score): value = font_style.render("Your Score: " + str(score), True, yellow) screen.blit(value, [0, 0])

game_loop()

游戏重新开始后,贪食蛇和食物的位置随机发生变化。

DeepSeek Coder 给我的体验是相当丝滑的,不懂代码的话进行直接语言交互和反馈就能到达最终的效果。

DeepSeek Coder是私募巨头幻方量化发布的第一代大模型,它是一款基于深度学习的编程语言处理模型,能够进行代码生成、数学推理等多种任务。该模型已经开源,并且包含了不同规模的版本,如1B、7B、33B等,以及Base模型和指令调优模型。

在国际权威数据集HumanEval上的编程多语言测试中,DeepSeek Coder的表现领先于现有的开源模型。特别是在代码生成任务上,DeepSeek Coder分别在HumanEval、MBPP和DS-1000数据集上优于此前最好的开源大模型CodeLlama。此外,DeepSeek Coder还展示了出色的数学和推理能力。

该模型的发布标志着幻方量化在探索人工通用智能(AGI)本质的道路上取得了阶段性成果。

该模型的发布标志着幻方量化在探索人工通用智能(AGI)本质的道路上取得了阶段性成果。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约