42 votes
Accepted

What is the worst opening move in Chess960 for White?

This calls for some scripting, so here's my first hasty attempt at it ;) Here's a quick way you can do the search on your own in python, using stockfish 10 and only the python-chess package. All open-...
user avatar
  • 11.8k
38 votes

Why don’t chess engines use Node.js?

Here is a link comparing C++ to Node.js from this question on Stack Overflow. To answer your question: C++, while more difficult to write, is way faster than basically anything else.
user avatar
34 votes

Why don’t chess engines use Node.js?

Node.js isn't a language; it's a framework on top of JavaScript. It's also not fast, certainly not compared to compiled languages like C++ or Java. Nor is JavaScript easier to use than compiled ...
user avatar
  • 441
32 votes
Accepted

What if both players always play the worst engine move?

You may find this game interesting: https://lichess.org/A9ZRnDcE. Here Stockfish (black) is programmed to select the move leading to the most negative eval position. White is a human who is aiming to ...
user avatar
  • 2,169
31 votes
Accepted

What prevents chess engines from being undetectable?

Engines have no concept of natural moves and they have no fear. An engine will play for the most advantage, not for the most manageable advantage, even if it allows a fierce attack, because it sees ...
user avatar
  • 3,450
30 votes
Accepted

Given a legal chess position, is there an algorithm that generates a series of moves that lead to it?

The task you are considered is usually called a proof game, named such because the task is to prove that the position is legal. As a genre of puzzles, there are various aesthetic constraints, most ...
user avatar
  • 596
27 votes

Why don’t chess engines use Node.js?

To add onto the comments: Node.js and Python are higher-level languages/frameworks, used as "glue languages" for machine learning frameworks that just serve as human-friendly wrappers to ...
user avatar
  • 1,097
26 votes

Creating chess engine, machine learning vs. traditional engine?

If you're trying to make the strongest engine possible, absolutely go for NN engines. Traditional engines are great - Stockfish is arguably still the strongest engine on the planet on consensus equal ...
user avatar
  • 21.7k
24 votes
Accepted

How does Stockfish know if the king is in check?

If you're curious about the Stockfish code, it can be found here: si->checkersBB = attackers_to(square<KING>(sideToMove)) & pieces(~sideToMove); We call the attackers_to method to ...
user avatar
23 votes
Accepted

Do chess programmes keep a history of the full board for each move?

You are doing a chess GUI, not a chess engine right? Chess GUI doesn't need to be super efficient, because you have no more than a chess game to look for. Even a game over 200 moves about the world ...
user avatar
  • 21.4k
20 votes
Accepted

How do chess engines decide which best line to play when the game outcome is within their horizon?

If the engine can choose between getting mated in 2 or mated in 3, it'll choose the line where it is mated in 3 (even though the mate in 2 might be 'more difficult' to spot for humans). It can't ...
user avatar
  • 23.9k
19 votes

What is the worst opening move in Chess960 for White?

Using @Phonon's Python script, I was able to determine that the worst move is 1. g4?? from the BBQRNNKR starting configuration, or 1. b4?? from its mirror image. This evaluates to -2.5 in one second ...
user avatar
  • 1,659
18 votes

How does Stockfish know if the king is in check?

Where and how in Stockfish's code is check detected? This is simple engine programming. You will need to build a bitboard of the attacking squares and two bitboards of your king, one for each color. ...
user avatar
  • 21.4k
16 votes

What prevents chess engines from being undetectable?

One very obvious indication for people using engines is, that they need roughly the same time for every move (usually about 5s in blitz games), even for the most obvious ones, which could be premoved. ...
user avatar
  • 1,144
15 votes

How does Stockfish know if the king is in check?

