Horse Walk Day Board algorithm

Source: Internet
Author: User

Problem description

In the given size of the checkerboard, the chess piece "horse" in the designated starting position, the pawn "horse" rule for the son must go on the chessboard "Day" word; Starting from the starting position of the chess piece "horse", search out a feasible path, make the pawn "horse" can go through all the drop points on the chessboard, and each drop point can walk only once;

For example: The chessboard size is 5*5, the chess piece Ma Fang's starting Drop point is (3, 3); The algorithm needs to search for a section starting from the position (3, 3) including the (1,1),(1,2),(1,3)... (5, 1), (5, 2), (5, 3), (5, 4), (5, 5) in total 25 can be drop all positions;

Problem analysis

Through the above problem description, we have a correct understanding of the content of the problem, and then we begin to make a detailed analysis of the problem, in order to find the correct solution to the problem of reasonable and feasible method;

First of all, we need to use the appropriate data structure in the program to represent the board in question, pieces, pieces of the process of walking; Next we need to analyze the core issues, that is, how to search for a feasible path, what strategy to search, how to express the search process;

For a chessboard of size n*m size, the piece starts at the current position (x, y) and can reach the next position (x ', y '):

(1) (x +1, y +2)

(2) (x +1, Y–2)

(3) (x–1, y +2)

(4) (x–1, y–2)

(5) (x +2, y + 1)

(6) (x +2, y–1)

(7) (x-2, y + 1)

(8) (X-2, y–1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.