Git Product home page Git Product logo

chess-shader-with-artificial-intelligence's Introduction

Chess Shader with AI

A simple AI implemented using the classic minimax algorithm except it's on a GPU.

Problems

  • No en croissant (too lazy to implement)
  • Castling during a check (too lazy to check)
  • Pawn promotions only works on pieces that are already captured (i.e. If the pawn reaches the end, your queens alive but the rooks dead, the pawn becomes a rook.) This is because there's no room left to store extra information based on how I implemented stuff
  • Depth of 2, this AI's big dumb in the late game
  • Bad board evaluation function, I just copied some numbers off a site (I fixed a big bug so it should work ok now)
  • Lots of wasted space, no dynamic memory allocation in shadurs

Setup for VRChat

Prerequisites

Avatars

  1. Import the ChessAi.unitypackage
  2. Put PrefabAvatarChessAI.prefab on your avatar
  3. Done. (Soft of)
  4. I suggest using FinalIK or Rigidbodies to plant the chess board in world space, and the Inventory System to enable/disable the game object

Worlds

  1. Import the ChessAi.unitypackage
  2. Put PrefabWorldChessAI.prefab in the world
  3. Done.
  4. The difference between the avatar version and this is this one uses an object synced sphere

Q & A

  1. What's the difference between the "New Game" and "Reset" buttons? The randomness helps the AI to pick moves that cost the same. "New Game" generates a new random seed so the AI doesn't pick the same sequence. "Reset" sets the randomness back to its initial state.

How It Works

Chessboard

  • The bottom two pixels contain a bit packed representation of an chessboard as how we would see it.
  • The top two pixels contain the (y, x) positions of every single piece.
  • The bottom two pixels are only good for moving and capturing pieces, it's fast to check where the piece can go. The top two pixels are good for the AI because it needs to generate an entire tree of moves. If the AI wants to know where the Queen is, it saves time looping through the entire board searching for it.

Min-max tree

  • The min-max tree is generated through six steps, each with a waiting period of 15ms in between to help reduce GPU stress.
  • The first 151 boards are generated from the current board position, there's a total of 151 moves that can be done per turn.
  • From those 151 boards, the AI generates another 151 for every single one.
  • At the end of the cycle, the path that benefits the computer according to the evaluation function is picked.

Board evaluation

  • For the evaluation function I copied from https://www.chessprogramming.org/Simplified_Evaluation_Function with minor modifications
  • Each piece has a different table influencing where to go and a piece value determining its importance. The king has two tables, early game and late game tables to determine how it moves
  • The entire board score is (White position score + white piece score) - (Black position score + black piece score)

Thanks to Merlin and d4rkpl4y3r for fixing my bit packing stuff.

If you have any question contact me at @SCRNinVR or on Discord, SCRN#8008

chess-shader-with-artificial-intelligence's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

chess-shader-with-artificial-intelligence's Issues

SDK3?

Is there anything stopping this from working in a Udon/SDK3 world?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.