lichess.org
Donate

I have a problem with Python's code designed to solve trivial endgames

Hi, I think someone could still help me with my Chess Python Endgame. I've described my problem in some detail. Read on, and see if you could correct my code for which I provide a temporary version on pastebin:
could someone kindly post a corrected code on pastebin.com and give me a link?
I need to create a game_tree with game_tree[K]['sequence'] for node K, where K==1 is the root. Then I need to determine the *fully optimal way* for both players B&W, if the stronger player could reach a Win in as few moves as possible, and if not the draw.The weaker player then should delay the checkmate as long as possible of even attain a draw. But moves_to_mate is from time to time incorrectly computed. moves_to_mate is None if the weaker player can reach a draw and should be as long as possible to delay checkmate.
A[K]['to_end'] is always a number but A[K]['moves_to_mate'] is None if the weaker player can reach a draw.
And the task is to compute game_tree[K]['sequence'] and game_tree[K]['to_end'] correctly for all K's when both B&W play fully optimally. Please note that game_tree may be called also "A".
My current code is here:

pastebin.com/Knunk3Qv

I need to create a game_tree with game_tree[K]['sequence'] for node K, where K==1 is the root. Then I need to determine the *fully optimal way* for both players B&W, if the stronger player could reach a Win in as few moves as possible, and if not the draw.The weaker player then should delay the checkmate as long as possible of even attain a draw. But moves_to_mate is from time to time incorrectly computed. moves_to_mate is None if the weaker player can reach a draw and should be as long as possible to delay checkmate.
A[K]['to_end'] is always a number but A[K]['sequence'] is None if the weaker player can reach a draw.
And the task is to compute game_tree[K]['sequence'] and game_tree[K]['to_end'] correctly for all K's when both B&W play fully optimally. Please note that game_tree may be called also "A".

to check the correctness of the code I'm using Stockfish: lichess.org/editor It is not necessary that *all* the positions are exactly the same for the code and StockFish, but StockFish should consider the code output optimal, and definitely the number A[K]['to_end'] should agree with StockFish optimal play. The difference between A[K]['to_end'] and A[K]['moves_to_mate'] is that the former is always a number but when the optimal result is a draw the latter is None. Feel free to ask me anything unclear.

A[K]['sequence'] contains the optimal sequence of (codes of moves) moves (i.e. not a number of moves) and A[K]['moves_to_mate'] is None if draw can be reached by the weaker player while A[K]['to_end'] is always a number leading to a draw or checkmate by the stronger player.

Most often the unique wrong result is only the root A[1]['sequence'] but I' not sure with this, as they may be some other wrong outputs.

At best for testing purposes, for this fen string: 7K/8/k1P5/7p/8/8/8/8 w - - 0 1 the optimal move should be to this: "8/6K1/k1P5/7p/8/8/8/8 b - -" (where I omitted the last 2 numbers as they are irrelevant, just the first part matters) i.e. an optimal move should be Kh8g7. But in any case do not hardcode it into the code, this example fen string will serve just for a check whether the code is correct even with promotions of P and p (white pawn and black pawn resp.)
And stronger is black as he seems to have a more advanced pawn which doesn't seem to be caught easily but that king's move to g7 will save white a draw.By moves_to_mate I mean in fact a plie.
As a final note, you need not consider any efficiency issues: if the code runs on that string above 20 hours that's perfectly OK.

This topic has been archived and can no longer be replied to.