I'm building a chess engine and trying to figure out how good are the moves generated. Can you tell what is the best move for white in following position and why? Thanks.
[fen "r1b1kbnr/2p2ppp/p1p5/3pP1q1/8/2N1P3/PPP2PPP/R1BQK1NR w KQkq - 0 1"]
Chess Stack Exchange is a question and answer site for serious players and enthusiasts of chess. It only takes a minute to sign up.Sign up to join this community
This is kind of similar to the line (with colors reversed) 1. e4 e6 2. d4 d5 3. Nc3 Bb4 4. a3 Bxc3+ 5. bxc3 dxe4 6. Qg4
It's basically an identical position with colors reversed except white's knight is already on c3 which is actually a really good square for the knight. In fact I believe the main line of the line listed above is 6.. Nf6 7. Qg7 Rg8 8. Qh6 Rg6 9. (Queen somewhere) Nc6 with idea of playing e5.
[fen ""] 1.e4 e6 2.d4 d5 3.Nc3 Bb4 4.a3 Bxc3+ 5.bxc3 dxe4 6.Qg4 Nf6 7.Qxg7 Rg8 8.Qh6 Rg6 9.Qd2 Nc6
Based on this I think the plan 1. Nf3 Qxg2 2. Rg1 Qh3 3. Rg3 Qd7 4. e4 looks strong.
[fen "r1b1kbnr/2p2ppp/p1p5/3pP1q1/8/2N1P3/PPP2PPP/R1BQK1NR w KQkq - 0 1"] 1.Nf3 Qxg2 2.Rg1 Qh3 3.Rg3 Qd7 4.e4
I will try to give you a simple mathematical answer. It is clearly oversimplified, but might be a way to think that helps you program your engine.
Assuming that your chess engine can calculate simple forced moves and the value of pawns it should find that White now must choose between defending the e5 pawn or the g2 pawn. What if we could simply count the number of squares attacked (including squares occupied by other pawns or pieces, even your own)?
Defending the e5 pawn: One variation is 1. Nf3 Qxg2 2.Rg1 Qh3. Black attacks 54 squares, while White attacks 54 squares.
Defending the g2 pawn: 1. Qf3 Qxe5. Black attacks 57 squares, while White attacks 50 squares.
Defending the e5 pawn puts White on as many attacked squares as White, while when defending the g2 pawn White is 7 squares down.
Of course, in the variation defending the e5 pawn playing 3. e4 is strong for White as it opens up for the bishop on c1. Just count the number of squares.
I repeat, this is very simplified, but in general the more active you are (the more squares your pawns and pieces attack), the better off you are all other things being equal. This is one way used by programmers to give a mathematical value to how active a position is.
(I might have counted a wrong, but not by much - it shows the general idea)