Cursor——ChatGPT的替代品【笔记】

  • 前言
  • 推荐
  • Cursor——ChatGPT的替代品
    • 下载
    • 登录
    • 使用
    • 高级
    • 另外
  • 最后

前言

2023-3-31 22:00:44

以下内容源自《笔记》
仅供学习交流使用

推荐

什么? 你还没用过 Cursor? 智能 AI 代码生成工具 Cursor 安装和使用介绍

Cursor AI IDE 开发者工具

【黑科技】任何人都可以白嫖最强AI!!!

Cursor——ChatGPT的替代品

下载

官网下载Cursor

登录

点击设置
点击sign in

可以使用github账号登录

使用

先别打开任何文件,就可以回答问题了

如果回答的是英文,就它让用中文回答


它能回答,编程问题


如何回答,变成以外的问题,请看后面

可以发现,它默认的是python代码

新建一个文件 main,java

输入文件名,敲回车

编写区,Ctrl+L

就写出的是java代码了

怎么让它问答一个编程以外的问题

新建一个hello.txt文件
然后写一个编程之外的问题

测试有可能不成功

提问:写一封情书

提问:西安邮电大学简介

高级

参考 Cursor AI IDE 开发者工具

以下是扫雷程序

import java.util.Scanner;public class Minesweeper {private int[][] grid;private boolean[][] revealed;private boolean[][] mines;private int rows;private int cols;private int numMines;public Minesweeper(int rows, int cols, int numMines) {this.rows = rows;this.cols = cols;this.numMines = numMines;grid = new int[rows][cols];revealed = new boolean[rows][cols];mines = new boolean[rows][cols];placeMines();calculateNumbers();}private void placeMines() {int count = 0;while (count < numMines) {int row = (int) (Math.random() * rows);int col = (int) (Math.random() * cols);if (!mines[row][col]) {mines[row][col] = true;count++;}}}private void calculateNumbers() {for (int r = 0; r < rows; r++) {for (int c = 0; c < cols; c++) {grid[r][c] = countAdjacentMines(r, c);}}}public void reveal(int row, int col) {if (mines[row][col]) {gameOver();return;}revealed[row][col] = true;if (grid[row][col] == 0) {for (int r = Math.max(0, row - 1); r <= Math.min(rows - 1, row + 1); r++) {for (int c = Math.max(0, col - 1); c <= Math.min(cols - 1, col + 1); c++) {if (!revealed[r][c]) {reveal(r, c);}}}}}private void gameOver() {System.out.println("Game over!");System.exit(0);}public boolean isGameOver() {for (int r = 0; r < rows; r++) {for (int c = 0; c < cols; c++) {if (mines[r][c] && !revealed[r][c]) {return false;}if (!mines[r][c] && !revealed[r][c]) {return false;}}}return true;}// This method returns the number of adjacent mines for a given cellprivate int countAdjacentMines(int row, int col) {int count = 0;for (int r = Math.max(0, row - 1); r <= Math.min(rows - 1, row + 1); r++) {for (int c = Math.max(0, col - 1); c <= Math.min(cols - 1, col + 1); c++) {if (mines[r][c]) {count++;}}}return count;}// This method returns the current state of the game as a string// Each cell is represented by a single character// If the cell is not revealed, it is represented by '-'// If the cell is revealed and contains a mine, it is represented by '*'// If the cell is revealed and does not contain a mine, it is represented by the number of adjacent minespublic String toString() {StringBuilder sb = new StringBuilder();for (int r = 0; r < rows; r++) {for (int c = 0; c < cols; c++) {if (!revealed[r][c]) {sb.append("-");} else if (mines[r][c]) {sb.append("*");} else {sb.append(grid[r][c]);}}sb.append("\n");}return sb.toString();}// We need to add a main method to the Minesweeper class to continue the Minesweeper program// In the main method, we can create a new instance of the Minesweeper class and start the game// We can use a Scanner object to get input from the user and call the reveal method with the user's input// We can also use the isGameOver method to check if the game is over and end the game if necessarypublic static void main(String[] args) {Minesweeper game = new Minesweeper(10, 10, 10);Scanner scanner = new Scanner(System.in);while (!game.isGameOver()) {System.out.println(game.toString());System.out.print("Enter row and column to reveal: ");int row = scanner.nextInt();int col = scanner.nextInt();game.reveal(row, col);}System.out.println(game.toString());System.out.println("Game over!");}}

运行结果

以下是GUI编写的扫雷程序

// Import necessary packages// The code provided does not contain any syntax errors that would prevent it from compiling.
// If the user is experiencing compilation errors, they should check their Java environment and ensure that all necessary packages and dependencies are properly installed.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;// Create a Minesweeper class that extends JFrame and implements ActionListener
public class Minesweeper extends JFrame implements ActionListener {// Declare necessary variablesprivate Container contentPane;private JPanel gamePanel, buttonPanel;private JButton[][] buttons;private int[][] counts;private int size = 10;private int numMines = 10;// Create a constructor for the Minesweeper classpublic Minesweeper() {// Set the title of the JFramesetTitle("Minesweeper");// Get the content pane of the JFramecontentPane = getContentPane();// Set the layout of the content pane to BorderLayoutcontentPane.setLayout(new BorderLayout());// Call the createGamePanel method to create the game panelcreateGamePanel();// Call the createButtonPanel method to create the button panelcreateButtonPanel();// Pack the JFramepack();// Set the JFrame to be visiblesetVisible(true);}// Create a method to create the game panelprivate void createGamePanel() {// Create a new JPanel for the game panelgamePanel = new JPanel();// Set the layout of the game panel to GridLayoutgamePanel.setLayout(new GridLayout(size, size));// Create a new 2D array of JButtons for the buttonsbuttons = new JButton[size][size];// Create a new 2D array of integers for the countscounts = new int[size][size];// Initialize the buttons and counts arraysfor (int i = 0; i < size; i++) {for (int j = 0; j < size; j++) {buttons[i][j] = new JButton();buttons[i][j].addActionListener(this);gamePanel.add(buttons[i][j]);counts[i][j] = 0;}}// Add the game panel to the content panecontentPane.add(gamePanel, BorderLayout.CENTER);}// Create a method to create the button panelprivate void createButtonPanel() {// Create a new JPanel for the button panelbuttonPanel = new JPanel();// Set the layout// Set the layout of the button panel to FlowLayoutbuttonPanel.setLayout(new FlowLayout());// Create a new JButton for the "New Game" buttonJButton newGameButton = new JButton("New Game");// Add an ActionListener to the "New Game" buttonnewGameButton.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {newGame();}});// Add the "New Game" button to the button panelbuttonPanel.add(newGameButton);// Add the button panel to the content panecontentPane.add(buttonPanel, BorderLayout.SOUTH);// Create a new JButton for the "Reset" buttonJButton resetButton = new JButton("Reset");// Add an ActionListener to the "Reset" buttonresetButton.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {reset();}});// Add the "Reset" button to the button panelbuttonPanel.add(resetButton);// Add the button panel to the content panecontentPane.add(buttonPanel, BorderLayout.SOUTH);// Create a new JButton for the "Settings" buttonJButton settingsButton = new JButton("Settings");// Add an ActionListener to the "Settings" buttonsettingsButton.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {// Call the showSettingsDialog method to show the settings dialogshowSettingsDialog();}});// Add the "Settings" button to the button panelbuttonPanel.add(settingsButton);// Add the button panel to the content panecontentPane.add(buttonPanel, BorderLayout.SOUTH);}// Create a method to generate the mines and update the countsprivate void generateMines(int row, int col) {// Declare necessary variablesint mines = 0;int i, j;// Generate the mineswhile (mines < numMines) {i = (int)(Math.random() * size);j = (int)(Math.random() * size);if (counts[i][j] != -1 && !(i == row && j == col)) {counts[i][j] = -1;mines++;}}// Update the countsfor (i = 0; i < size; i++) {for (j = 0; j < size; j++) {if (counts[i][j] == -1) {updateCounts(i, j);}}}}// Create a method to update the countsprivate void updateCounts(int row, int col) {// Declare necessary variablesint i, j;// Update the countsfor (i = row - 1; i <= row + 1; i++) {for (j = col - 1; j <= col + 1; j++) {if (i >= 0 && i < size && j >= 0 && j < size && counts[i][j] != -1) {counts[i][j]++;}}}}// Create a method to reveal the button at the specified row and columnprivate void reveal(int row, int col) {// Check if the button is already revealed or flaggedif (buttons[row][col].getText().length() > 0) {return;}// Check if the button contains a mineif (counts[row][col] == -1) {// Reveal all the mines and end the gamefor (int i = 0; i < size; i++) {for (int j = 0; j < size; j++) {if (counts[i][j] == -1) {buttons[i][j].setText("*");}}}JOptionPane.showMessageDialog(this, "You lose!");newGame();return;}// Reveal the button and check if the game is won// Reveal the button and check if the game is wonbuttons[row][col].setText(Integer.toString(counts[row][col]));if (checkWin()) {JOptionPane.showMessageDialog(this, "You win!");newGame();}}// Create a method to check if the game is wonprivate boolean checkWin() {// Declare necessary variablesint revealed = 0;// Check if all non-mine buttons are revealedfor (int i = 0; i < size; i++) {for (int j = 0; j < size; j++) {if (buttons[i][j].getText().length() > 0 || counts[i][j] == -1) {revealed++;}}}if (revealed == size * size) {return true;}return false;}// Create a method to start a new gameprivate void newGame() {// Reset the counts and buttons arrayscounts = new int[size][size];for (int i = 0; i < size; i++) {for (int j = 0; j < size; j++) {buttons[i][j].setText("");counts[i][j] = 0;}}// Generate the mines and update the countsgenerateMines(-1, -1);}// Create a method to reset the gameprivate void reset() {// Reset the counts and buttons arraysfor (int i = 0; i < size; i++) {for (int j = 0; j < size; j++) {buttons[i][j].setText("");counts[i][j] = 0;}}}private void showSettingsDialog() {// Declare necessary variablesJTextField sizeField = new JTextField(Integer.toString(size));JTextField numMinesField = new JTextField(Integer.toString(numMines));Object[] message = {"Size:", sizeField,"Number of Mines:", numMinesField};// Show the settings dialog and update the settingsint option = JOptionPane.showConfirmDialog(this, message, "Settings", JOptionPane.OK_CANCEL_OPTION);if (option == JOptionPane.OK_OPTION) {try {int newSize = Integer.parseInt(sizeField.getText());int newNumMines = Integer.parseInt(numMinesField.getText());if (newSize > 0 && newSize <= 30 && newNumMines >= 0 && newNumMines < newSize * newSize) {size = newSize;numMines = newNumMines;newGame();} else {JOptionPane.showMessageDialog(this, "Invalid input!");}} catch (NumberFormatException e) {JOptionPane.showMessageDialog(this, "Invalid input!");}}}// Create an actionPerformed method to handle button clickspublic void actionPerformed(ActionEvent e) {// Get the button that was clickedJButton button = (JButton)e.getSource();// Find the row and column of the buttonint row = -1, col = -1;for (int i = 0; i < size; i++) {for (int j = 0; j < size; j++) {if (buttons[i][j] == button) {row = i;col = j;break;}}}// Call the reveal method to reveal the buttonreveal(row, col);}// Create a main method to create a new Minesweeper objectpublic static void main(String[] args) {new Minesweeper();}// Create a method to flag the button at the specified row and columnprivate void flag(int row, int col) {// Check if the button is already revealedif (buttons[row][col].getText().length() > 0) {return;}// Check if the button is already flaggedif (buttons[row][col].getText().equals("F")) {buttons[row][col].setText("");return;}// Flag the buttonbuttons[row][col].setText("F");}// Create a method to handle right-clicks on buttonsprivate void handleRightClick(MouseEvent e) {// Get the button that was clickedJButton button = (JButton)e.getSource();// Find the row and column of the buttonint row = -1, col = -1;for (int i = 0; i < size; i++) {for (int j = 0; j < size; j++) {if (buttons[i][j] == button) {row = i;col = j;break;}}}// Call the flag method to flag the buttonflag(row, col);}// Override the mousePressed method to handle right-clicks on buttonspublic void mousePressed(MouseEvent e) {if (SwingUtilities.isRightMouseButton(e)) {handleRightClick(e);}}// Create a method to handle keyboard eventspublic void keyPressed(KeyEvent e) {// Check if the "r" key is pressedif (e.getKeyCode() == KeyEvent.VK_R) {reset();}// Check if the "n" key is pressedif (e.getKeyCode() == KeyEvent.VK_N) {newGame();}// Check if the "s" key is pressedif (e.getKeyCode() == KeyEvent.VK_S) {showSettingsDialog();}}// Create a method to initialize the gameprivate void initGame() {// Set the size and number of minessize = 10;numMines = 10;// Create the counts and buttons arrayscounts = new int[size][size];buttons = new JButton[size][size];// Create the game panelgamePanel = new JPanel();gamePanel.setLayout(new GridLayout(size, size));// Create the buttons and add them to the game panelfor (int i = 0; i < size; i++) {for (int j = 0; j < size; j++) {buttons[i][j] = new JButton();buttons[i][j].addActionListener(this);buttons[i][j].addMouseListener(new MouseAdapter() {public void mousePressed(MouseEvent e) {if (SwingUtilities.isRightMouseButton(e)) {handleRightClick(e);}}});gamePanel.add(buttons[i][j]);}}// Add the game panel to the content panecontentPane.add(gamePanel, BorderLayout.CENTER);// Create the button panelcreateButtonPanel();// Generate the mines and update the countsgenerateMines(-1, -1);}}

运行结果

另外

VSCode软件插件Chatmoss,也可以体验,但是好像有额度。

以下是GUI的扫雷程序


最后

2023-3-31 22:43:31

祝大家逢考必过
点赞收藏关注哦

Cursor——ChatGPT的替代品【笔记】相关推荐

  1. 【AI热点技术】ChatGPT开源替代品——LLaMA系列之「羊驼家族」

    ChatGPT开源替代品--LLaMA系列之「羊驼家族」 1. Alpaca 2. Vicuna 3. Koala 4. ChatLLaMA 5. FreedomGPT 6. ColossalChat ...

  2. 吴恩达ChatGPT网课笔记Prompt Engineering——训练ChatGPT前请先训练自己

    吴恩达ChatGPT网课笔记Prompt Engineering--训练ChatGPT前请先训练自己 主要是吴恩达的网课,还有部分github的prompt-engineering-for-devel ...

  3. ChatGPT提问技巧 笔记

    今天看视频的过程中,学习到了向ChatGPT提问的一些技巧,其中有一些对我而言很有用. 1.定义身份+描述细节 第一点,提问的时候给ChatGPT身份定义,同时描述问题的背景,甚至可以让ChatGPT ...

  4. 吴恩达ChatGPT《Building Systems with the ChatGPT API》笔记

    1. 课程介绍 使用ChatGPT搭建端到端的LLM系统 本课程将演示使用ChatGPT API搭建一个端到端的客户服务辅助系统,其将多个调用链接到语言模型,根据前一个调用的输出来决定使用不同的指令, ...

  5. 生命的意義在你的内心

    不把生命的意義,寄託在外物之上 如今的人,太過於追求財物等外在事物,將自己人生的希望,生命的意義寄託在它們之上.當自己人生處於低谷的時候,要是沒有這些東西支撐自己,可能就沒有奮鬥下去的動力了. 王陽明 ...

  6. ChatGPT的1000+篇文章总结

    ChatGPT的1000+篇文章总结 本文收集和总结了有关ChatGPT的1000+篇文章,由于篇幅有限只能总结近期的内容,想了解更多内容可以访问:http://www.ai2news.com/, 其 ...

  7. 开发者笑疯了! LLaMa惊天泄露引爆ChatGPT平替狂潮,开源LLM领域变天

    [导读]Meta的LLaMA模型开源,让文本大模型迎来了Stable Diffustion时刻.谁都没想到,LLaMA的一场「史诗级」泄漏,产生了一系列表现惊艳的ChatGPT「平替」. 谁能想到,一 ...

  8. 开源LLM领域变天!LLaMa惊天泄露引爆ChatGPT平替狂潮

    ©作者 | Aeneas 好困 来源 | 新智元 Meta的LLaMA模型开源,让文本大模型迎来了Stable Diffustion时刻.谁都没想到,LLaMA的一场「史诗级」泄漏,产生了一系列表现惊 ...

  9. 我的 Python 全栈开发自学笔记

    学习 Python 虽然不一定能直接带来好的工作机会,但如果你想在工作中快速提升自己能力以及工作效率,那么建议一定要学习 Python. 我是一个 Python 爱好者,在过去的七年里,我把自己在学习 ...

最新文章

  1. bindservice启动服务
  2. 谷歌深度学习四大教训:应用、系统、数据及原理(附数据集列表)
  3. 操作系统--文件管理之索引
  4. Kubernetes:实现应用不停机更新
  5. 全栈深度学习第2期: 开发套件与工具篇
  6. 使用SDK进行二次开发流程简述
  7. C++ list 函数用法整理
  8. 【牛客网-公司真题-前端入门篇】——如何快速上手牛客
  9. 【Makefile】Makefile编写规则
  10. 软考中级(系统集成项目管理工程师)(备考用)
  11. PLSQL 下载、安装、配置驱动连接 详解
  12. 知识点总结之学习方式
  13. 如何用计算机环境设计,计算机绘图软件在环境艺术设计中运用.doc
  14. 51单片机数码管滚动显示学号_数协微课 | LED数码管与51单片机应用
  15. 2022百度之星程序设计大赛 - 复赛 1001 子序列
  16. 质数检验(埃拉托色筛选法、根号x复杂度算法)
  17. comsol—偏振光仿真
  18. Filter过滤词汇
  19. JavaScript中函数
  20. 计算机二级办公室应用题目,计算机二级考试办公室软件高级应用试题

热门文章

  1. MYSQL 性能优化 index 函数,隐藏,前缀,hash 索引 使用方法(2)
  2. html表单验证方法,简述HTML交互式表单验证方法
  3. thinkajax入门------验证ThinkAjax.send 、ajaxReturn
  4. SQL注入基础--判断闭合形式
  5. 文献阅读-Clinical and Biological subtypes of B-cell lymphoma revealed by microenvironment signature
  6. LeetCode 2309. 兼具大小写的最好英文字母
  7. 欧盟GDPR通用数据保护条例-原文
  8. MPU6050配置低功耗和中断
  9. JAVA Spring Security对接QQ快速登录(web应用)
  10. connection_reset解决方案