How to realize the horse pedal chessboard with java
This article is about how to implement the horse pedal chessboard with java. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
The details are as follows
The horse pedal chessboard is easy to implement, but sometimes it runs very slowly, and it may not be able to produce results. Here, greedy algorithms are used to optimize, that is, to find out the most difficult path, that is, the least position for the next step to play chess.
The complete code of the algorithm is given below:
/ * * Horse pedal chessboard problem: (solved by greedy method) * there are 64 positions on the chessboard, and the "day" word walking method happens to cover the entire chessboard * / / the next direction class class Direction {int x; int y; int wayOutNum } public class Hores_chessboard_1 {static final int [] dx = {- 2,-1, 1, 2, 2, 1,-1,-2}; / / incremental static final int [] dy in x direction = {1, 2, 2, 1,-1,-2,-2,-1}; incremental static final int N in / / y direction = 8 Static int [] [] chessboard = new int [N] [N]; / chessboard / * * @ param nami * @ param x return is the position of the piece * @ return. If the position of the piece is invalid, a number greater than 8 is returned. * otherwise, the number of the next exit of the pieces will be returned * / static int wayOut (int x, int y) {int count = 0; int tx, ty, I; / / determine whether the chessboard boundary is exceeded, and whether the position has been if (x7 | | Y7 | | chessboard [x] [y]! = 0) {return 9;} for (iS0) IMur1 & & tx-1 & & ty