Android real-world projects with source code

Source: Internet
Author: User

Wuziqi game wuzilianzhuAlgorithmImplementation

 

 

1. Game Rules

 Wuziqi is a competitive activity between two people. The rules and rules of the black and white sides are the same,The direction of the Five-connected sub-lines is horizontal, vertical, and oblique. If either party is black or white, the first line of the Five-connected sub-lines will win.

 

 

 

2.Five sub-beaded Algorithms

In the 9x9 game board (the actual chessboard can be any size here), we can think of it as a two-dimensional array, and fill in the value 1 of the array of the current vertex in the black box, after the pawns in the white square are filled with the value 2 in the array of the points, the point without the pawn is 0 in the number group, and the black and white sides are actually assigning values to the two-dimensional array each step. Therefore, based on the value of the two-dimensional array, we can calculate the five sub-keys, or draw the black and white pawns on the chess board.

 

After the player clicks on the screen, he gets the x y coordinate of the screen and divides it by the width and height of each grid on the board. Then he can get the index in the two-dimensional array. Based on the x y indexes, he can know that the pawn is under it. in this two-dimensional array.

 

 

Now I will take you to analyze the five sub-beaded algorithms. First of all, there must be eight possibilities for connecting the five pieces to the first line. Next we will analyze the eight possibilities.

 

 

 

First: The X-axis is horizontal, where four chess pieces have been connected to either side of the first line, and either side of the next chess piece will be five pieces. You can use a for loop to traverse the current X-point index.,The starting point is X-4 and the ending point is x + 4, which facilitates a total of nine times. If five pieces are consecutively connected, the five sub-beads are connected; otherwise, the break can be directly connected if one of them is not connected;

 

 

 

Second: the X axis is horizontal, where several pawns on the left and right sides are not satisfied with the five sub-beads, but if the middle is connected to the next match

Therefore, when writing an algorithm, it is necessary to facilitate the indexing of the current pawn five times before and after the current index to determine whether the current pawn can be followed by a five-Child ball. Same as Algorithm

 

 

 

The third type is Y-4 to Y + 4.


 

 

Type 4: Y axis vertically likewise X axis

 

 

 

Category 5: traversal from (X-4) (Y-4) to (x + 4) (Y + 4)

 

 

 

Method 6: Same as Algorithm

 

 

 

7. traversal from (x + 4) (Y + 4) to (x-4) (Y + 4)

 

 

 

Method 8: Same as Algorithm

 

 

In this way, the algorithms of the five sub-links will be introduced. The following is an example of my source code. Currently, I am not interested in AI. We can study it together.

 

Source code:Http://download.csdn.net/source/3395573

 

Related Article

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.