How to Use Stockfish CLI to Master Chess on Your PC - Make Tech Easier

DOWNLOAD LINK GATHER AT THE END OF THIS CONTENT

If you’ve been playing chess for a while, you might have heard about Stockfish, the chess AI that eats chess grandmasters for breakfast, lunch, and the evening snacks after dinner. This guide shows how to make it work on your desktop computer!

Good to know: Are you a social gamer? Take a look through these online board games you can play with your friends[1].

What Is Stockfish?

Stockfish is more of a chess engine than an AI, and is among the strongest ones in the world[2]. With it, you can find the best moves from any position – as long as you give it time to process the ongoing game.

Arena Chess Running Stockfish As Black Arena Chess running Stockfish

It’s also among the most popular, partly because it’s free and open source. The only thing that seems on par with it is Dragon[3], but that one costs money to use. When you’re training for tournaments or trying to figure out the best move to all kinds of chess puzzles, Stockfish is going to be your best friend.

It’s good to remember that Stockfish is a command line program, so you will need the Windows Command Prompt[4] or Linux Terminal[5] to use it.

How Chess Engines Like Stockfish Work

Chess engines (or chess AI, if you will) are much closer to password crackers than you might think.

When a chess engine like Stockfish thinks, it actually brute forces through all the combinations of legal moves until it finds the one that leads to the closest route to a mate. That’s how they rate how strong (or weak) your move is – a move that leads to checkmate in four turns is better than another move that requires eight turns.

Deep Blue Chess Engine Deep Blue, an early computerized chess engine. Image source: Wikimedia Commons[6]

As there are too many moves for Stockfish to go through, it will literally require days until it sees everything from 18 turns to after 1e4. That’s why you have to tell it how long it should think. It keeps track of the best move it has found so far, then picks that move when it reaches the time limit.

Chess GUIs that use Stockfish and other chess engines also have a ponder feature. It makes the engine think of a move while you’re thinking of your next move. This makes for a seamless play – your opponent will immediately start its next move after you make yours.

Good to know: if you like playing AI games, check out AI Dungeon[7].

How to Download Stockfish

  1. Download Stockfish 15.1 from the official Stockfish website[8]. On Linux, you can use sudo apt install stockfish instead. Be sure to update apt[9] first to get the latest version.

Note: there are two versions: AVX2 and POPCNT. In most newer computers and laptops, AVX2 should work. Only use POPCNT if it doesn’t.

How to Use Stockfish CLI to Master Chess on Your PC - Make Tech Easier
  1. On Windows, you should get a ZIP file after clicking the download link. Extract the file and run the EXE file from the folder.
Windows Explorer Stockfish File For Windows Screenshot
  1. If you’re on Linux, run the terminal and enter stockfish.
Terminal Stockfish Command Stockfish Arrow Pointing

Tip: Want to improve your gaming performance on Linux? Try GameMode.[10]

Playing with Stockfish

  1. To play a game, you have to show Stockfish what the board looks like using the position command. This command uses two parameters: the notation you’re using and the current state of the board. Try typing position startpos move e2e4 to do the King’s Pawn Opening as white.

Note: be sure to have a notepad app ready and use it to paste your moves.

Terminal Stockfish Command Position Startpos Move E2e4
  1. After pressing Enter, you might notice that nothing seems to have happened. But don’t panic – Stockfish has the move saved in memory. You just have to type d to show what the board looks like now.
Terminal Stockfish Command D Shows A Virtual Chess Board
  1. Now we’re going to make Stockfish think. Type go movetime 1000 below the line that says “Checkers” to make it think for one second. The number is in milliseconds, and you can change that to make Stockfish stop thinking for a shorter or longer time.
Terminal Stockfish Command Go Movetime 1000
  1. Stockfish will show you a ton of output, but the important part is the last line. The result may vary depending on the computer, but you should get something like bestmove c7c5 ponder g1f3 in the end. This means that it currently thinks that c7c6 is the best reply to e2e4 and that it expects you to play g1f3 after that.
Terminal Stockfish Command Go Movetime 1000 Result Bestmove C7c5 Ponder G1f3
  1. It’s time to make Stockfish move. Add the bestmove’s value after the original startpos command, then paste the value. In this case, we’re going to type position startpos move e2e4 c7c6 in the terminal.
Terminal Stockfish Command Position Startpos Move E2e4 C7c6
  1. At this point, it’s your turn again, so you should add your next move after c7c6. You can enter d to see the board at anytime.
Terminal Stockfish Showing E2e4 C7c6 And Next Human Turn Will Be F2f4
  1. Keep going until Stockfish (most likely) beats you.
Terminal Stockfish Player Lost To Stockfish Cli

Tip: Linux gamers should read on to learn about the best Linux distros for gaming[11].

Frequently Asked Questions

What is a chess GUI?

A chess GUI is like a virtual chess board – it lets you play chess on it without having to play with a physical chess board. They work with a protocol standard called UCI (Universal Chess Interface) to talk with chess engines so you could play games against them. Some can also let you make engines play against each other, just to see which one would win.

What is Universal Chess Interface?

Universal Chess Interface (UCI) is a set of protocols that tell how a chess engine should provide its outputs and ask for inputs. This lets you pit computer chess engines against each other, and help with making these very engines compatible with almost any kind of chess GUI in existence.

Is Stockfish open source?

In what language is Stockfish coded in?

Stockfish is mainly coded in C++. If you want to beef up your programming talent, try these coding games[12].

Image credit: Unsplash[13]. All screencaps by Terenz Jomar Dela Cruz.

Terenz Jomar Dela Cruz
Terenz Jomar Dela Cruz

Terenz is a hobbyist roboticist trying to build the most awesome robot the world has ever seen. He could have done that already if he wasn't so busy burning through LEDs as a second hobby.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

References

  1. ^ online board games you can play with your friends (www.maketecheasier.com)
  2. ^ among the strongest ones in the world (computerchess.org.uk)
  3. ^ Dragon (komodochess.com)
  4. ^ Windows Command Prompt (www.maketecheasier.com)
  5. ^ Linux Terminal (www.maketecheasier.com)
  6. ^ Wikimedia Commons (en.wikipedia.org)
  7. ^ AI Dungeon (www.maketecheasier.com)
  8. ^ Stockfish website (stockfishchess.org)
  9. ^ apt (www.maketecheasier.com)
  10. ^ Try GameMode. (www.maketecheasier.com)
  11. ^ the best Linux distros for gaming (www.maketecheasier.com)
  12. ^ coding games (www.maketecheasier.com)
  13. ^ Unsplash (unsplash.com)

Total