Use js to implement wuziqi with OO ideas

Source: Internet
Author: User

Under the address: http://files.cnblogs.com/helimin19/Gobang.rar

Let's talk about the real principle of wuziqi I think: determine whether there are five pieces in the same direction as the forward direction, backward direction, oblique direction, and reverse direction.

Now, we analyze the current principles with OO ideas:

Wuziqi is basically a game player. It is made up of a grid, so we get two maps: The game player and the game player grid.

First, let's analyze the basic unit elements and methods of wuziqi:

Adequacy:
1. The size of a single cell exists, so we can specify the allocation and height.
2. when a single cell is placed in a chess game, we can use top, bottom, left, right, topright, bottomright, bottomleft, and topleft for the single cell in eight directions.
3. We can use topnumber, rightnumber, bottomnumber, leftnumber, toprightnumber, bottomrightnumber, bottomleftnumber, and topleftnumber to represent the same number of pawns in eight directions.
4. whether a single cell contains pawns. We use player for representation. For example, if we use 1, it indicates that the cell contains white, 2 indicates that the cell contains sunspots, and 0 indicates that no pawns are stored.

5. When a single cell is placed in the chess game, we use rowindex and celindex to indicate the forward and backward indexes of the single cell in the chess game.

Event:

When we perform this operation in a single cell, we will add corresponding pawns to the single cell, and set the number of chess pieces in the same eight sides and the number of chess pieces in the corresponding eight-direction unit cell (this is related)

As far as the opponent of the game is very simple, there is no need to worry about it. It will be clear at the first glance on behalf of the game.

Finally, build a game partner

Attention should be paid to the anti-fraud games. The chess games we see are different from those controlled by the real players.

In fact, the current control game is the game we can play on (we play in the grid)

The chess scene we see: in order to make it look like a game on the grid, we have added a chess scene we can see, it shows that the effect is half a unit cell different from the actually controlled chess game.

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.