The knight and bishop checkmate. Checkmate with knight and bishop - online chess training

  • Tutorial

Want to puzzle a novice chess player?
Ask him to checkmate with his knight and bishop.

Want to puzzle a novice programmer?
Ask him to calculate checkmate with a knight and bishop.

Chess problems excite the programmer's imagination,
that is why for a practical demonstration of combinatorics
I chose the most difficult chess problem from the “checkmate to the lonely king” series.

Setting a goal

The goal of the project is to create a solution base, that is, a list of correct moves for all possible locations of the white king, bishop, knight and black king on the chessboard.

In this publication I will tell you how I solved this problem, what difficulties I encountered, and also demonstrate what happened in the end. Technologies used: C#, JavaScript, PHP, HTML, CSS.

Being a very mediocre chess player, I never learned how to quickly checkmate with a knight and bishop. Therefore, I decided to compensate for this shortcoming with my programming skills, go through all possible positions and find the correct move for each.

Before writing a single line of code, I hatched a “Napoleonic” plan for several weeks on how I would do it. I really wanted to start solving this problem from the end, by going through all the mating combinations. And then make one move back at a time until all possible options are exhausted.

How many options are there?

There are 64 squares on a chessboard. We have four figures.
The number of possible combinations is 64 * 64 * 64 * 64 = 16,777,216.

You can only leave the light-squared bishop.
The number of options will be halved: 64 * 32 * 64 * 64 = 8,388,608.
This is exactly how many positions will be in our solution database.

In fact, there are even fewer combinations: two pieces cannot stand on one cell, kings cannot stand on adjacent cells, the black king cannot be in check, and so on. Looking ahead, I will say that there were 5,609,790 combinations in the solution database, the array will be 67% full.

However, to simplify the algorithm and speed up access to database data, I decided not to waste time on trifles and create a four-dimensional array for all combinations.

The following structure is defined to store each combination:

Struct Combo ( public Coord whiteKing; public Coord whiteBishop; public Coord whiteKnight; public Coord blackKing; )
Inside, another Coord structure is used to record the coordinates of the figure, with the ability to calculate the index from 0 to 63, as well as with an overloaded comparison operator.

