用Java的两个类来解决8个难题?
我正在尝试用Java中的*解决8个难题。 我在这里读到了 我正在用这种API创建一个数据类型板用Java的两个类来解决8个难题?,java,algorithm,sliding-tile-puzzle,Java,Algorithm,Sliding Tile Puzzle,我正在尝试用Java中的*解决8个难题。 我在这里读到了 我正在用这种API创建一个数据类型板 public Board(int[][] tiles) // create a board from an n-by-n array of tiles, // where tiles[row][col] = tile at (row, col) public String toS
public Board(int[][] tiles) // create a board from an n-by-n array of tiles,
// where tiles[row][col] = tile at (row, col)
public String toString() // string representation of this board
public int tileAt(int row, int col) // tile at (row, col) or 0 if blank
public int size() // board size n
public int hamming() // number of tiles out of place
public int manhattan() // sum of Manhattan distances between tiles and goal
public boolean isGoal() // is this board the goal board?
public boolean equals(Object y) // does this board equal y?
public Iterable<Board> neighbors() // all neighboring boards
public boolean isSolvable() // is this board solvable?
public static void main(String[] args) // unit testing (required)
}
public Board(int[][]tiles)//从n×n的tile数组创建一个板,
//其中tiles[row][col]=tile at(row,col)
public String toString()//此板的字符串表示形式
public int tileAt(int row,int col)//tile at(row,col)或0(如果为空)
public int size()//电路板大小n
public int hamming()//瓷砖数量不合适
public int manhattan()//瓷砖和目标之间的曼哈顿距离之和
public boolean isGoal()//这是目标板吗?
公共布尔值等于(对象y)//此电路板是否等于y?
公共Iterable邻居()//所有相邻板
public boolean isSolvable()//此板可解吗?
公共静态void main(字符串[]args)//单元测试(必需)
}
(根据)
.
我不明白为什么我需要两个java类,一个Board和一个Solver。我知道Board班将有无数的方法来计算hamming和Manhattan距离等。。。但是为什么呢?我知道将创建多个board对象,每个对象表示8的不同状态,并使用各种不同的tile解决难题,但为什么我需要两个类呢?解算器类将如何解决和实现/使用Board类?多谢各位 您所遵循的指南中只有两个“需要”一词的实例,并且都与拥有两个类无关。所以没人说你需要两门课;这只是一个更好的设计。对于解算器来说,电路板是一种不同的东西,因此它们由不同的类表示。(这一个提到了两个类)为什么有两个类是更好的设计?与Board类相比,为什么为Solver提供(例如)isSolvable()方法更好?“为什么设计X比设计Y更好?”是一个相当广泛的问题,您要问的是OOP,而不是算法。我建议你读一篇关于软件设计的介绍性文章,如果这还不清楚,你至少要问一个更具体的问题。