3

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.

ABCD
  • 22,419
  • 2
  • 43
  • 82
Shadow_Sphynx
  • 33
  • 1
  • 4

1 Answers1

9

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:

Basically, what you need to do is:

  1. 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:

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

  3. 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.

ABCD
  • 22,419
  • 2
  • 43
  • 82