laitimes

C Language Project Practice: Chess Zero Basic Project! 200-line source code example

author:C language programming

This article mainly introduces the C language implementation - "Chess Project" for everyone, which is not the same as Chinese chess! The sample code in the article is introduced in great detail, with certain reference value, interested partners can refer to it!

C Language Project Practice: Chess Zero Basic Project! 200-line source code example

Chess, also known as Chess, is a two-player board game.

The board is square and consists of 64 black-and-white (dark and light) grids; the pieces are divided into 32 black and white (dark and light) sides, with 16 pieces on each side. Although Chinese calls it Chess or Chess, it actually originated in Asia and was later introduced to Europe by the Arabs and became a popular international chess game.

Chess is played against each other, with white and black on the other. The game is played by the white bearer first, and each step is taken, and the two sides round the popular chess until the end of the game. The general moves of the various pieces are as follows:

King (K): Horizontal, straight, and oblique can walk, but each time you are limited to one step. The king is not allowed to deliver food, that is, any grid controlled by the enemy cannot be entered by his own king. Otherwise, if you count the foul of "sending the king", you will be sentenced to defeat three times.

(1) Except when transposing, wang can walk to any adjacent grid that is not attacked by the opponent's pieces, and can only take one step.

(2) Transposition is a move carried out by the king and any of his own cars together and is still regarded as a step of the king.

Rear (Q): Horizontal, straight, oblique can be walked, the number of steps is not limited, but can not cross the child.

Car (R): horizontal and vertical can walk, the number of steps is not limited, can not go obliquely. Except for the translocation of the king car, it is not possible to cross the son.

Elephant (B): Can only walk obliquely. The number of cells is not limited, and it is not possible to cross the child. At the beginning of the game, there are two elephants on each side, one in the white square and one in the black square.

Horse (N): Each move moves first sideways or straight, and then obliquely out of the grid; or first obliquely one block, and finally go out horizontally or vertically (that is, take the word "day"). You can cross the line, and there is no restriction on "trampling horse legs" in Chinese chess.

Soldier (P): You can only walk straight forward, only one block at a time. But when taking the first step, you can walk one or two blocks. The soldier's method of eating sub-pieces is different from the direction of the chess, it is straight to eat obliquely, that is, if the soldier's oblique entry has the opponent's chess pieces in one block, it can be eaten and occupied by the grid.

Everyone must understand the rules of chess, because this is related to the logical part of the rules for you to implement this chess project!

Plugin: graphic library plugin easyX, involving image materials can be found on Baidu or can pay attention to the end of the article;

C Language Project Practice: Chess Zero Basic Project! 200-line source code example

Companion Tutorial: Chess Game Tutorial - Bilibili

Source code example:

Unfinished chess piece code, you can also think about it yourself first, every time you think is the process of your progress!

If there is any problem in the process of learning, and if there is anything you don't understand in this project, you can come to me to communicate, and I will help you!

Then today's sharing is here, the follow-up will update more wonderful projects, we must learn the C language C++ yo ~ ~

Write at the end: For small partners who are ready to learn C/C++ programming, if you want to better improve your programming core skills (internal skills), you may wish to start now!

Programming Learning Book Sharing:

C Language Project Practice: Chess Zero Basic Project! 200-line source code example

Programming Learning Video Sharing:

C Language Project Practice: Chess Zero Basic Project! 200-line source code example

Organize and share (source code learned over the years, project practical videos, project notes, basic introductory tutorials)

Welcome to change careers and learn programming partners, use more information to learn to grow faster than their own thinking!

For C/C++ interested, you can pay attention to the small editor in the background private message me: [programming exchange] let's learn together! You can pick up some C/C++ project learning videos! Keyword auto-reply has been set up, and it will be collected automatically!

Read on