Code Monkey home page Code Monkey logo

Comments (4)

greg-kennedy avatar greg-kennedy commented on September 24, 2024 3

And... it's done.

Novel: https://github.com/greg-kennedy/ChessBook/blob/master/sample/novel.md

Code (repo): https://github.com/greg-kennedy/ChessBook

Preview

preview

from 2017.

greg-kennedy avatar greg-kennedy commented on September 24, 2024 1

So, a couple things to note about this.

First, I tried to make this novel "interesting" by using a Mate-in-2 problem, so that White would have an ending to search for instead of just a quiescent position. The actual position I used was from a real game in 2017, "Monika Socko vs Laura Unuk, Riga, 2017". See if you can find the best move : )

Second, if you're unfamiliar with chess algorithms: The Minimax algorithm is a simple recursive algorithm paired with a static evaluation function. Essentially, for each board position, try making every possible move - and then, if you are not deep enough, try every resulting move from there. At the bottom, "calculate" how good you think the position is. Simply, you can assign point values to each piece, and count up the "score" of the board.

The intent of Minimax is to minimize the damage that the opponent will do at every move. You should make the move that results in the "maximum" of all possible opponent "minimums". For Chess, you can assign a massive value to capturing a King, and the engine will automatically seek out attacks and checkmates.

Unfortunately, Minimax alone is highly inefficient. This simple position resulted in 370,000+ words for just a 3-ply search. One improvement comes from Alpha-Beta pruning, which cuts branches of the tree when the outcome is guaranteed equal-or-worse than some already evaluated position. The improvement is dramatic, and its development made chess engines actually viable competitors. In my case, Alpha-Beta was actually TOO efficient and I ended up less than 50,000 words... so, the novel code includes a 10% chance to skip pruning if a position is deemed equally as good as another previously seen. The final sample comes to approximately 51,000 words or so.

There are other scripts in the repository: an Engine module, which can be attached to a Chess state and "play" as Harold. And there is play.pl which can be used to play against the engine. This being NaNoGenMo, I ran out of time for some of the engine features I wanted: castling and en-passant are not supported. It turned out not to matter for my test position.

from 2017.

dluman avatar dluman commented on September 24, 2024

This is a very interesting take on suspense. I look forward to reading it!

from 2017.

eseyffarth avatar eseyffarth commented on September 24, 2024

I love this idea! Did you see the entry by @nothings from 2014 that turned a similar (but deterministic) problem into a story?

from 2017.

Related Issues (20)

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.