Checkers Algorithm Strategy

Source: Internet
Author: User

chess piece beating algorithm
The algorithm is implemented in the Chessboard.canjumpto function.

? Find a piece of all the available positions, and build a data structure "diagram" form
This algorithm is somewhat like the breadth-first traversal algorithm of graphs. The text is described as follows:
1. Add the current piece coordinates to the "diagram".
2. From the position of the current pawn, from six directions to find the position of the pieces can jump,
3. If the 2nd step finds that the coordinates are not added to the "diagram", add these coordinates to the "diagram".
4. Proceed to step 2nd from step 3rd, just add the coordinates in "diagram". Until the coordinates have been added to the graph.
? Shortest Path Search
When the user specifies the chess position, it also calculates the shortest path from the current position to the target position, preparing for the game's playing pieces to move around the animation. This algorithm is still a bit like the breadth-first traversal algorithm of graphs, the text is described as follows:
1. Set the "weight" of all coordinates to-1
2. Set the "weight" of the current piece coordinate to 0.
3. Starting from the position of the current pawn, find the position where the pieces can be jumped.
3. If the 3rd step finds that the coordinates do not have a "weight" of-1, the "weights" of these coordinates are added 1 on the basis of the previous coordinate.
4. Proceed to step 2nd from the 4th step, just set the "weight" coordinate. Until all coordinates are set to "weights".
5. Starting from the target position, start looking backwards, and each time you look for a value that is 1 smaller than the current position. Always find the starting position. This will find the shortest path.
These are the basic knowledge of data structure, a little abstract, as long as the understanding and imagination there is no problem. Oh, the last "peace" exam has a topic: what is the previous sequence of Li, what is the post-order, I really can't remember. Knowledge of the data structure can be used to understand, test but can not score, injustice Ah.

5. Computer Chess strategy

This is the most difficult part of the design, the way people and computer thinking is completely different, how to put people's chess ideas to represent the computer computing data structure, this is more difficult, or AI so many years have no breakthrough progress?
? Two calculation method of distance between coordinates

The computer chess strategy mainly has the following aspects:

    • Figure out all the possible methods of your own.
    • Pick a piece and walk the farthest (as soon as possible to win).
    • Choose a piece and walk that is most likely to hinder the other person's way forward.
    • Choose the pieces and walk that offer the most favourable conditions for the next step, as far as possible
    • To make a comprehensive analysis of the above, and get a better approach.

Checkers Algorithm Strategy

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.