Your question has nothing to do with Stockfish. Though it may be interesting to check the original source code. This is purely algorithmic. One dumb solution would be implementing a boolean function (...
user avatar
  • 159
14 votes
Accepted

Alternative approaches to chess engine programming

In the beginning years of computer chess, people have actually tried to teach computers chess in the same way as they do with humans, explaining strategic concepts like a healthy pawn structure or the ...
user avatar
  • 23.9k
13 votes
Accepted

Programming three-fold repetition for my chess engine

Threefold-repetition is about a position (not moves) occurring three times. Those positions do not have to be reached by the same moves. Also (as this also seems to be confused sometimes) it is ...
user avatar
  • 20.4k
13 votes

Is it normal for a chess engine to blunder material if its evaluation is only based on naive material evaluation?

This exact bot has already been created. On lichess, it is simpleEval. You could potentially use it to debug a lot of your issues by seeing what this engine does against you in a given position. ...
user avatar
  • 5,070
13 votes

Which methods can be used to prove that a position is illegal?

Easy illegality is easy: not exactly 1 king on both sides, both kings in check, pawns on the final ranks. It's also fairly easy to tally promoted material and subtract the missing pawns. A quick ...
user avatar
12 votes

How do I check if a move is legal using Stockfish?

Stockfish assumes that all FEN positions you feed it are legal positions. If you feed it an illegal position and ask it to evaluate it, it will likely crash: Stockfish 5 64 by Tord Romstad, Marco ...
user avatar
  • 1,857
12 votes
Accepted

Working with UCI protocol (coding)

Let's use Stockfish to find out the moves for this position [fen "N7/P3pk1p/3p2p1/r4p2/8/4b2B/4P1KP/1R6 w - - 0 34"] The FEN string is: "N7/P3pk1p/3p2p1/r4p2/8/4b2B/4P1KP/1R6 w - - 0 34". You should ...
user avatar
  • 21.4k
12 votes
Accepted

Checkless Chess

Your "checkless" chess AI would run into problems with the stalemate rule. It would consider the poaition with white king on a6, white pawn a7, black king a8, a win for White because wherever Black ...
user avatar
  • 3,236
12 votes
Accepted

How do chess engines evaluate a position if the position is in the middle of an exchange?

A good chess engine won't stop after a predetermined number of moves, but will keep looking until the position is "quiescent", which roughly speaking means that there are no pending captures or checks....
user avatar
  • 10.2k
12 votes

What prevents chess engines from being undetectable?

Some of those things are possible in theory. Especially if you have a good idea what an engine-detector is looking for, you could maybe do some machine-learning training of algorithm against ...
user avatar
11 votes
Accepted

Which interface protocol should I implement for my chess engine?

There're only two protocols - UCI and Winboard. Winboard is an old protocol and not really being used nowadays. Crafty is the only major engine still supporting the Winboard protocol, but it's only ...
user avatar
  • 21.4k
11 votes
Accepted

How can I know the Elo rating of my chess engine?

Easy question. Announce your engine on the chess programming forum (http://talkchess.com/forum/index.php). There'll be engine testers adding your engine to their rating list, such as CCRL. But please ...
user avatar
  • 21.4k
11 votes
Accepted

Stockfish evaluation of a position from PGN

Yes there are easy ways to do this. I'm going to briefly show you one quick way of doing it in python, using the python-chess module. If the in-code comments are not enough, feel free to ask for ...
user avatar
  • 11.8k
11 votes
Accepted

Creating chess engine, machine learning vs. traditional engine?

First step: Define your goals/reasons I think this is the predominant factor. Which of these best fits you? (Choose only one) You want to enjoy a fun, challenging coding task You want to create an ...
user avatar
  • 286
11 votes

Why don’t chess engines use Node.js?

Node.js is just a JavaScript (JS) runtime environment that is basically just Chrome's V8 JS engine, with the APIs (set of standardized commands for interacting with something) only needed for a ...
user avatar
  • 229
10 votes

Is the dead position problem solvable?

Computer detection of dead positions is much trickier than people think. It is unlikely that an algorithm exists that runs in reasonable time and is 100% accurate. It is easy to check for a simple ...
user avatar
  • 4,850

Only top scored, non community-wiki answers of a minimum length are eligible