Ai人机猜拳游戏伪代码转换为Java语言

img


这是个人机猜拳游戏,要求电脑前十次随机出拳,十次后根据人的出拳习惯进行出拳,想知道else后如何使用二维数组模拟人的出拳习惯,希望指点一二
本人大学党,刚接触,求指点


import java.util.Random;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        // 创建 Scanner 对象,用于获取用户输入
        Scanner scanner = new Scanner(System.in);

        // 创建 Random 对象,用于生成随机数
        Random random = new Random();

        // 循环进行猜拳
        while (true) {
            // 提示用户输入出拳决策
            System.out.println("请出拳:1. 剪刀 2. 石头 3. 布");
            int player = scanner.nextInt();

            // 生成随机数,模拟电脑出拳
            int computer = random.nextInt(3) + 1;

            // 判断胜负
            if (player == computer) {
                // 平局
                System.out.println("平局");
            } else if ((player == 1 && computer == 2) || (player == 2 && computer == 3) || (player == 3 && computer == 1)) {
                // 电脑胜利
                System.out.println("电脑胜利");
            } else {
                // 玩家胜利
                System.out.println("玩家胜利");
            }
        }
    }
}


import java.util.Scanner;

public class AiFingerGuessingGame {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String userChoice;
String computerChoice;
int computerRandom;

  while (true) {
     // Prompt user to enter their choice
     System.out.println("Enter your choice (rock, paper, or scissors): ");
     userChoice = input.nextLine();
     
     // Generate random number for computer's choice
     computerRandom = (int)(Math.random() * 3);
     
     // Convert random number to corresponding choice
     if (computerRandom == 0) {
        computerChoice = "rock";
     } else if (computerRandom == 1) {
        computerChoice = "paper";
     } else {
        computerChoice = "scissors";
     }
     
     // Compare choices and determine winner
     if (userChoice.equals(computerChoice)) {
        System.out.println("It's a tie!");
     } else if (userChoice.equals("rock")) {
        if (computerChoice.equals("scissors")) {
           System.out.println("You win!");
        } else {
           System.out.println("Computer wins.");
        }
     } else if (userChoice.equals("paper")) {
        if (computerChoice.equals("rock")) {
           System.out.println("You win!");
        } else {
           System.out.println("Computer wins.");
        }
     } else if (userChoice.equals("scissors")) {
        if (computerChoice.equals("paper")) {
           System.out.println("You win!");
        } else {
           System.out.println("Computer wins.");
        }
     }
     
     // Prompt user to play again
     System.out.println("Do you want to play again? (yes/no)");
     String playAgain = input.nextLine();
     if (playAgain.equals("no")) {
        break;
     }
  }
}
}

东软?