javarandom.java

来自「人工智能最简单问题的示例代码」· Java 代码 · 共 54 行

JAVA
54
字号
import java.io.*;
import java.util.Random;

public class JavaRandom {

	public static void main(String[] args) throws IOException {
		Random rand = new Random();
		String str;
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		while (true) {
			try {
				str = in.readLine();
			} catch (IOException e) {
				continue;
			}
			if (str.indexOf("check_status") != -1)
				System.out.print("ready");
			else if (str.indexOf("beetlemove") != -1) {
				switch (rand.nextInt(4)) {
				case 0:
					System.out.print("action up");
					break;
				case 1:
					System.out.print("action down");
					break;
				case 2:
					System.out.print("action left");
					break;
				case 3:
					System.out.print("action right");
					break;
				}
			} else if (str.indexOf("snailmove") != -1) {
				switch (rand.nextInt(4)) {
				case 0:
					System.out.print("action up");
					break;
				case 1:
					System.out.print("action down");
					break;
				case 2:
					System.out.print("action left");
					break;
				case 3:
					System.out.print("action right");
					break;
				}
			}
			System.out.flush();
		}
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?