|
原文地址鏈接 https://mp.weixin.qq.com/s/QEId53_7tpt3BnGar6sxiA
不懂代碼的小白通過Deepseek寫一個游戲原創(chuàng) Road Hero 路上俠客 2024-05-12 19:30 上海 聽全文 Deepseek家族最后一個成員DeepSeek Coder 官方網(wǎng)頁端: ?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()
游戲重新開始后,貪食蛇和食物的位置隨機發(fā)生變化。 ![]()
DeepSeek Coder 給我的體驗是相當絲滑的,不懂代碼的話進行直接語言交互和反饋就能到達最終的效果。 DeepSeek Coder是私募巨頭幻方量化發(fā)布的第一代大模型,它是一款基于深度學習的編程語言處理模型,能夠進行代碼生成、數(shù)學推理等多種任務。該模型已經(jīng)開源,并且包含了不同規(guī)模的版本,如1B、7B、33B等,以及Base模型和指令調(diào)優(yōu)模型。 在國際權(quán)威數(shù)據(jù)集HumanEval上的編程多語言測試中,DeepSeek Coder的表現(xiàn)領先于現(xiàn)有的開源模型。特別是在代碼生成任務上,DeepSeek Coder分別在HumanEval、MBPP和DS-1000數(shù)據(jù)集上優(yōu)于此前最好的開源大模型CodeLlama。此外,DeepSeek Coder還展示了出色的數(shù)學和推理能力。 該模型的發(fā)布標志著幻方量化在探索人工通用智能(AGI)本質(zhì)的道路上取得了階段性成果。 該模型的發(fā)布標志著幻方量化在探索人工通用智能(AGI)本質(zhì)的道路上取得了階段性成果。 。
|