Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the horse pedal chessboard with java

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report