Public struct Coord ( public byte x; // checkerboard vertical from 0 to 7 (from a to h) public byte y; // checkerboard horizontal from 0 to 7 public int index ( get ( return x + y * 8; ) set ( x = (byte) (value % 8); y = (byte) (value / 8); public static bool operator == (Coord a, Coord b) ( return a.x == b.x && a.y == b.y; ) )
This structure has proven to be very convenient for passing as an argument to various helper functions, for example:

Bool isCheck(Combo combo); // Checking the position for check bool isCheckmate (Combo combo); // checkmate bool isCheckByBishop (Combo combo); // is there a check from the bishop
However, this structure is not enough to record the result of the solution base; we also need...

White box

The goal of our program will be to create a “white box” in which all positions in which it is “White’s move” will be added up, and for which it is known exactly what move needs to be made, and after how many moves checkmate will be guaranteed.

An integral part of the “white box” is the following structure:

Struct WhitesMove ( public Combo combo; public byte moves; // how many moves to checkmate public Coord moveFrom; // correct move - from where public Coord moveTo; // where )
The easiest way to organize a white box is to open a four-dimensional matrix. Each dimension of this matrix corresponds to a possible position of each shape:

WhitesMove [ , ] box = new WhitesMove ;
the first dimension is the coordinate of the white king.
the second dimension is the coordinate of the white elephant / 2.
the third dimension is the coordinate of the white horse.
the fourth dimension is the coordinate of the black king.

The main thing is not to confuse their order :) The array will be 33% discharged, but very convenient for processing. It is in this array that 8,388,608 records will be stored for solving combinations.

By the way, before I started writing all the brute-force algorithms, I created an empty project and initialized this four-dimensional matrix to make sure that there was enough memory and that I wouldn’t have to invent anything additional. Apparently, the experience of participating in computer science Olympiads of the last millennium had an effect, where the size of the structure could not exceed 64 kilobytes, because Turbo Pascal 7.0.

Algorithm idea

I will briefly describe the main idea of ​​solving this problem. It is based on a breadth-first search algorithm, which had to be slightly modified, since two people play chess and moves are made one at a time. Therefore, instead of one queue, we will need two - “black” and “white”.

Queue blackQueue = new Queue (); Queue whiteQueue = new Queue ();
We have already become familiar with the WhitesMove structure. The structure of BlacksMove is a little simpler, since it does not need to store black's last move.

Struct BlacksMove ( public Combo combo; public byte moves; )
First, we will place in the “black queue” all mating positions in which black is to move. Then from each such position we will make a reverse move for White and form a “white queue” - a list of positions in which White can move.

These steps will need to be repeated until all possible combinations are completely exhausted.

The main algorithm in the form of pseudocode:

We clear the “white queue”, “black queue”, “white box” We look for all mating positions Add them to the “black queue” Repeat ( Until the “black queue” is empty Take a position from the “black queue” We go through all the reverse moves of White for it If no check for the black king If such a position is not in the “white box” Add a position to the “white box” Add a position to the “white queue” While the “white queue” is not empty Take a position from the “white queue” We go through all possible reverse moves of the black king for it If from this position any move leads to a known position from the “white box” Add the position to the “black queue”) While the “black queue” is not empty The “white box” contains a database of solutions

Matt positions

Creating a database of correct moves begins with finding all mating combinations. The use of enumerators made it possible to describe this process quite effectively.

Foreach (Combo combo in AllCheckmates()) ( BlacksMove checkmate = new BlacksMove ( combo = combo, moves = 0 ); blackQueue.Enqueue(checkmate); )
A total of 232 mating positions were found. Let me remind you that we limited ourselves to only the light-squared bishop.

Some of them are quite exotic, non-existent and “cooperative”, this is when the black king himself went under the checkmate.

Chess players are well aware that checkmate with a knight and light-squared bishop must be placed in the white corner. In the black corner, checkmate is only possible if black plays along. I specifically placed a photo with just such a pseudo-mat at the beginning of the article in order to provoke the attention of real chess players :)

Checkmate in one move

The next stage is to make a reverse move for White. That is, for each mating position found, do all possible reverse moves for White.

How to reverse? Considering that captures are not provided for in our positions, the algorithm is quite simple - make any white move, after which there will be no check for the black king.

All positions found in this way can already be put into a “white box”, indicating that there is one move to checkmate, and what kind of move needs to be made for this. At the same time, we place the found combinations in the “black queue”.

// While the “black queue” is not empty while (blackQueue.Count > 0) ( // Take a position from the “black queue” BlacksMove black = blackQueue.Dequeue(); // We go through all the reverse moves of white for it foreach (WhitesMove white in AllWhiteBackMoves(black)) // If there is no check to the black king if (!isCheck(white.combo)) // If such a position is not in the “white box” if (!whiteBox.Exists(white.combo)) ( // Add a position to the “white box” whiteBox.Put (white); // Add a position to the “white queue” whiteQueue.Enqueue(white) )

By the way, about yield

The use of enumerators with a yield mechanism allows you to very beautifully implement various searches, for example, this is what the function of searching through all possible moves with white pieces looks like:

IEnumerable AllWhiteBackMoves(BlacksMove black) ( foreach (WhitesMove white in AllWhiteKingMoves(black)) yield return white; foreach (WhitesMove white in AllWhiteBishopMoves(black)) yield return white; foreach (WhitesMove white in AllWhiteKnightMoves(black)) yield return white; )


A total of 920 such positions were found, here are the most interesting ones:

Knight's move:

Bishop move:

King move:

Checkmate in one and a half moves

The next stage is to make a reverse move for black. I fiddled with this algorithm the longest; many mistakes were made before everything worked correctly.

At first glance, everything is similar to the previous option: for each position from the “white queue” it is necessary to go through all possible moves of the black king. And add all the combinations found to the “black queue” - after all, this is checkmate in one and a half moves, from which you can then make a reverse move for White again - there will be checkmate in two moves - and so continue until all options are reviewed.

This was the mistake. With any possible move by Black, a “cooperative” checkmate is obtained in one and a half moves, but in fact the king will not necessarily go under checkmate. This error was pointed out to me by Dmitry Grin, who attended all my webinars on the creation of this program, for which special thanks to him.

