原文地址鏈接
https://mp.weixin.qq.com/s/QEId53_7tpt3BnGar6sxiA
?https://chat.deepseek.com/coder
注冊賬戶后登錄即可免費(fèi)使用。
今天我們嘗試寫一個貪食蛇的Python代碼。
提示詞:
寫一個貪食蛇的Python程序
將生成的代碼復(fù)制到VS Code中報錯。
將錯誤信息直接復(fù)制到DeepSeek Coder讓其識別并進(jìn)行修改。
import pygame
import random
# 初始化pygame
pygame.init()
# 設(shè)置屏幕大小
screen_width = 800
screen_height = 600
screen = pygame.display.set_mode((screen_width, screen_height))
# 設(shè)置顏色
white = (255, 255, 255)
yellow = (255, 255, 102)
black = (0, 0, 0)
red = (213, 50, 80)
green = (0, 255, 0)
blue = (50, 153, 213)
# 設(shè)置蛇的初始位置和大小
snake_block = 10
snake_speed = 15
# 設(shè)置字體
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
game_loop()
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])
游戲重新開始后,貪食蛇和食物的位置隨機(jī)發(fā)生變化。
DeepSeek Coder 給我的體驗(yàn)是相當(dāng)絲滑的,不懂代碼的話進(jìn)行直接語言交互和反饋就能到達(dá)最終的效果。
DeepSeek Coder是私募巨頭幻方量化發(fā)布的第一代大模型,它是一款基于深度學(xué)習(xí)的編程語言處理模型,能夠進(jìn)行代碼生成、數(shù)學(xué)推理等多種任務(wù)。該模型已經(jīng)開源,并且包含了不同規(guī)模的版本,如1B、7B、33B等,以及Base模型和指令調(diào)優(yōu)模型。
在國際權(quán)威數(shù)據(jù)集HumanEval上的編程多語言測試中,DeepSeek Coder的表現(xiàn)領(lǐng)先于現(xiàn)有的開源模型。特別是在代碼生成任務(wù)上,DeepSeek Coder分別在HumanEval、MBPP和DS-1000數(shù)據(jù)集上優(yōu)于此前最好的開源大模型CodeLlama。此外,DeepSeek Coder還展示了出色的數(shù)學(xué)和推理能力。
該模型的發(fā)布標(biāo)志著幻方量化在探索人工通用智能(AGI)本質(zhì)的道路上取得了階段性成果。
該模型的發(fā)布標(biāo)志著幻方量化在探索人工通用智能(AGI)本質(zhì)的道路上取得了階段性成果。
。