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

这篇具有很好参考价值的文章主要介绍了Cursor——ChatGPT的替代品【笔记】。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

前言

2023-3-31 22:00:44

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

推荐

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

Cursor AI IDE 开发者工具

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

Cursor——ChatGPT的替代品

下载

官网下载Cursor
Cursor——ChatGPT的替代品【笔记】

登录

点击设置
点击sign in
Cursor——ChatGPT的替代品【笔记】

可以使用github账号登录

使用

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

如果回答的是英文,就它让用中文回答
Cursor——ChatGPT的替代品【笔记】
Cursor——ChatGPT的替代品【笔记】
它能回答,编程问题

Cursor——ChatGPT的替代品【笔记】
如何回答,变成以外的问题,请看后面
Cursor——ChatGPT的替代品【笔记】

可以发现,它默认的是python代码
Cursor——ChatGPT的替代品【笔记】

新建一个文件 main,java
Cursor——ChatGPT的替代品【笔记】
输入文件名,敲回车
Cursor——ChatGPT的替代品【笔记】
编写区,Ctrl+L
Cursor——ChatGPT的替代品【笔记】
就写出的是java代码了
Cursor——ChatGPT的替代品【笔记】
怎么让它问答一个编程以外的问题

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

测试有可能不成功

提问:写一封情书
Cursor——ChatGPT的替代品【笔记】
提问:西安邮电大学简介
Cursor——ChatGPT的替代品【笔记】

高级

参考 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 cell
    private 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 mines
    public 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 necessary
    
    
    public 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!");
    }


}

运行结果
Cursor——ChatGPT的替代品【笔记】