The correct algorithm is as follows: for each position N after the reverse move of the black king, you need to go through all its possible forward moves to make sure that they all lead to familiar positions from the “white box”, that is, they lead to checkmate. And only after this position N can be added to the “black queue”. And if the black king can “sneak away” from position N, then we skip this option. It will occur in subsequent iterations, when there will be more familiar positions.

This is what this part of the algorithm looks like:

// While the "white queue" is not empty while (whiteQueue.Count > 0) ( // Take position N from the "white queue" WhitesMove white = whiteQueue.Dequeue(); Combo whiteFigures = white.combo; // Iterate through everything for N possible reverse moves of the black king foreach (BlacksMove black in AllBlackBackMoves(white)) ( bool solved = true; // We go through all possible moves of the black king foreach (Coord blackKing in AllKingMoves(black.combo.blackKing)) ( whiteFigures.blackKing = blackKing; // rearrange the black king if (isCheck(whiteFigures)) // do not go into check continue; if (box.Exists(whiteFigures)) // skip the solved positions continue; solved = false; // the black king was able to “sneak away” break; ) // If any move from this position leads // to a known position from the “white box” if (solved) // Add the position to the “black queue” blackQueue.Enqueue(black) )
A total of 156 combinations of “Checkmate in one and a half moves” were found.

Iterativeness of half moves

The described algorithms for creating half-moves must be looped. From the “black queue” we form a “white queue”, and then vice versa - from the “white” we form a “black”. And so on until all new positions are exhausted. The “White Box” is filled at the stage of forming the “White Queue”, since positions in which White is to move are placed in it.

The ready-made algorithm for searching through all the options worked in about 12 minutes and stopped at move 33. This is exactly the maximum number of moves needed to mate the black king with a knight and bishop from any position.

By the way, there were not many such “most difficult” positions, only 156, here is one of them:

There will be no mat!

There are many positions in which, even after White moves, the black king can eat a knight or bishop and end up in a draw. There are also stalemate options. Here are some of the most interesting positions.

How to store a solution database

How to store the found solution database?
The simplest and incorrect way is to use serialization. The serialized four-dimensional structure array took up 1.7 gigabytes (!) on disk. The serialization process lasted about six minutes, and deserialization took about the same.

This option, of course, is not suitable. Moreover, in practice there is no need to use the entire four-dimensional array. Only one entry is needed for a specific item.

Eureka! To save space, you can also get rid of storing the coordinates of the figures for each combination. When we have a four-dimensional array, the position of each piece on the board is uniquely determined by its index in the array.

It was decided to store the entire solution database in one file - as a linear scan of a four-dimensional array. For any possible position, the address at which the correct answer is written is calculated.

How can we write down the answer we need as compactly as possible? There is no need to store the position of the pieces, so only three numbers remain - how many moves to checkmate, what to move and where to move. This is how the correct move for White is clearly determined.

6 bit. How many moves to checkmate is an integer from 0 to 33.
2 bits. Which piece moves - three possible options, king, bishop or knight.
6 bit. Where the piece moves is the index of the field on the board from 0 to 63.

This means that two bytes are enough for each solution record:
1 byte - how many moves to checkmate, or 0 if the position is unfamiliar.
2 bytes - FFNNNNNN
FF - number of the piece that needs to be moved (1 - king, 2 - bishop, 3 - knight)
NNNNNN - cell coordinate - where to go (from 0 to 63).

So, the solution database file takes 64 * 32 * 64 * 64 words = exactly 16 megabytes. The placement of the pieces is determined by the coordinates of each word, the first byte contains the number of moves to checkmate (or 0 if there is no solution), the second byte stores the correct move.

It would be possible to reduce the file size by half if we did not store the number of moves until checkmate, but it would not be interesting to play like that.

Coordinates of the black-squared white bishop

It's time to pay for optimization. It is necessary to implement an algorithm for recalculating coordinates for combinations with a “black and white” bishop.

This was done as follows. If the coordinate of the bishop falls on a black square, then it is necessary to “flip” the coordinates of all the pieces on the board. In this case, the Y coordinate remains unchanged, and X changes to 7-X. For a visual demonstration of coordinate reversal, see the figure.

