我正在尝试创建一个2D拼图滑块游戏.我创建了自己的对象gamestate来存储父游戏状态和新的游戏状态,因为我计划使用BFS解决它.示例数组看起来像
int[][] tArr = {{1,5,2},{3,4,0},{6,8,7}};
Run Code Online (Sandbox Code Playgroud)
这暗示着
[1,5,2,3,4,0,6,8,7]
为了存储这个状态,我使用了以下for循环,它带来了indexOutOfBounds exceptions.
public class GameState {
public int[][] state; //state of the puzzle
public GameState parent; //parent in the game tree
public GameState() {
//initialize state to zeros, parent to null
state = new int[0][0];
parent = null;
}
public GameState(int[][] state) {
//initialize this.state to state, parent to null
this.state = state;
parent = null;
}
public GameState(int[][] state, GameState parent) {
//initialize this.state to state, this.parent to parent
this.state …Run Code Online (Sandbox Code Playgroud)