P
P
Programmir2021-03-25 09:23:40
Game development
Programmir, 2021-03-25 09:23:40

Where can I find the chess algorithm?

I'm making a game like chess. Where can I find a detailed algorithm? For example, how is a check made? That is, we calculate all the opponent's pieces, and if the king is on the trajectory of one of the pieces, then we give a check? And do we get a checkmate, such as a miscalculation that the king cannot retreat somewhere or the ally's piece cannot take the opponent's piece, which gives a check, or stand on the trajectory of the enemy piece, covering the king?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Siomin, 2021-03-25
@MaxSiominDev

You have to use stockfish

S
Sergey Pankov, 2021-03-25
@trapwalker

In the general case, such problems are solved by enumeration. To do this, a tree of possible states of the board is built starting from the current state. The children of the current state in this tree are the results of all possible moves of the next player. This is a highly branched tree, which means that in just a few moves the number of elements in it will become too large to sort through and evaluate them one by one. Here, there is no question of descending the tree to the final (leaf) states, by which you can unequivocally judge the win.
Obviously, the tree can be truncated and not considered obviously losing or too costly moves, it is possible to compare states with certain pre-calculated situations. The more of them in the database, the faster your algorithm will work.
In any case, computers have learned to play chess more or less efficiently only recently, and this requires very powerful computers, a large database, and non-trivial algorithms for recognizing typical patterns on the board.
You can’t just take and remake a ready-made good chess algorithm for yourself. Rather, it is possible, but difficult.
But to try to write something of your own is a good exercise for the brain.
Try to implement a class to describe the state of the board (includes the position of the pieces and the color of the move). Describe a class for a tree of such states. The tree node will contain the state of the board and links to possible states.
For a state, it is possible to give an approximate estimate of its winningness. In the simplest case, this is to weigh the pieces by strength and sum up the points. In a more complex one, this is understood as a battle by a piece or not, whether it is blocked, etc.
Just in case, I’ll say that I don’t know how to play chess, I only know the rules and can only play at an amateur level, so I can talk nonsense. I'm just telling you how I would approach the solution of the problem naively from scratch. With a serious solution to this problem, science has long crossed the threshold of complexity for the most talented beginner.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question