How to Use Stockfish CLI to Master Chess on Your PC

Spread the love

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.

Content

What Is Stockfish?

Stockfish is more of a chess engine than an AI, and is among the strongest ones in the world. 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

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, 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 or Linux Terminal 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, an early computerized chess engine. Image source:
Wikimedia Commons

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.

How to Download Stockfish

  1. Download Stockfish 15.1 from the official Stockfish website. On Linux, you can use sudo apt install stockfish instead. Be sure to update apt 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.

  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.

  1. If you’re on Linux, run the terminal and enter stockfish.

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

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.

  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.

  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.

  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.

  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.

  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.

  1. Keep going until Stockfish (most likely) beats you.

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

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?

Stockfish is open source. You can find the source code at the Official Stockfish Github Repository.

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.

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

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Sign up for all newsletters.
By signing up, you agree to our Privacy Policy and European users agree to the data transfer policy. We will not share your data and you can unsubscribe at any time. Subscribe


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.

Comments are closed