gpt4 book ai didi

java - 为什么我不能在不将抽象类的方法更改为静态的情况下初始化它们?

转载 作者:行者123 更新时间:2023-11-29 04:50:18 25 4
gpt4 key购买 nike

<分区>

我正在学习有关构建简单行为 Ai 的教程。它的“大脑”类是抽象的,包含“运行”、“成功”、“失败”等状态。现在在我的 ai 单元 - 机器人类中,我有一个启动机器人的方法

public void update(){

if(Routine.getState()==null){
Routine.start();
}
Routine.act(this, board);

}

Eclipse 告诉我 Routine 中的方法无效,因为:

Cannot make a static reference to the non-static method getState() from the type Routine

我可以为 getState 做些什么,但我也必须将 RoutineState 更改为静态状态,但我不能为 start 或 act 做,因为它们包含 this.

到目前为止,这是人工智能的大脑:

public abstract class Routine {

public enum RoutineState{
Success,
Failure,
Running
}


public RoutineState getState(){
return state;
}

protected RoutineState state;

protected Routine() { }

public void start(){
this.state = RoutineState.Running;
}

public abstract void reset();

public abstract void act(droid droid, board board);

public void succed(){
this.state = RoutineState.Success;
}

public void Fail(){
this.state = RoutineState.Failure;
}

public boolean isSuccess(){
return state.equals(RoutineState.Success);
}

public boolean isFailure(){
return state.equals(RoutineState.Failure);
}

public boolean isRunning(){
return state.equals(RoutineState.Running);
}



}

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