Breeding Chess AIs



  • As a hobby, I've been writing a program that learns to play chess via evolution: randomly modified copies play chess in order to win the right to breed, resulting in the birth of further mutated offspring. I've finally gotten it to a point where it can usually beat me easily after a day of running a gene pool. Then again, I'm not actually that good of a player, so it might not be that impressive.

    If you want to play against it, I've connected it to lichess: https://lichess.org/@/Genetic_Chess_Bot
    If you don't mind subjecting your sanity to C++, the source code is here: https://github.com/MarkZH/Genetic_Chess/

    As an example of evolution in action, here's a recent history of piece evaluations (how valuable is a queen vs. other pieces). It only took about 120,000 specimens to figure out the correct order (queen > rook > bishop ~ knight > pawn).

    pool.txt special piece strength.png


  • BINNED

    @MZH It's funny that it considers the king to be of negative value.

    Depending on how large the codebase is and where it's on the sane/insane scale of C++, I might actually take a look at it. Genetic algorithms always seemed interesting in theory, but I've never got how to actually make them work.



  • @MZH Cool.

    How many parameters are you tweaking when the algorithms reproduce?



  • @topspin I thought that was interesting as well. There are two genes that use the piece values. The Total Force Gene adds up the pieces on your side and subtracts the pieces of your opponent. This has no effect in the king's value since there are always one white king and one black king on the board. The Opponent Pieces Targeted Gene adds up all opponent pieces currently under attack and subtracts the pieces under attack on your side. What the negative king value tells me is that putting the king in check is unhelpful in and of itself when considering a board position (the leaf of a game tree search).

    @Captain There are 34 parameters: 6 in the gene for time control, 27 in genes for board position evaluation, and one in a gene that does nothing but mutate (the Null Gene). The last acts as a sort of null hypothesis to see what random, undirected, uninfluenced-by-reality evolution looks like. If another gene's evolution looks like (for currently vague definitions of "looks like") the Null Gene, then that gene might not actually be useful and should be deleted.


  • 🚽 Regular

    This kind of reminds me of this video I saw recently.

    https://youtu.be/sw7UAZNgGg8



  • @The_Quiet_One That was cool. I saw a video a while back about implementing the original MENACE (as mentioned by Vsauce).

    https://www.youtube.com/watch?v=R9c-_neaxeU

    The difference between learning by punishment and learning by rewards makes me want to modify my program. Right now, after a game, the next offspring is produced by sexual reproduction between the two players and the offspring replaces the loser. So, about half of the loser's genes make it to the next generation (as does the winner's, but the winner survives to the next generation, leading to a 1.5x representation of the winner's genes). Now I think I'll code a switch so that only asexual reproduction is used--the winner produces a mutated clone and the loser simply dies--to see what happens.


  • BINNED

    @MZH so it seems to think knights are slightly better than bishops. I might have to reconsider how I approach those sorts of simplifications.

    Do I need a lichess account to play it?


  • Notification Spam Recipient

    @topspin said in Breeding Chess AIs:

    It's funny that it considers the king to be of negative value.

    .... It's not?


  • BINNED

    @Tsaukpaetra losing it is usually seen as bad, and attacking the opponent's is a good thing.


  • Notification Spam Recipient

    @MZH said in Breeding Chess AIs:

    If you want to play against it, I've connected it to lichess: https://lichess.org/@/Genetic_Chess_Bot

    How do?

    Also...

    2172cf55-c33c-44b5-8f8a-286921b6270f-image.png

    Trolololo....


  • Notification Spam Recipient

    Signed up and tried to ask the bot to play (I think). Their welcome email is kinda lewd...

    37947034-345f-49f4-aa42-3a3be4cca4db-image.png



  • @Tsaukpaetra I set up the bot to not accept correspondence games (where players take literal days to pick moves) since I don't want my bot locked to one game for weeks. Pick a shorter time control by choosing "Real time" in the drop down menu.


  • Notification Spam Recipient

    @MZH said in Breeding Chess AIs:

    locked to one game for weeks

    Wait, you can't have more than one game going at the same time?



  • @kazitor said in Breeding Chess AIs:

    @MZH so it seems to think knights are slightly better than bishops. I might have to reconsider how I approach those sorts of simplifications.

    Do I need a lichess account to play it?

    The piece values are constantly changing, and the knight and bishop tend to oscillate around each other. So I don't think small differences are important unless they get larger as time goes on.

    You do need an account to specifically challenge someone, but not to play randomly arranged games.



  • @Tsaukpaetra said in Breeding Chess AIs:

    @MZH said in Breeding Chess AIs:

    locked to one game for weeks

    Wait, you can't have more than one game going at the same time?

    I could, but I also run the gene pool at the same time, which maxes out the rest of my CPUs running 7-8 local games in parallel.


  • Notification Spam Recipient

    @MZH said in Breeding Chess AIs:

    maxes out the rest of my CPUs

    I could host. My home server is really bored...

    Edit: But maybe not eternally bored 😉 😉


  • BINNED

    @Tsaukpaetra said in Breeding Chess AIs:

    @topspin said in Breeding Chess AIs:

    It's funny that it considers the king to be of negative value.

    .... It's not?

    Losing / taking the king loses / wins the game, so its piece value is infinite.



  • @topspin said in Breeding Chess AIs:

    @Tsaukpaetra said in Breeding Chess AIs:

    @topspin said in Breeding Chess AIs:

    It's funny that it considers the king to be of negative value.

    .... It's not?

    Losing / taking the king loses / wins the game, so its piece value is infinite.

    My program detects checkmate, so the kings are never removed from the board. So, at least for the the gene that computes the total value of all pieces (your pieces minus your opponent's pieces), the king values cancels. So, I think the resulting value of the king is a reflection of how useful it is to directly attack it and put it in check. Apparently, it does not think highly of it.

    Here's one interesting idea I read on the lichess forums:

    The purpose of the longer time to think is to create more problems for your opponent. You should look for moves which gives your opponent the more difficult choices. This means that you should (almost) never play a forced combination where only one move is reasonable. In complex positions, you should play attacking moves but non-forcing moves. This gives your opponent the chances of missing a simple tactic. In quiet positions, you should strive to improve you pieces, and your opponent, being low on time, often just shuffles pieces. This pattern should give you an advantage once time control has passed.

    So, putting the king in check means the opponent has fewer moves to consider, since the only moves allowed are those that get them out of check. This allows them more time to consider each move and to think further head. This is just a guess though.


  • Discourse touched me in a no-no place

    @MZH That trick with running rapidly into the weeds in a short timed game is how I've been trouncing chess algorithms for years.


Log in to reply