Live data from Hacker News

A step-by-step guide to building a simple chess AI

medium.com

21–30 of 44 posts

Re: A step-by-step guide to building a simple chess AI

#22

I made a few minimax based AIs for games in uni, but I had always wondered how I would calculate score. How are these point systems made? Are they just educated guesses? How far can minimax take you as far as skill level?

> How are these point systems made?

I'm currently in the process of building my own chess AI (in python), and I'm using as a score a weighted combination of the material and of the number of squares controlled by each side. I am planing to experiment with weighting more the squares that are closed to the opponent's king, and possibly to improve the evaluation function using reinforcement learning.

That said, my program is currently pretty weak, first I have to optimize its calculation speed to it can calculate deeper.

Re: A step-by-step guide to building a simple chess AI

#23

No story about chess engines is complete without a mention of 1k Chess for the Sinclair ZX81: http://users.ox.ac.uk/~uzdm0006/scans/1kchess/ How big is it? 672 bytes. How much memory did that ZX81 have after the OS had claimed its share? 672 bytes.

Afaik it was an incomplete engine (didn't implement all the rules of the game), right? Still impressive, but important to keep that in mind.

Re: A step-by-step guide to building a simple chess AI

#24

I made a few minimax based AIs for games in uni, but I had always wondered how I would calculate score. How are these point systems made? Are they just educated guesses? How far can minimax take you as far as skill level?

There's a common scoring system that is often used to help children who are learning to play chess (pawn is 1, knight and bishop are 3, etc).

A pure minimax engine isn't that hard to beat because the engine will be basically playing random moves during the opening phase. An opening repertoire + minimax on a modern computer will beat casual players (probably 1700-1900 Elo if I had to guess). You also have to do some good time management.

Re: A step-by-step guide to building a simple chess AI

#25
post #2

Interesting that it's deterministic. I can get it to play the same game again and again. Why is this not the case with more advanced chess engines? Edit: Apparently single-threaded stockfish is deterministic. Maybe my experience with non-deterministic chess engines just has to do with the handicapping related to providing easier levels of play.

Never checked but somehow got me surprised: aren't all chess engines deterministic? The same program, given the same input, should give the same output unless it is specifically programed to try to avoid it (and then we have PRNGs).

Stockfish isn't.

Re: A step-by-step guide to building a simple chess AI

#27
I spent some time trying to develop a chess AI a short time ago. I had this crazy idea that if I stored all of the possible moves in memory I'd only need to calculate the nth level of depth after every move.

This kills the computer.

After deciding it was best to simply re-evaluate every time, what caught me up was en passant castling and so fourth. It's a challenging topic. I recommend it.

Re: A step-by-step guide to building a simple chess AI

#28

No story about chess engines is complete without a mention of 1k Chess for the Sinclair ZX81: http://users.ox.ac.uk/~uzdm0006/scans/1kchess/ How big is it? 672 bytes. How much memory did that ZX81 have after the OS had claimed its share? 672 bytes.

Afaik it was an incomplete engine (didn't implement all the rules of the game), right? Still impressive, but important to keep that in mind.

It didn't understand castling, en passant and promotions. It would also only play white.

I did once try to pit it against a modern engine. It seemed to do reasonably well until the modern engine sneakily castled, and I was unable to tell 1k Chess about this, thus forcing it to forfeit the game.

Of course, since posting that, I since found this:

http://nanochess.org/chess6.html

Chess for the PC; 392 bytes. You put it in your boot sector. Still no castling, en passant and promotions, though, although there's an 831 byte version which has those.

Re: A step-by-step guide to building a simple chess AI

#29
I'm very interested in the values assigned to pieces. Does anyone know the source or reasoning behind the table in step 2?

How are pieces relative values calculated? What's to say a pawn is 1/3 of a rook or a knight?

And why is the king 900, not simply the total value of all other pieces or slightly more? 8 pawns (10 ea), 2 knights (30 ea), 2 rooks (30 ea) and a queen (90) totals 290 points. Why can't a king simply be 300 points? If it needed to be worth more than both sets (white and black) for some reason why couldn't it be worth 600? The value 900 seems arbitrary to me.

If there's sound reasoning behind this can anyone recommend material related to deriving similar weighted values?

Re: A step-by-step guide to building a simple chess AI

#30
post #29

I'm very interested in the values assigned to pieces. Does anyone know the source or reasoning behind the table in step 2? How are pieces relative values calculated? What's to say a pawn is 1/3 of a rook or a knight? And why is the king 900, not simply the total value of all other pieces or slightly more? 8 pawns (10 ea), 2 knights (30 ea), 2 rooks (30 ea) and a queen (90) totals 290 points. Why can't a king simply b…

Check out this chess programming wiki article [1] for a (still fairly hand-wavy) rationale for similar piece values, and the Wikipedia article on chess piece relative values [2] for a more in-depth look at various weightings. Some modern approaches use analysis of a huge corpus of master games to come up with piece values, but many of the systems are based on intuition and empirical evidence.

[1] https://chessprogramming.wikispaces.com/Simplified+evaluatio... [2] https://en.wikipedia.org/wiki/Chess_piece_relative_value

Post reply on HN