Connecting Chess Engine with a Java program I wanted to make a 1 player chess game.

The idea is:


The move made by the player would be displayed on the GUI.
It is sent to the Chess Engine in its own specific understood form.
Then the result of the Chess engine would be taken and then made visible on the GUI.


Currently I have made no progress on it and am on a dead end. My current program on Java lets 2 players play with each other. The program manages the rules that have to be followed and which moves are illegal. But for a single player game I wanted an AI for my game that can take inputs and give outputs. I searched online for various open source chess engines like Stockfish. But found nothing about using it in my program.

I tried to work on to create my own engine but it was quite a challenge for me. Hence connecting it with an external AI is the only solution I think there is.
Let's break it down:


You have a working Java chess board that you can use to move pieces
You want a chess engine (engine is a more precise term than AI)
You want to download Stockfish and use it
You want to invent a new protocol or technology to communicate your chess board with the Stockfish engine


To me, your question is really:


How to connect an external chess engine such as Stockfish within my own chess GUI in Java?


Useful old posts in this site:


Chess Engine API
What is the optimal way to use Stockfish programmatically?


Basically, what you need to do is:


You shouldn't invent your own technology, you should study the UCI protocol. http://wbec-ridderkerk.nl/html/UCIProtocol.html is a useful reference. I can get you started, do this:


Download Stockfish
Open Stockfish in a console/terminal, don't double-click on it with your mouse
Type ucinewgame and then go movetime 1000. Do you see Stockfish's move?
Read the protocol specification and learn how to analyze a position, and the output format.

Write a UCI output parser. Parse whatever information you want.
Use the information to make a move on your chess board.


The only technical difficulty I can see here is to establish a "connection" between your GUI with the engine. This is done by creating a new process, running the engine.


  https://stackoverflow.com/questions/2006035/how-to-create-a-process-in-java has information on how to do it.


Once you have the new process, you can establish a simple standard input/output pipeline. https://stackoverflow.com/questions/27081918/java-how-to-send-a-value-to-child-process-using-outputstream has the details. Ask on Stackoverflow if you're not sure.