我正在为一门涉及骑士之旅的启发式编程课程做作业。目前,我有一种方法,旨在用“棋盘”对象填充 8x8 棋盘数组,这些对象知道棋盘上该空间的“可访问性”,以及该棋盘是否曾经被实际访问过。但是,当我创建 8x8 数组并尝试为此数组调用我的“填充”方法时,我收到一条错误消息,告诉我该数组在我正在使用的包中不存在......我在这里做错了什么?不应该像声明数组和调用方法一样简单吗
Board [][] chessboard = new Board [8][8];
chessboard.fill();
还是我的语法错误?这里的参考是我的代码,它创建了我的 Board 对象、我的可访问性矩阵,然后将这些可访问性值复制到我的 8x8 数组上的每个 Board 对象。谢谢!
public class Board {
/*
 * Initialize array that emulates chessboard. Will be 8x8, each space will 
 * contain the number of squares from which that space can be reached. The 
 * knight will start at a new space each tour and choose each move based on
 * the "accessability" of each square within its "move pool". The knight 
 * will move to the square with least accesibility each time. When the 
 * Knight is moved to a square, this square will be marked as visited so 
 * that it cannot be visited again. Also, any space that could have been 
 * moved to but was not will have its accesability reduced by 1.     
 */
private boolean visited;
private int accessValue;
private Board [][] chess = new Board[8][8];
public Board(int acessability, boolean beenVisited)
{
    visited = beenVisited;
    accessValue = acessability;  
}
int [][] accessMatrix = {{2,3,4,4,4,4,3,2},
                        { 3,4,6,6,6,6,4,3 },
                        { 4,6,8,8,8,8,6,4 },
                        { 4,6,8,8,8,8,6,4 },
                        { 4,6,8,8,8,8,6,4 },
            { 4,6,8,8,8,8,6,4 },
            { 3,4,6,6,6,6,4,3 },
            { 2,3,4,4,4,4,3,2}};
public void fill()
{
for (int i = 0 ; i < accessMatrix.length ; i++)
{
    chess[0][i].changeAccess(accessMatrix[0][i]);
}
for (int i = 0 ; i < accessMatrix.length ; i++)
{
    chess[1][i].changeAccess(accessMatrix[1][i]);
}
for (int i = 0 ; i < accessMatrix.length ; i++)
{
    chess[2][i].changeAccess(accessMatrix[2][i]);
}
for (int i = 0 ; i < accessMatrix.length ; i++)
{
    chess[3][i].changeAccess(accessMatrix[3][i]);
}
for (int i = 0 ; i < accessMatrix.length ; i++)
{
    chess[4][i].changeAccess(accessMatrix[4][i]);
}
for (int i = 0 ; i < accessMatrix.length ; i++)
{
    chess[5][i].changeAccess(accessMatrix[5][i]);
}
for (int i = 0 ; i < accessMatrix.length ; i++)
{
    chess[6][i].changeAccess(accessMatrix[6][i]);
}
for (int i = 0 ; i < accessMatrix.length ; i++)
{
    chess[7][i].changeAccess(accessMatrix[7][i]);
}
}   
public int getAccess()
{
return accessValue;
}
public int changeAccess(int newAccess)
{
int accessNew;
accessNew = newAccess;
return accessNew;    
}