4

I'm working on a chess AI for a school project and I am looking into ways to identify the current phase of a board, meaning the opening, middlegame, and endgame. I have seen an article explaining Tapered Evaluation, however I don't really understand what the point of this is. I want to be able to change my overall board evaluation heuristic depending on what state the game is in. This way, in the middlegame, I can prioritize king protection and development and other strategies.

5

I think you don't need this. You shift from opening to middle game when your opening book for this line runs out. The middle-end phase is less relevant in AI, and your algorithm will handle those the same. You could define a line, e.g. when your search depth could be increased over some threshold, because the board has only a handful of pieces left, but I don't think it's an important change.

  • Okay, I see what you're saying, however, I think the king's role changes in the endgame enough to warrant this, if nothing else. I am not extremely well versed in chess theory but I know it is important to activate the king in the endgame, rather than hide it away, protected like the middlegame. Thoughts? – Damion Lance Dec 9 '19 at 15:25
  • I know from experience you need 2 nights to implement Minimax with alpha-beta pruning for a simple game (Chess might be a bit more tedious to code than Reversi I've did, so maybe add 1 more night). Then you'll see it for yourself. Even an AI just doing that will beat an average player on contemporary hardware. Your AI will know from looking ahead 10-15 moves that moving your king into the center is bad for the middle game and good in the end when mostly pawns are around. – Nyos Dec 9 '19 at 15:43
3

The definition of "the middlegame" is a somewhat gray area.

There's no commonly-accepted, sharply-defined definition for when the middlegame starts/ends.

I suggest you start with one of these definitions, test it, and refine it if it gives poor results:

Middlegame Definition #1:

  • Castling has occurred, OR
  • 10 moves have been played

Middlegame Definition #2:

  • One player's rooks are connected, OR
  • 12 moves have been played

Middlegame Definition #3:

  • One player has castled AND has moved all minor pieces at least once AND has moved at least 1 pawn, OR
  • 12 moves have been played

The endgame is generally defined as being "when the Kings are ready to join the battle", which usually occurs when there are few pieces left on the board. Start with defining the endgame as when there are 12 pieces left on the board and improve it if that definition ever fails.

  • "When the Kings are ready to join the battle" is a questionable definition of endgame. When you play an endgame, you have to be on the look out for effective use of your king. There are endgames where kings doesn't join battle (eg: both sides hunt opposing kings). – Cyriac Antony Dec 9 '19 at 8:38
  • 5
    "has moved all minor pieces at least once AND has moved at least 1 pawn" seems somewhat redundant. It is difficult to move the bishops without moving at least two pawns. – Arthur Dec 9 '19 at 9:08
  • I have used my King in the middle game to help mate the other guy. At least one GM game did that too. Qs were still on the board when I did it so I had to count moves carefully to ensure it worked:) – edwina oliver Jan 20 at 18:03
2

There is no sharp definition that would say x moves and y moves is where.

The opening is pretty much over when you have exhausted moves that have been played so many times by many players. It could be short if someone makes an unusual move, or, for a very long time, play some extremely old lines especially when GMs want to play safe for a draw.

Endgames would tend to start when there is really not enough material to mount a mating attack by force. Just trading queens is not enough if all the other pieces are still in play.

But none of this should matter to an AI program. They are just arbitrary identifiers to help indicate the stage of the game.

A good AI program would evaluate the position independently of what stage you thought the game was in. Not doing so would lead to a number of places that give weird results. Anyway, isn't AI supposed to determine those weightings for itself based on the position?

The problem is you can't train AI with enough examples to really make AI work the way it normally does.

  • I see what you're saying however, in reference to your last statements, I'm not using a data-driven AI, but an expert-based, rule driven agent. This way it will not "learn" best moves based on neural networks or other machine learning algorithms, but rather with rules and heuristics. – Damion Lance Dec 9 '19 at 5:42
  • @DamionLance - Then we disagree on what AI really is. I do not call rule based decision AI but merely a fancy program to make decisions. I may be too old , but I do not see how it learns anything from rules and heuristics. Are you using a sort of genetic algorithm to adjust the rules? Then again I do not think you can have enough data to do that. Maybe for an opening but not later on. – yobamamama Dec 9 '19 at 14:02
  • @DamionLance - What school is this? HS like a science fair project, special 'governors' school for the super smart, community college, university, graduate school? I would suggest especially for earlier on that scale you try to find a way to scale the problem down. – yobamamama Dec 9 '19 at 14:04
  • This is for an undergraduate project for my 300's level intelligent systems course. Basically the way it operates is the agent evaluates all possible moves and decides which ones are useful (based on positional heuristics and potential for capture or mate), then uses a minimax algorithm to find which moves maximize gain for itself, while minimizing board value for the opponent. – Damion Lance Dec 9 '19 at 15:16
  • @DamionLance - that sounds reasonable for that course. I think you need a different set of rules to evaluate the end of the initial tree analysis. More based on pawn structure, material, positional factors, then those could work for any phase of the game. Openings should be by history of results from GM games to simplify the task. – yobamamama Dec 9 '19 at 18:28
1

As a rough estimate, I've once seen the definition that the endgames begins when each side's pieces has a strength of 13 or less (counting 9 for queen, 5 for rook, 3 for bishop/knight and ignoring pawns) Can't remember the source, though.

The opening is often said to end when all of the pieces are developped, but it's not always so clear. You may want to alow one piece to stay on its starting square and call it the middlegame already

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.