If the bishop stands on a white square, then first you need to “flip” the coordinates of all the pieces. Then look for a position in the solution database. And once again “turn over” the coordinate of the correct move read from there.

Visualization of the solution base

So, the problem is solved!
The solution base has been created.
But how to demonstrate it?

The most obvious way is to use web technologies so that you can simply provide a link to a working example. A photo course has already been created using my “programmer formula”

Is it possible to checkmate with a king and a bishop?

"It is forbidden!" - you will say with confidence. And you will be right if you make the right reservation.

"Can!" And here you are right under certain conditions.

Let's look at these simple nuances.

When is it impossible to checkmate?

It's very simple. In the absence of other pieces except kings and bishops, it is impossible to checkmate. A mating position cannot occur on the board even with the best wishes of both sides.

They simply do not exist in the nature of chess. Just arrange the pieces and try.

When is it possible to checkmate?

The first and main condition:

1. The presence of at least one piece in the opponent’s camp, except for the king

For example:

Please note that this position can only be obtained through the joint efforts of both parties)

Hence the second condition:

2. Erroneous play by the opponent

White plays 1.Bh3, attacking the horse.

1...Nf4??

The phrase “The best defense is attack” does not apply to this case)

2. Bd7X

And one more condition:

3. Poor arrangement of figures

For example:

The position of mutual zugzwang is already familiar to us. Despite the huge material advantage, Black drove his king so unsuccessfully that with his move he gets mate with a bishop or pawn in all variations.

For example 1...Qf2 2.Be5! Qe1 (2...g4 3.Cf6X) 3.g3+ Q:g3 4.C:g3X

Endgame paradoxes

Let's compare the two positions:

Here White has an extra piece and a pawn. It would seem quite enough for victory.

However, there are nuances. More precisely a nuance. It is impossible to queen a pawn. The black king has locked himself in a corner and it is not possible to smoke him out. He simply moves from h8 to g7 and back. There is also no checkmate, only a stalemate. Draw

And in the next position the pawn is black and advanced almost to the promotion square, but black may end up in a mating position.


In positions like these, the color of the corner box is key. . If this square is the color of the bishop, checkmate is also possible, as in the previous example, or simply pushing the king out of the corner.

What is the result if time is overdue?

In conclusion, there are a number of points that are of practical importance and related to time.

  • In the position of king and bishop against the king without other pieces, a draw will be immediately recorded. Even if someone is overdue. Because checkmate is impossible.
  • But in the position of White’s king and bishop against Black’s king and pawn, if White runs out of time, they will be counted defeated in all cases. Because theoretically a pawn can be promoted to queen.
  • If, in the same situation, Black ran out of time, a draw is recorded in all cases, except for the position in which the extreme pawn and the corner square are the color of the bishop. Checkmate is theoretically possible here, as in the diagram above.

In a practical game, it is important to keep these nuances in mind so as not to lose points literally out of the blue.

Thank you for your interest in the article.

If you found it useful, please do the following:

  1. Share with your friends by clicking on the social media buttons.
  2. Write a comment (at the bottom of the page)
  3. Subscribe to blog updates (form under the social media buttons) and receive articles to your email.

We have repeatedly emphasized the importance of coordinated play of pieces when mateing a lone king. This principle of interaction of forces, expressed in the fact that each piece with its activity on the chessboard complements the activities of other pieces, acquires even greater significance when checkmate with a bishop and a knight. In general, checkmating a lone king is a good school for learning the basics of how pieces interact.

The endgame we are considering here presents a certain difficulty not only for beginners, but also for breakers. There have been cases where even experienced chess players could not cope with mate with a bishop and a knight in 50 moves. In any case, to achieve checkmate with the most unfavorable arrangement of the pieces of the strongest side, as a rule, about 35 moves are needed, and this is quite close to the draw limit (50 moves). Therefore, the process of checkmate with a knight and bishop requires great precision.

The plan of action, as in the previously discussed endings, for the stronger side is to gradually limit the mobility of the enemy king, and for the weakest - to try to keep the king in the center of the board as long as possible.

