gpt4 book ai didi

java - Java 游戏的随机 Action AI Controller

转载 作者:行者123 更新时间:2023-12-01 21:47:49 26 4
gpt4 key购买 nike

我正在尝试为我的敌舰实现一个基本的游戏人工智能,该人工智能执行随机 Action (即转身和射击,然后向前移动,然后可能转身并射击等)。我已经制作了一个基本的 AI,只需旋转和射击。

这是 RotateAndShoot AI:

public class RotateAndShoot implements Controller {
Action action = new Action();

@Override
public Action action() {
action.shoot = true;
action.thrust = 1; //1=on 0=off
action.turn = -1; //-1 = left 0 = no turn 1 = right
return action;
}
}

这里是 Controller 类,如果这有助于解释:

public interface Controller {
public Action action();
}

它们使用一个名为 Action 的类,该类仅提供一些分配给操作的变量(例如 public int Twitter ,如果将其转换为 on 状态,则使船向前移动)。我怎样才能实现一种只执行一系列随机操作的人工智能形式?

最佳答案

您可以使用 Math.random() 或 Random。

这是随机的解决方案:

@Override
public Action action() {
Random rand = new Random();
action.shoot = rand.nextBoolean();
action.thrust = rand.nextInt(2);
action.turn = rand.nextInt(3) - 1;
return action;
}

关于java - Java 游戏的随机 Action AI Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35734653/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com