Advanced version of horse traversal-Knight Parade (Added evaluation function) [teaks & xgluxv & R]

Source: Internet
Author: User

Last week, a simple horse traversal was released.ProgramBecause the method is not good, it cannot effectively solve the problem of Knight parade. This release can solve this problem within a tolerable time range, and greatly improve the search speed of non-Parade routes. It can be said that the advanced version of horse traversal.

The so-called knight parade problem, that is, on the basis of horse traversal, requires the horse to go through the chess board, if you take another step, you can return to the original starting point, the traversal route meets the requirements of the knight parade.

The question of Knight parade is actually a problem of Hamilton ring. If you search blindly, the cost is high and the results will not be obtained for a long time. Therefore, the evaluation function (navigator function) is added to this method. The specific method is to check which of the following candidate points can have the least direction of action, so this point is given priority. In this way, the remaining points will have as many direction options as possible, with fewer chances to be blocked, so that effective solutions can be found faster.

Haha, this method was obtained by previous researchers to manually solve the problem of Knight parade. It can be solved with paper and pen, not to mention the use of computers to search for _ ^.

You can also download the C ++ and C # versions.Code, What they achieveAlgorithmThe search process is the same.

I don't think the performance of using this algorithm to test C ++ and C # is very comprehensive. After all, the algorithm only uses a small part of the language's functions, therefore, we cannot fully reflect the differences between the two. We can only look at the implementation efficiency of both parties.

On my machine, C ++ and C # (both release versions) Start With (0, 0) the starting point is to search for the execution time of the 100000 server guard parade routes (the traversal routes of the 1530348 horses), which are roughly 273.764 S and 819.778 s, respectively. The ratio is about. This ratio may not affect commercial software too much, but if it is a game, you should consider it carefully.

Click here to download the source code (vs2005 project file. The C ++ Project is a Win32 console project, and the C # project is based on. NET 2.0)

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.