In this endgame, checkmate can only be forced on six squares of the board: in one of the two corners accessible to the bishop, or on adjacent squares.

The diagrams above show typical final positions for mating with a bishop and a knight. We draw students' attention to two main conditions, without which achieving checkmate is impossible. This is, firstly, as with checkmate with two bishops, the king of the strongest side must necessarily be at the distance of the knight's move from the corner square. And, secondly, checkmate requires only one of the two corners accessible to the bishop.

In diagrams 1 and 2, white is at the very target: the enemy king is locked in the desired corner, and you just need to carefully carry out the final blows.

As you noticed, checkmate can only be placed in the corner of the color of your bishop. Now let's get acquainted with how the lone king is pushed into the desired corner. The method of pushing back that we will use was proposed about 200 years ago by the famous French chess player F. Philidor (1726-1795), and the method of teaching this ending was developed more than 50 years ago by the Polish master D. Przepyurka (1880-1940).

Position shown in the diagram above , will be a starting point for us. It is not difficult to remember, since all four pieces are located on the same straight line, and the knight is under attack at an angle that is safe for the black king (this circumstance should make it easier to remember which piece to place where, since the bishop cannot take control this is the corner field h8). The white king has approached the enemy king at the closest distance and occupies the most advantageous position (opposition!). Pay special attention to the interaction of the white pieces: each of them has its own role, and they all complement each other in the game.

White's task is to push the enemy king to the white corner (since the bishop is light-squared!), that is, to the a8 corner (it is also possible to h1 corner, but it is further than the a8 corner). The black king will try to break through to the center or to one of the safe corners - h8 or al (there he is not threatened with checkmate - check it yourself!).

In the future, the moves of the white king and the bishop do not require any special explanation: both figures strive to cut off the squares around the black king, along which he could break through in the direction he needs.

The knight's moves are less obvious: his route, reminiscent of the Latin letter W, is shown in diagram 4 . The knight should not make any other moves until the black king is driven into the a8 corner, otherwise the black king can slip free.

