用于Java游戏的随机动作AI控制器

我正在尝试为我的敌方舰船实现一个基本的游戏AI,使其执行随机动作(例如转向并射击,然后向前移动,然后可能掉头再射击等)。我已经制作了一个简单的AI,它只会旋转并射击。

这是RotateAndShoot AI的代码:

public class RotateAndShoot implements Controller {Action action = new Action();@Overridepublic 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 thrust,如果设置为开启状态,会使舰船向前移动)。我该如何实现一个只执行一系列随机动作的AI形式呢?


回答:

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

这是使用Random类的解决方案:

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

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注