wangzigeng2004 / VR_Chess_Stockfish

VR chess against stockfish engine

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

🐟Stockfish in VR


This project is a proof of concept for implementing a uci protocol chess engine in a virutal reality environment.

Unity Preview Screenshot with debugger output

Helpful Language

UCI [Universal Chess Interface] : Text based protocol used by engines to play chess games automatically. uci protocol

FEN [Forsyth–Edwards Notation] : A description of a board state as a string, using letters and numbers to define the pieces position and empty spaces. Following is an example of a string depicting the beginning state of a board as a FEN string. rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1

Stockfish is one of many UCI compatible chess engines. It was chosen for use here due to its availability and prestige in the world of chess engines.

This test is accomplished in Unity using the XR Interaction Toolkit and tested in a Quest 2.

Program Flow

  1. Read state of 3D chess board in Unity Engine
  2. Convert state to valid FEN string that can be passed to engine
  3. Run engine with given board state
  4. Take results from engine computation and effect corresponding asset (Chess Piece on Board).

TO ACCOMPLISH

  • Handle captures
  • Handle end of game

Big Learning Experience

So up until this point, most games and experiences I have created are small enough where optimization is simple and performance is not a huge concern. For this tool I had to dive in to mutlithreading. The stockfish "terminal" can not run on the main thread. My first attempts to do so resulted in a horrific lag or complete freeze in the VR headset and caused my first in headset bout with nausea. Digging into multithreading, per suggestion of a friend, we have remedies the solution. Now, when stockfish is called, a seperate thread process is created and runs stockfish as a windowless program. Once stockfish has a suggested move, the thread return the move and closes down.

About Me

Hi! I am a graduate of Holberton. I have finished the Full Stack Software Engineering program with a specialization in Augmented and Virtual Reality Development. I enjoy creating behind the scenes tools for VR experiences. Feel free to click around. Please contact me with any thoughts, suggestions, or job opportunities!

🐦 twitter 💼 linkedin

About

VR chess against stockfish engine


Languages

Language:ShaderLab 77.3%Language:HLSL 13.4%Language:C# 9.2%