以下是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 variables
      private 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 class
      public Minesweeper() {
        // Set the title of the JFrame
        setTitle("Minesweeper");
        
        // Get the content pane of the JFrame
        contentPane = getContentPane();
        
        // Set the layout of the content pane to BorderLayout
        contentPane.setLayout(new BorderLayout());
        
        // Call the createGamePanel method to create the game panel
        createGamePanel();
        
        // Call the createButtonPanel method to create the button panel
        createButtonPanel();
        
        // Pack the JFrame
        pack();
        
        // Set the JFrame to be visible
        setVisible(true);
      }
  
    // Create a method to create the game panel
    private void createGamePanel() {
        // Create a new JPanel for the game panel
        gamePanel = new JPanel();
        
        // Set the layout of the game panel to GridLayout
        gamePanel.setLayout(new GridLayout(size, size));
        
        // Create a new 2D array of JButtons for the buttons
        buttons = new JButton[size][size];
        
        // Create a new 2D array of integers for the counts
        counts = new int[size][size];
        
        // Initialize the buttons and counts arrays
        for (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 pane
        contentPane.add(gamePanel, BorderLayout.CENTER);
    }
  
    // Create a method to create the button panel
    private void createButtonPanel() {
        // Create a new JPanel for the button panel
        buttonPanel = new JPanel();
        
        // Set the layout// Set the layout of the button panel to FlowLayout
        buttonPanel.setLayout(new FlowLayout());
    
        // Create a new JButton for the "New Game" button
        JButton newGameButton = new JButton("New Game");
    
        // Add an ActionListener to the "New Game" button
        newGameButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                newGame();
            }
        });

        // Add the "New Game" button to the button panel
        buttonPanel.add(newGameButton);
        
        // Add the button panel to the content pane
        contentPane.add(buttonPanel, BorderLayout.SOUTH);// Create a new JButton for the "Reset" button
        JButton resetButton = new JButton("Reset");
    
        // Add an ActionListener to the "Reset" button
        resetButton.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            reset();
          }
        });

        // Add the "Reset" button to the button panel
        buttonPanel.add(resetButton);
        
        // Add the button panel to the content pane
        contentPane.add(buttonPanel, BorderLayout.SOUTH);
            
        // Create a new JButton for the "Settings" button
        JButton settingsButton = new JButton("Settings");
        
        // Add an ActionListener to the "Settings" button
        settingsButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                // Call the showSettingsDialog method to show the settings dialog
                showSettingsDialog();
            }
        });
    
        // Add the "Settings" button to the button panel
        buttonPanel.add(settingsButton);
    
        // Add the button panel to the content pane
        contentPane.add(buttonPanel, BorderLayout.SOUTH);
    }
    // Create a method to generate the mines and update the counts
    private void generateMines(int row, int col) {
      // Declare necessary variables
      int mines = 0;
      int i, j;
      
      // Generate the mines
      while (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 counts
      for (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 counts
    private void updateCounts(int row, int col) {
      // Declare necessary variables
      int i, j;
  
      // Update the counts
      for (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 column
    private void reveal(int row, int col) {
      // Check if the button is already revealed or flagged
      if (buttons[row][col].getText().length() > 0) {
        return;
      }
      
      // Check if the button contains a mine
      if (counts[row][col] == -1) {
        // Reveal all the mines and end the game
        for (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 won
      buttons[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 won
    private boolean checkWin() {
      // Declare necessary variables
      int revealed = 0;
      
      // Check if all non-mine buttons are revealed
      for (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 game
    private void newGame() {
      // Reset the counts and buttons arrays
      counts = 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 counts
      generateMines(-1, -1);
    }

    // Create a method to reset the game
    private void reset() {
      // Reset the counts and buttons arrays
      for (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 variables
      JTextField 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 settings
      int 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 clicks
    public void actionPerformed(ActionEvent e) {
      // Get the button that was clicked
      JButton button = (JButton)e.getSource();
      
      // Find the row and column of the button
      int 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 button
      reveal(row, col);
    }
    // Create a main method to create a new Minesweeper object
    public static void main(String[] args) {
      new Minesweeper();
    }
    
    // Create a method to flag the button at the specified row and column
    private void flag(int row, int col) {
      // Check if the button is already revealed
      if (buttons[row][col].getText().length() > 0) {
        return;
      }
      
      // Check if the button is already flagged
      if (buttons[row][col].getText().equals("F")) {
        buttons[row][col].setText("");
        return;
      }
      
      // Flag the button
      buttons[row][col].setText("F");
    }
    // Create a method to handle right-clicks on buttons
    private void handleRightClick(MouseEvent e) {
      // Get the button that was clicked
      JButton button = (JButton)e.getSource();
      
      // Find the row and column of the button
      int 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 button
      flag(row, col);
    }

    // Override the mousePressed method to handle right-clicks on buttons
    
    public void mousePressed(MouseEvent e) {
      if (SwingUtilities.isRightMouseButton(e)) {
        handleRightClick(e);
      }
    }
    // Create a method to handle keyboard events
    
    public void keyPressed(KeyEvent e) {
      // Check if the "r" key is pressed
      if (e.getKeyCode() == KeyEvent.VK_R) {
        reset();
      }
      
      // Check if the "n" key is pressed
      if (e.getKeyCode() == KeyEvent.VK_N) {
        newGame();
      }
      
      // Check if the "s" key is pressed
      if (e.getKeyCode() == KeyEvent.VK_S) {
        showSettingsDialog();
      }
    }

    // Create a method to initialize the game
    private void initGame() {
      // Set the size and number of mines
      size = 10;
      numMines = 10;
      
      // Create the counts and buttons arrays
      counts = new int[size][size];
      buttons = new JButton[size][size];
      
      // Create the game panel
      gamePanel = new JPanel();
      gamePanel.setLayout(new GridLayout(size, size));
      
      // Create the buttons and add them to the game panel
      for (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 pane
      contentPane.add(gamePanel, BorderLayout.CENTER);
      
      // Create the button panel
      createButtonPanel();
      
      // Generate the mines and update the counts
      generateMines(-1, -1);
    }
    
   


}

运行结果
Cursor——ChatGPT的替代品【笔记】

另外

VSCode软件插件Chatmoss,也可以体验,但是好像有额度。
Cursor——ChatGPT的替代品【笔记】

以下是GUI的扫雷程序


最后

2023-3-31 22:43:31

祝大家逢考必过
点赞收藏关注哦文章来源地址https://www.toymoban.com/news/detail-407324.html

到了这里,关于Cursor——ChatGPT的替代品【笔记】的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • selenium的新一代替代品---DrissionPage(very 推荐)

    官方文档地址: http://g1879.gitee.io/drissionpagedocs/ DrissionPage 是一个基于 python 的网页自动化工具。 它既能控制浏览器,也能收发数据包,还能把两者合而为一。 可兼顾浏览器自动化的便利性和 requests 的高效率。 它功能强大,内置无数人性化设计和便捷功能。 它的语法简洁而优

    2024年02月11日
    浏览(29)
  • 了解一下 Fossil,一个 Git 的替代品 | Linux 中国

    Fossil 是一个集版本控制系统、bug 追踪、维基、论坛以及文档解决方案于一体的系统。 正如任何程序员都知道的,有很多原因说明跟踪代码更改是至关重要的。有时候你只是想知道你的项目是如何开始和发展的历史,这是出于好奇或教育的原因。其他时候,您希望允许其他编

    2024年02月14日
    浏览(30)
  • AI程序员Devin的开源替代品-Devika

    Devika是一名高级人工智能软件工程师,可以理解人类的高级指令,将它们分解成步骤,研究相关信息,并编写代码来实现给定的目标。Devika利用大型语言模型、规划和推理算法以及网页浏览能力来智能地开发软件。 Devika的目标是通过提供一个人工智能结对程序员来彻底改变我

    2024年04月28日
    浏览(25)
  • Centos停止维护以后Rocky Linux是最好的替代品

    公众号: MCNU云原生 ,欢迎微信搜索关注,更多干货,及时掌握! 目录 一、Centos Stream不可取 二、Rocky Linux是最好的生产应用替代品 三、个人学习的选择 1、Centos 7/Centos 8 2、Rocky Linux 3、Mint 4、Debian 5、Ubuntu 2020年12月08日,CentOS官方宣布了停止维护CentOS Linux的计划,并推出了

    2024年02月05日
    浏览(41)
  • ClickHouse Keeper: 一个用 C++ 编写的 ZooKeeper 替代品

    。 本文字数:9915;估计阅读时间:25 分钟 审校:庄晓东(魏庄) 本文在公众号【ClickHouseInc】首发 ClickHouse 是用于实时应用和分析的最快且资源利用率最高的开源数据库。ClickHouse Keeper 是 ClickHouse 的一个组件,是 ZooKeeper 的快速、更节省资源和功能丰富的替代品。这个开源

    2024年02月05日
    浏览(23)
  • x-cmd pkg | tsx - Node.js 的直接替代品

    tsx 代表 “TypeScript execute”,由 TypeScript 编写,内部使用由 Go 语言编写的 esbuild 核心二进制实现超快的 TypeScript 编译,旨在增强 Node.js 以无缝运行 TypeScript / ESM / CJS module 编写的脚本文件,成为 node 命令的直接替代品。 使用 x env use tsx 即可自动下载并使用 在终端运行 eval \\\"$(

    2024年01月22日
    浏览(40)
  • x-cmd pkg | sd - sed 命令的现代化替代品

    sd 是一个基于正则表达式的搜索和替换文本的命令行工具,类似于 sed,但 sd 使用更简单,对用户更为友好。 使用 x sd 即可自动下载并使用 在终端运行 eval \\\"$(curl https://get.x-cmd.com)\\\" 即可完成 x 命令安装, 详情参考 x-cmd 官网 x-cmd 提供1分钟教程,其中包含了 sd 命令常用功能的

    2024年01月16日
    浏览(47)
  • CentOS Linux的替代品(六)_BigCloud Enterprise Linux R8 U2 基础安装教程

    BC-Linux借助中国移动应用产业链及上下游发展优势 ,开展常态化生态认证,全面兼容飞腾、鲲鹏、海光、龙芯、兆芯、申威6大国产芯片,与国内主流服务器、中间件、数据库、安全组件等厂商互认证,已完成百款软硬件产品的适配,可以应用于业务全场景,打造更安全、更广

    2024年02月12日
    浏览(24)
  • 微软应用商店Microsoft Store错误代码: 0xC002001B官方解决方法和Windows计算器替代品Qalculate

    Windows10计算器软件不能使用,本想通过Microsoft Store重新安装一下,结果微软应用商店Microsoft Store显示错误代码: 如图所示 0xC002001B 原文链接点击跳转 下载地址 Qalculate功能更强大好用

    2024年02月12日
    浏览(43)
  • ROS小车研究笔记1/31/2023 小车硬件结构及键盘移动控制节点

    1 小车硬件结构 1 中控设备 上方的单片机用于控制电机运动,搭载wifi模块和电量显示屏。下方为树莓派,安装了ROS系统和Ubuntu系统,用于整个小车控制。显示屏和树莓派相连 2 传感器系统 激光雷达及转换器。激光雷达和转换器相连,再由转换器连接树莓派以控制激光雷达 摄

    2024年02月09日
    浏览(53)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包