您好我一直在尝试使用广度优先搜索编程算法,找到蓝点退出游戏的最短路径。我是java新手,无法运行/理解该类的算法。我有一个名为gameModel的类,它存储每个点的状态。该计划旨在测试蓝点可以在没有通过橙色点(SELECTED)的情况下离开板的最快方式,并且如果没有出路胜过玩家获胜。我一直在运行程序,并得到编译错误,我不知道如何解决。我将控制器类包含在短点运行的地方。广度优先搜索移动网点游戏
import java.util.Random;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.*;
/**
* The class <b>GameController</b> is the controller of the game. It implements
* the interface ActionListener to be called back when the player makes a move. It computes
* the next step of the game, and then updates model and view.
*/
public class GameController implements ActionListener {
private int size;
private GameModel gameModel;
private GameView gameView;
private boolean click;
/**
* Constructor used for initializing the controller. It creates the game's view
* and the game's model instances
*
* @param size
* the size of the board on which the game will be played
*/
public GameController(int size) {
this.size = size;
this.gameModel = new GameModel(size);
this.gameView = new GameView (gameModel, this);
click = false;
}
/**
* Starts the game
*/
public void start(){
if (click){
List start = new List {gameModel.getCurrentDot().getX(), gameModel.getCurrentDot().getY()};
List<int> targets = new ArrayList<>();
List<int> blocked = nwq ArrayList<>();
for (int i = 0; i < size; i++){
targets.add(i, 0);
targets.add(i, size);
targets.add(1, size);
targets.add(1, 0);
}
for (int i = 0; i < size; i++){
for (int j = 0; j < size; j++)
if(gameModel.getstatus(i, j) == SELECTED){
blocked.add(i, j);
}
String path = Breadth-First-Start(start, targets, blocked);
gameView = new GameView(gameModel, this);
gameView.getBoardView().update();
}
}
public Breadth-First-Start(start, targets, blocked){ // Need help with
Queue queue = new LinkedList();
queue.add(start + "");
while(!queue.isEmpty()){
String p = queue.remove();
if (p != blocked){ //If p is not in blocked paths
if (p == targets){ //If p is in targets
return "q + {p}";
} else {
queue.add("q + {p}");
blocked.add(p);
}
}
}
什么是编译错误?请将它们添加到帖子中。 – hotzst
Sthepanie,这与问题无关,但你必须学会接受一些答案*如果*他们解决了你的问题(或只是留下评论,表明答案不起作用),因为这个网站的工作原理你不会甚至不必付钱给他们接受他们的答案(但你的问题主要是“调试”,他们很难,不容易解决),这样做会引发人们在未来再次帮助你。 –
所有的渥太华学生都会让其他人为他们做功课吗? – Oliver