我试图实现一个基本的游戏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的类,它只提供一些分配给操作的变量(例如,公共int推力,如果转换为on状态,则会向前移动)。我如何去实现一种形式的人工智能,它只是做了一系列的随机行动?
发布于 2016-03-01 22:26:01
您可以使用Math.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;
}https://stackoverflow.com/questions/35734653
复制相似问题