Deepseek最强大的就是它的深度思考,并且展现了它的思考过程。
五种可使用Deep seek的方式(应该不限于这五种,后续嵌入deepseek的应该更多,多了解一点因为官网容易崩~~):
1.deep seek官网
2.硅基流动siliconflow
3.秘塔(深度思考)
4.sider
5.chatbox
今天学了deepseek做几个小游戏,很有意思。官网和硅基流动都无法直接运行代码,sider和秘塔有“运行”按钮。对deepseek进行简单的提问“做一个消消乐小游戏”或“做一个贪吃蛇小游戏”,deepseek会展示深度思考的过程,然后给出代码。为了使得游戏设计更有意思(好上手玩),比如贪吃蛇游戏,要求“进一步改进代码,呈现UI界面,包含“开始”按钮”、“结束”按钮、“上下左右”按钮、以及能够统计分数”。
silicon flow中嵌入deepseek写消消乐小游戏(要求生成UI界面)
import pygame
import random# 游戏常量配置
WIDTH, HEIGHT = 400, 450
BLOCK_SIZE = 40
GAP = 2
ROWS = 8
COLS = 8
COLORS = [(255, 0, 0), # 红(0, 255, 0), # 绿(0, 0, 255), # 蓝(255, 255, 0), # 黄(255, 165, 0)] # 橙def create_board():"""创建初始游戏面板"""return [[random.randint(0, len(COLORS)-1) for _ in range(COLS)] for _ in range(ROWS)]def find_matches(board):"""查找所有可消除的方块"""matches = set()# 横向检查for row in range(ROWS):for col in range(COLS - 2):if board[row][col] == board[row][col+1] == board[row][col+2]:matches.update([(row, col), (row, col+1), (row, col+2)])# 纵向检查for col in range(COLS):for row in range(ROWS - 2):if board[row][col] == board[row+1][col] == board[row+2][col]:matches.update([(row, col), (row+1, col), (row+2, col)])return matchesdef drop_blocks(board):"""处理方块下落和新方块生成"""for col in range(COLS):# 收集该列有效方块column = [board[row][col] for row in range(ROWS) if board[row][col] != -1]# 生成新列(补充新方块)new_column = [-1]*(ROWS - len(column)) + column# 更新游戏面板for row in range(ROWS):board[row][col] = new_column[row] if new_column[row] != -1 else random.randint(0, len(COLORS)-1)def draw_board(screen, board, score):"""绘制游戏界面"""screen.fill((30, 30, 30))# 绘制得分font = pygame.font.SysFont(None, 36)text = font.render(f'Score: {score}', True, (255, 255, 255))screen.blit(text, (10, HEIGHT-40))# 绘制方块for row in range(ROWS):for col in range(COLS):color_idx = board[row][col]if color_idx == -1:continuex = col * (BLOCK_SIZE + GAP)y = row * (BLOCK_SIZE + GAP)pygame.draw.rect(screen, COLORS[color_idx], (x, y, BLOCK_SIZE, BLOCK_SIZE))def main():pygame.init()screen = pygame.display.set_mode((WIDTH, HEIGHT))pygame.display.set_caption("消消乐")clock = pygame.time.Clock()board = create_board()selected = Nonescore = 0running = Truewhile running:draw_board(screen, board, score)pygame.display.flip()clock.tick(30)for event in pygame.event.get():if event.type == pygame.QUIT:running = Falseif event.type == pygame.MOUSEBUTTONDOWN:x, y = pygame.mouse.get_pos()col = x // (BLOCK_SIZE + GAP)row = y // (BLOCK_SIZE + GAP)if 0 <= row < ROWS and 0 <= col < COLS:if selected is None:selected = (row, col)else:# 判断是否相邻row1, col1 = selectedif (abs(row - row1) == 1 and col == col1) or (abs(col - col1) == 1 and row == row1):# 交换方块board[row][col], board[row1][col1] = board[row1][col1], board[row][col]# 检查消除matches = find_matches(board)if not matches:# 无效交换,换回来board[row][col], board[row1][col1] = board[row1][col1], board[row][col]else:# 处理连续消除while matches:# 移除匹配方块for (r, c) in matches:board[r][c] = -1score += len(matches)# 方块下落和新方块生成drop_blocks(board)# 检查新的消除matches = find_matches(board)selected = Noneelse:selected = None # 取消选择pygame.quit()if __name__ == "__main__":main()
deepseek官网写消消乐小游戏
import os
import random
from collections import dequeclass PuzzleGame:def __init__(self, size=8):self.size = sizeself.board = []self.score = 0self.colors = ['★', '◆', '●', '▲', '♠', '♦'] # 不同符号表示颜色self.directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] # 移动方向def create_board(self):"""初始化游戏棋盘"""self.board = [[random.choice(self.colors) for _ in range(self.size)] for _ in range(self.size)]# 确保初始棋盘没有现成匹配while self.find_matches():self.board = [[random.choice(self.colors) for _ in range(self.size)] for _ in range(self.size)]def print_board(self):"""打印游戏界面"""os.system('cls' if os.name == 'nt' else 'clear')print(f"当前分数: {self.score}\n")print(" " + " ".join(str(i) for i in range(self.size)))for i, row in enumerate(self.board):print(f"{i} |" + " ".join(row) + "|")def get_swap(self):"""获取用户输入的交换位置"""while True:try:coords = input("\n输入交换坐标 (格式:x1 y1 x2 y2): ").split()if len(coords) != 4:raise ValueErrorx1, y1, x2, y2 = map(int, coords)if self.is_valid_swap(x1, y1, x2, y2):return (x1, y1), (x2, y2)print("无效交换!必须相邻且坐标有效")except (ValueError, IndexError):print("输入格式错误,示例:2 3 2 4")def is_valid_swap(self, x1, y1, x2, y2):"""验证是否为相邻交换"""if not (0 <= x1 < self.size and 0 <= y1 < self.size):return Falseif not (0 <= x2 < self.size and 0 <= y2 < self.size):return Falsereturn abs(x1 - x2) + abs(y1 - y2) == 1 # 曼哈顿距离为1def swap_tiles(self, pos1, pos2):"""交换两个格子"""(x1, y1), (x2, y2) = pos1, pos2self.board[x1][y1], self.board[x2][y2] = self.board[x2][y2], self.board[x1][y1]# 如果没有产生消除,则交换回来if not self.find_matches():self.board[x1][y1], self.board[x2][y2] = self.board[x2][y2], self.board[x1][y1]return Falsereturn Truedef find_matches(self):"""查找所有可消除项"""matches = []# 横向检测for i in range(self.size):j = 0while j < self.size - 2:if self.board[i][j] == self.board[i][j+1] == self.board[i][j+2] != ' ':start = jwhile j < self.size and self.board[i][start] == self.board[i][j]:j += 1if j - start >= 3:matches.extend([(i, col) for col in range(start, j)])else:j += 1# 纵向检测for j in range(self.size):i = 0while i < self.size - 2:if self.board[i][j] == self.board[i+1][j] == self.board[i+2][j] != ' ':start = iwhile i < self.size and self.board[start][j] == self.board[i][j]:i += 1if i - start >= 3:matches.extend([(row, j) for row in range(start, i)])else:i += 1return list(set(matches)) # 去重def remove_matches(self, matches):"""消除匹配项并计分"""for x, y in matches:self.board[x][y] = ' 'self.score += len(matches) * 10 # 每个消除项10分def drop_tiles(self):"""下落填充空位"""for j in range(self.size):column = [self.board[i][j] for i in range(self.size) if self.board[i][j] != ' ']column = [' '] * (self.size - len(column)) + columnfor i in range(self.size):self.board[i][j] = column[i]def refill_board(self):"""补充新的元素"""for i in range(self.size):for j in range(self.size):if self.board[i][j] == ' ':self.board[i][j] = random.choice(self.colors)def has_possible_moves(self):"""检测是否还有可能的移动"""for i in range(self.size):for j in range(self.size):for dx, dy in self.directions:ni, nj = i + dx, j + dyif 0 <= ni < self.size and 0 <= nj < self.size:# 尝试交换self.board[i][j], self.board[ni][nj] = self.board[ni][nj], self.board[i][j]if self.find_matches():self.board[i][j], self.board[ni][nj] = self.board[ni][nj], self.board[i][j]return Trueself.board[i][j], self.board[ni][nj] = self.board[ni][nj], self.board[i][j]return Falsedef play(self):"""主游戏循环"""self.create_board()while True:self.print_board()if not self.has_possible_moves():print("\n游戏结束!无更多可移动步骤")breakpos1, pos2 = self.get_swap()if self.swap_tiles(pos1, pos2):while True:matches = self.find_matches()if not matches:breakself.remove_matches(matches)self.drop_tiles()self.refill_board()self.print_board()if __name__ == "__main__":game = PuzzleGame()game.play()
|
silicon flow中嵌入deepseek写贪吃蛇小游戏(要求生成UI界面)
import tkinter as tk
from tkinter import messagebox
import randomclass SnakeGameUI:def __init__(self, master):self.master = masterself.master.title("贪吃蛇游戏")# 游戏配置self.cell_size = 20self.width = 30 # 格子数量self.height = 30self.speed = 500 # 游戏速度(ms)# 游戏状态self.snake = [(self.width//2, self.height//2)]self.direction = (0, 1)self.food = self.generate_food()self.score = 0self.game_over = False# 创建界面self.create_widgets()self.bind_keys()self.start_game()def create_widgets(self):"""创建界面组件"""# 游戏画布self.canvas = tk.Canvas(self.master,width=self.width*self.cell_size,height=self.height*self.cell_size,bg='black')self.canvas.grid(row=0, column=0, columnspan=3)# 控制面板self.btn_up = tk.Button(self.master, text="↑", command=lambda: self.change_direction((0, -1)))self.btn_left = tk.Button(self.master, text="←", command=lambda: self.change_direction((-1, 0)))self.btn_right = tk.Button(self.master, text="→", command=lambda: self.change_direction((1, 0)))self.btn_down = tk.Button(self.master, text="↓", command=lambda: self.change_direction((0, 1)))self.btn_up.grid(row=1, column=1, sticky="ew")self.btn_left.grid(row=2, column=0, sticky="ew")self.btn_right.grid(row=2, column=2, sticky="ew")self.btn_down.grid(row=2, column=1, sticky="ew")# 分数标签self.lbl_score = tk.Label(self.master, text=f"得分: {self.score}", font=('Arial', 14))self.lbl_score.grid(row=3, column=0, columnspan=3)def bind_keys(self):"""绑定键盘事件"""self.master.bind('<Up>', lambda e: self.change_direction((-1, 0)))self.master.bind('<Down>', lambda e: self.change_direction((1, 0)))self.master.bind('<Left>', lambda e: self.change_direction((0, -1)))self.master.bind('<Right>', lambda e: self.change_direction((0, 1)))def generate_food(self):"""生成食物位置"""while True:x = random.randint(0, self.width-1)y = random.randint(0, self.height-1)if (x, y) not in self.snake:return (x, y)def change_direction(self, new_dir):"""改变移动方向"""# 禁止直接反向移动if (new_dir[0] != -self.direction[0] or new_dir[1] != -self.direction[1]):self.direction = new_dirdef draw(self):"""绘制游戏元素"""self.canvas.delete("all")# 绘制蛇for i, (x, y) in enumerate(self.snake):color = 'lime' if i == 0 else 'green'self.canvas.create_rectangle(x*self.cell_size, y*self.cell_size,(x+1)*self.cell_size, (y+1)*self.cell_size,fill=color, outline='black')# 绘制食物fx, fy = self.foodself.canvas.create_oval(fx*self.cell_size, fy*self.cell_size,(fx+1)*self.cell_size, (fy+1)*self.cell_size,fill='red', outline='darkred')# 更新分数self.lbl_score.config(text=f"得分: {self.score}")def move(self):"""处理移动逻辑"""if self.game_over:return# 计算新头部位置head_x, head_y = self.snake[0]dx, dy = self.directionnew_head = (head_x + dx, head_y + dy)# 碰撞检测if (new_head in self.snake or new_head[0] < 0 or new_head[0] >= self.width ornew_head[1] < 0 or new_head[1] >= self.height):self.game_over = Truemessagebox.showinfo("游戏结束", f"游戏结束!得分: {self.score}")self.master.destroy()returnself.snake.insert(0, new_head)# 吃食物检测if new_head == self.food:self.score += 10self.food = self.generate_food()else:self.snake.pop()self.draw()self.master.after(self.speed, self.move)def start_game(self):"""开始游戏循环"""self.draw()self.master.after(self.speed, self.move)if __name__ == "__main__":root = tk.Tk()game = SnakeGameUI(root)root.mainloop()
用deep seek官网写贪吃蛇小游戏(要求生成UI界面)
import tkinter as tk
from tkinter import messagebox
import random
import json
import osclass SnakeGame:def __init__(self, master):self.master = masterself.master.title("贪吃蛇游戏")# 游戏配置self.cell_size = 25self.width = 20self.height = 20self.speed = 500self.score = 0self.high_score = 0# 游戏状态self.snake = []self.direction = (0, 1)self.food = Noneself.game_active = False# 初始化界面self.create_widgets()self.load_high_score()self.reset_game()def create_widgets(self):"""创建游戏界面"""# 控制面板control_frame = tk.Frame(self.master)control_frame.pack(pady=10)# 游戏控制按钮self.btn_start = tk.Button(control_frame, text="开始游戏", command=self.start_game, width=10)self.btn_stop = tk.Button(control_frame, text="结束游戏", command=self.stop_game, state=tk.DISABLED, width=10)self.btn_start.pack(side=tk.LEFT, padx=5)self.btn_stop.pack(side=tk.LEFT, padx=5)# 方向控制按钮dir_frame = tk.Frame(self.master)dir_frame.pack(pady=5)self.btn_up = tk.Button(dir_frame, text="↑", command=lambda: self.change_direction((-1, 0)))self.btn_left = tk.Button(dir_frame, text="←", command=lambda: self.change_direction((0, -1)))self.btn_right = tk.Button(dir_frame, text="→", command=lambda: self.change_direction((0, 1)))self.btn_down = tk.Button(dir_frame, text="↓", command=lambda: self.change_direction((1, 0)))self.btn_up.grid(row=0, column=1, padx=3)self.btn_left.grid(row=1, column=0, padx=3)self.btn_right.grid(row=1, column=2, padx=3)self.btn_down.grid(row=1, column=1, padx=3)# 游戏画布self.canvas = tk.Canvas(self.master,width=self.width*self.cell_size,height=self.height*self.cell_size,bg="#2E2E2E")self.canvas.pack(pady=10)# 分数显示score_frame = tk.Frame(self.master)score_frame.pack()self.lbl_score = tk.Label(score_frame, text=f"当前得分: {self.score} 最高得分: {self.high_score}",font=("微软雅黑", 12))self.lbl_score.pack()def load_high_score(self):"""加载历史最高分"""if os.path.exists("snake_highscore.json"):try:with open("snake_highscore.json", "r") as f:data = json.load(f)self.high_score = data.get("high_score", 0)except:passdef save_high_score(self):"""保存最高分"""with open("snake_highscore.json", "w") as f:json.dump({"high_score": self.high_score}, f)def reset_game(self):"""重置游戏状态"""self.snake = [(self.width//2, self.height//2)]self.direction = (0, 1)self.food = self.generate_food()self.score = 0self.update_score()def generate_food(self):"""生成食物"""while True:x = random.randint(0, self.width-1)y = random.randint(0, self.height-1)if (x, y) not in self.snake:return (x, y)def change_direction(self, new_dir):"""改变方向"""if self.game_active and (new_dir[0] != -self.direction[0] or new_dir[1] != -self.direction[1]):self.direction = new_dirdef draw(self):"""绘制游戏元素"""self.canvas.delete("all")# 绘制蛇for i, (x, y) in enumerate(self.snake):color = "#4CAF50" if i == 0 else "#8BC34A"self.canvas.create_rectangle(x*self.cell_size, y*self.cell_size,(x+1)*self.cell_size, (y+1)*self.cell_size,fill=color, outline="#2E7D32")# 绘制食物fx, fy = self.foodself.canvas.create_oval(fx*self.cell_size+2, fy*self.cell_size+2,(fx+1)*self.cell_size-2, (fy+1)*self.cell_size-2,fill="#FF5252", outline="#D32F2F")def update_score(self):"""更新分数显示"""self.lbl_score.config(text=f"当前得分: {self.score} 最高得分: {self.high_score}")def move(self):"""移动蛇"""if not self.game_active:return# 计算新头部位置head_x, head_y = self.snake[0]dx, dy = self.directionnew_head = (head_x + dx, head_y + dy)# 碰撞检测if (new_head in self.snake or not (0 <= new_head[0] < self.width) ornot (0 <= new_head[1] < self.height)):self.game_over()returnself.snake.insert(0, new_head)# 吃食物if new_head == self.food:self.score += 10if self.score > self.high_score:self.high_score = self.scoreself.save_high_score()self.food = self.generate_food()self.update_score()else:self.snake.pop()self.draw()self.master.after(self.speed, self.move)def start_game(self):"""开始游戏"""if not self.game_active:self.reset_game()self.game_active = Trueself.btn_start.config(state=tk.DISABLED)self.btn_stop.config(state=tk.NORMAL)self.move()def stop_game(self):"""结束游戏"""if self.game_active:self.game_active = Falseself.btn_start.config(state=tk.NORMAL)self.btn_stop.config(state=tk.DISABLED)messagebox.showinfo("游戏结束", f"游戏已结束!本次得分: {self.score}")def game_over(self):"""游戏结束处理"""self.game_active = Falseself.btn_start.config(state=tk.NORMAL)self.btn_stop.config(state=tk.DISABLED)messagebox.showinfo("游戏结束",f"游戏失败!最终得分: {self.score}\n历史最高分: {self.high_score}")self.draw()if __name__ == "__main__":root = tk.Tk()game = SnakeGame(root)root.mainloop()
今天就记录到这里。
`