1. Bh7 (immediately cutting off the path of the enemy king to the corner he desires.) Ke8 2. Ne5 (The knight goes along its route. Key position, Black has two options, move the king to f8 or d8) Kd8 (the black king is trying to break into center on the left flank.) (2... Kf8 3. Nd7+ Ke8 4. Ke6 (Now it’s time to move the king) Kd8 5. Kd6 Ke8 6. Bg6+ Kd8 7. Bf7 Kc8 8. Nc5 (The knight moves strictly along plan) Kd8 9. Nb7+ Kc8 10. Kc6 Kb8 11. Kb6 Kc8 12. Be6+ Kb8 13. Bd7 Ka8 14. Nc5 (Finishing maneuver) Kb8 15. Na6+ Ka8 16. Bc6#) 3. Ke6 (White king pursues black colleague, not allowing him to move too far away.) Kc7 (It seems that Black managed to break through, however) 4. Nd7 $1 (The knight's route is the same Kc6 5. Bd3 { Обратите внимание на то, как взаимодействуют белые фигуры.} Kc7 6. Be4 Kd8 7. Kd6 Ke8 8. Bg6+ Kd8 {Это уже было} 9. Bf7 Kc8 10. Nc5 Kb8 11. Kc6 Ka7 12. Be6 Kb8 13. Kb6 Ka8 14. Bd7 Kb8 15. Na6+ Ka8 16. Bc6# 1-0!}

We invite you to make sure that the other moves of the black king do not change the essence of the matter. You just need to remember that the pieces of the strongest side must, by concerted actions, build a barrier in the way of the non-enemy king and drive it into the bishop-colored corner. Moreover, the horse moves along a strictly planned route. Of course, during the game positions may arise with pieces located in less convenient positions. Then, through maneuvering, it is necessary to reach a situation familiar to us in order to complete the game according to a known pattern.

How to push a centralized king to the edge of the board

When a lone king is in the center of the board, the strongest side first of all tries to dislodge him from there. This is achieved through the centralization of power, which a lone king cannot prevent. He is able to hold out in the central part of the board for only about ten moves.

Have you already learned how to checkmate with two rooks? Knowing how to use your rooks is one of the most important skills for a beginner chess player! Use them alternately to "push" your opponent's king to the edge of the board and finish the training.

If you learn to checkmate with your queen, you can win games with just one extra pawn! This lesson will show you that even the queen, the most powerful piece, cannot checkmate alone. The king must help him. Try to master the simplest matting method yourself!

In serious games you will have to prove that you can deliver this checkmate much more often than any other! Checkmate with king and rook is much more difficult than checkmate with king and queen. Here you will have to use the king and rook together as an attacking force. You can only checkmate after you push your opponent's king to the edge of the board. Master the principles of rook checkmate and you'll be armed and dangerous in chess tournaments!

This endgame can be won if your pieces work together. Your bishops must drive the enemy king into the corner of the board, because only there can he get checkmate. It is most convenient to push back the enemy king with your own when the bishops stand side by side, blocking his escape route. Be careful, avoid an accidental stalemate!

This position requires practice to master it completely! Until you checkmate the computer with a bishop and knight at least five times, you won't be confident that you can do it on the board. The enemy king can only be checkmated in a corner of the board that is the color of your bishop. In this case, on the white squares h1 and a8. Push the king back to square a8; use the bishop to attack the white squares and the knight to attack the black squares.

WARNING: Before starting this exercise, try to solve the previous one. This is one of the most difficult endgames! As you learned in the last lesson, you can checkmate in the corner of the same color as your bishop. First, position your pieces correctly (all of them, including the king), then push the enemy king to the edge of the board. Then everything will be easier, because you already know how to finish the job.

In this endgame it all comes down to the king's activity. At least starting from the next move. The winning method is to exploit the bishop's weaknesses. Approach the enemy king on white squares, and black will not be able to threaten you. Don't forget to take advantage of profitable opportunities. When the king can no longer defend the bishop, look for forks!

Beware of forks! Wrestling a horse can be very difficult. Technically push enemy pieces back to places where they lack space. Then make the king and knight separate and win the knight. Remember: it is often better to make a wait-and-see move that limits your opponent's options than to give endless checks.

Checkmate with knight and bishop in chess- this is a very complex strategy; checkmate in such a game can be achieved after 35 moves. This brings to mind the 50-move rule. Since the permissible number of moves according to existing chess rules is 50, such a completion requires precise play.

To checkmate the king, the following conditions of this tactic must be met:

Initially, the king of the strongest side is moved to the edge of the board, at a distance for the knight to move on the corner square.

Checkmate is placed in the very corner of the field, on one of six fields: the color that matches the color of the bishop in these corners.

First, let's figure out how to place a checkmate in the corner. And so, the king is placed in the corner required for the condition, and is deprived of the opportunity to leave it. Let's pay attention to how the knight and bishop interact in the game. These two figures fully complement each other. The knight occupies black squares, the bishop occupies white squares. In this strategy, checkmate can be achieved in less than nine moves.

1.King a7
2. King d7 King b7
3. King d8 King b8
4. Bishop a6

After all this, the king is even more limited in his movements.
5. King a7 Bishop c8 King b8
6. Knight b4 King a7

7. King c7 King a8
8. Bishop b7+ King a7
9. Knight c6++

Since checkmate can only be achieved when the opponent's king is located in a corner corresponding to the color of the bishop, now we will consider the situation of how to move the king from corner to corner.
1 Knight f7+ King g4
2. Bishop f5 King f8
3. Bishop h7 King e8
4. Knight e5 King d8

Black chess wants to break into the a1 corner.
5. King e6 King c7
6. Knight d7 King b7
7. Bishop d3 King c6
8. Bishop a6 King c7
9. Bishop b5 King d8
10. Knight b6 King c7
11. Knight d5++.

The method of this game was invented by Philidor, a French chess player in 1777.

Interesting information on this technique: at the 47th chess championship in Minsk in 1979, the endgame “knight and bishop against the king” appeared between Balashov and Anikaev. Anikaev tested his opponent's mating technique in 20 moves. It turned out to be successful: with his actions, Balashov forced the king to move into the corner corresponding to the colors of the field along which the bishop was moving. And only after that Anikaev surrendered.

Share: