Java游戏的随机动作AI控制器
我正在尝试为我的敌舰实现一个基本的游戏AI,它可以执行随机动作(即转身射击,然后向前移动,然后可能转身射击等)。我已经做了一个简单的旋转和射击的基本人工智能 以下是RotateAndShoot AI:Java游戏的随机动作AI控制器,java,artificial-intelligence,Java,Artificial Intelligence,我正在尝试为我的敌舰实现一个基本的游戏AI,它可以执行随机动作(即转身射击,然后向前移动,然后可能转身射击等)。我已经做了一个简单的旋转和射击的基本人工智能 以下是RotateAndShoot AI: public class RotateAndShoot implements Controller { Action action = new Action(); @Override public Action action() { action.shoot = true; ac
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;
}
}
以下是控制器类,如果这有助于解释:
public interface Controller {
public Action action();
}
它们使用一个名为Action的类,该类只提供一些分配给动作的变量(例如public int-struch,如果将其转换为on状态,则会将船舶向前移动)。如何实现一种只执行一系列随机操作的AI形式?您可以使用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;
}
您可以使用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;
}