Coder Social home page Coder Social logo

chessongolem's Introduction

Chess on Golem

Summary

This project was created as an entry to Golem Hackathon 12/2020.

The other part of project - Chess on Golem Viewer (react app that works as a GUI for Chess on Golem ) can be viewed here: https://github.com/broadcastmonkey/ChessOnGolemViewer

It's purpose is to show that any state based game / problem can be run in Golem Network and solved interactively by provider nodes.

This particular example shows classical chess game played by two AI players that facilitate golem network for computing.

Whole game is managed by Node.js server which distributes chess computing tasks across Golem Network providers.

Each move request is sent to Golem Market and calculated by provider with best bid.

The aim is to show how computing power may affect the outcome of the game.

Right now the depth is fixed by allowing particular players to calculate moves with specific search depth. In youtube demos white player plays with depth of 17 / 20 and black player plays with depth of 1.

In future with more providers in the Golem Network particular players may parallelize their calculations by using more or less providers to achieve better or worse moves in shorter time. It would also probably impact of final cost of game for each player.

Hybrid strategies might be also used, e.g.: use more computing power at the beginning of the game and less computing power in the endgame.

DEMO's

Demo v0.3 // january 2021 https://www.youtube.com/watch?v=Wp_lJEeN7UA&feature=youtu.be&ab_channel=Pawe%C5%82Burgchardt

Demo v0.2 // january 2021 https://www.youtube.com/watch?v=C65uTAZAsRA&list=UUxg1Vq50vwy7Pm3kFwb0ZQg&index=2&ab_channel=Pawe%C5%82Burgchardt

Demo v0.1 // january 2021 (problem with some providers' payments ==> invoices that are way too huge) https://www.youtube.com/watch?v=cTD0zq7jURM&list=UUxg1Vq50vwy7Pm3kFwb0ZQg&index=3&ab_channel=Pawe%C5%82Burgchardt

Presentation: http://developed.home.pl/chessongolem.pdf

Subprojects used in development

Node Chess App

Node.js Server (can be run on linux or windows machines) that is responsible for handling chess game and requesting Golem Network for aid with calculating next moves for each AI player. Moves are calculated on Node alpine docker image transformed to .gvim with a help of a stockfish.js chess engine.

Node chess app creates a request to golem network for each move that is being performed by AI players. For demo purposes one player asks for best move with depth precision of 20 and the other one uses depth of 1.

This can be changed in chess/index.js on line 32:

moveData.depth = moveData.turnId == "w" ? 20 : 1;

Typical calculation times:
Depth
< 10 => < 1s
~ 20 => ~ 3s
~ 30 => ~ 157s

Example of a file with task description that is sent to Golem Providers:

//--------
hash_00000132_0003
20
position fen rnbqkbnr/ppp1pppp/8/3p4/4P3/8/PPPP1PPP/RNBQKBNR w KQkq d6 0 2
//--------

Line 1 : id of an operation used to distinguish different tasks by chess server.
Line 2 : contains depth that stockfish.js algorithm needs to consider.
Line 3: describes current chess game state in fen notation.

Correct output should look similar to this file:

//--------
bestmove e4d5 ponder g8f6
exec time:8672.225822
depth:20
hash:hash_00000132_0003
//--------

With lines describing suggested move, calculation time[ms], depth of calculations and operation id.

Node Chess app is also used as backend server for GUI App that displays chess game in real time with some statistics regarding provider nodes work.

Demo of Node Chess app currently runs at http:// 20.52.154.16/3970 on Linux Ubuntu VM in MS Azure cloud.

To run Node Chess app please do the following:

cd chess
yarn install
yarn js:chess

Script runs until game is finished, when some calculation fails or timeouts golem network is being asked to perform it again.

Multiple clients can connect to socket.io websocket server and listen for events that describe current game state

Events:
• currentTurnEvent
• providerFailed
• computationStarted
• movesRefreshed
• gameFinished
• offersReceived
• agreementCreated
• agreementConfirmed
• computationFinished
• invoiceReceived
• moveEvent
• positionEvent

When client reconnects server sends him automatically current state of the game.

Chess on Golem Viewer

React application that serves as GUI for displaying chess game progress for Chess on Golem.

It displays game progress and some interesting stats regarding provider nodes that took part in calculations.

There is live app available at: https://chessongolem.app

If It's not currently running you can request start at pawel.burgchardt [ A-T] gmail.com

You can run it locally by going to chess-viewer folder and executing

npm install
npm start

You can then open the browser and see the result at http://localhost:3000/

Chess on Golem Viewer connects automatically to node chess app server on 127.0.0.1:3970

To change it please update .env.development file

//------
REACT_APP_NAME=Chess on Golem 1
REACT_APP_VERSION=0.0.1
REACT_APP_SOCKET_SERVER_URL=http://127.0.0.1:3970/
REACT_APP_API_URL=http://127.0.0.1:3970/api
//------

SET UP

  • node 12
  • yagna daemon
  • run yarn install / yarn js:chess in chess folder
  • run npm install / npm start in chess-viewer folder
  • enjoy chess game played by two golem AIs at http://localhost:3000/

Potential growth

  • player vs golem mode
  • other state based games implemented
  • golem network tests for interactive tasks

Used framewroks / libraries

  • Node.js / udner MIT license
  • React / under MIT license
  • Bootstrap / under MIT license
  • Chess.js / under BSD license
  • Chessboard.jsx / under MIT license
  • Socket.io / under MIT license
  • stockfish.js / under GNU General Public License

License

Project is licensed under GPLv3 license.

Author

Paweł Burgchardt

chessongolem's People

Contributors

broadcastmonkey avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

0xhanh

chessongolem's Issues

Small request: Add Golem topic to repository

Hello!

It would be much appreciated if you could add the topic golem to the repository!
That would mean people could find all the awesome projects by just exploring the topic golem here https://github.com/topics/golem, and hopefully create a little bit more exposure for this awesome project! ❤️

There will be a settings wheel on the right side of the screenshot if you head over to your repository's main page, click that and you should see the option to add a topic.
image

Please update your Golem SDK to the newest version :)

Hey! My name is Grzegorz and I'm working with the JS SDK Team at Golem Network.

I would like to let you know that we're actively working on new features and updates of the SDK. As part of these activities we renamed the library from yajsapi to @golem-sdk/golem-js.

Feel free to update your project and use the newest SDK version and features!

🔗 Relevant links

📚 More information

🎙 Looking forward to hearing from you

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.