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)