Python Forum
A new endgame problem, almost solved but not quite 2
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A new endgame problem, almost solved but not quite 2
#1
I'm trying to create my own chess endgame code for a trivial game 3 pieces on the board Q+K+k (all in Python) but I'm getting a wrong output at the node 1 in my dictionary A[1]['moves_to_mate']==9 but the true value should be 11 plies to mate (according to stockfish).

Any hint why I'm not getting the true value A[1]['moves_too_mate'] == 9 at the root but please see the comment at the last few lines below:
A BREAKTHROUGH: the only node which is incorrectly computed is the A[1]['sequence']. The code gives [13] but when manually set to [14] all other nodes A[K]['sequence'] for K>1 are OK and correct. Can someone try to help me, given this information ?? PS. Look also here moves_to_mate should be and is 5 when A[1]['sequence'] = 29 is set manually: https://pastebin.com/Knunk3Qv (Note A[1]['sequence'] is the same thing as game_tree[1]['sequence'])

Any help will be highly appreciated. The dictionary A is self explanatory and looks like this:

 
A[new_node_id] = {
                    'fen': simplified_fen,
                    'moves_to_mate': None,
                    'parent': node_id,
                    'color': chess.WHITE if simplified_fen.split()[1] == 'w' else chess.BLACK,
                    'result': None,
                    'processed': False,
                    'sequence': [],
                    'children': [],
                    'to_end': None,
                }
The code is the code is here and the output is here: https://pastebin.com/iJJf74WQ

Final Output:
Output:
{'fen': '7Q/8/8/6k1/2K5/8/8/8 w - -', 'moves_to_mate': 9, 'parent': None, 'color': True, 'result': 1, 'processed': True, 'sequence': [17], 'children': [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30], 'to_end': 9} 1* {'fen': '8/6k1/4K3/8/8/7Q/8/8 b - -', 'moves_to_mate': 4, 'parent': 3743, 'color': False, 'result': 1, 'processed': True, 'sequence': [31639], 'children': [31639, 31640, 31641], 'to_end': 4} 15967* {'fen': '6k1/8/4K3/8/8/7Q/8/8 w - -', 'moves_to_mate': 3, 'parent': 15967, 'color': True, 'result': 1, 'processed': True, 'sequence': [70638], 'children': [70636, 70637, 70638, 70639, 70640], 'to_end': 3} 31639* {'fen': '5k2/8/4K3/8/8/7Q/8/8 w - -', 'moves_to_mate': 3, 'parent': 15967, 'color': True, 'result': 1, 'processed': True, 'sequence': [70642], 'children': [70641, 70642, 70643, 70644, 70645], 'to_end': 3} 31640 {'fen': '8/8/4K1k1/8/8/7Q/8/8 w - -', 'moves_to_mate': None, 'parent': 15967, 'color': True, 'result': None, 'processed': True, 'sequence': [], 'children': [70646, 70647], 'to_end': None} 31641 {'fen': '8/6k1/8/3K4/8/7Q/8/8 w - -', 'moves_to_mate': 5, 'parent': 1190, 'color': True, 'result': 1, 'processed': True, 'sequence': [15967], 'children': [15967, 15968, 15969, 15970, 15971, 15972], 'to_end': 5} 3743* {'fen': '8/8/6k1/3K4/8/7Q/8/8 b - -', 'moves_to_mate': 6, 'parent': 101, 'color': False, 'result': 1, 'processed': True, 'sequence': [3743], 'children': [3743, 3744, 3745, 3746], 'to_end': 6} 1190* {'fen': '8/8/6k1/8/2K5/7Q/8/8 w - -', 'moves_to_mate': 7, 'parent': 17, 'color': True, 'result': 1, 'processed': True, 'sequence': [1190], 'children': [1190, 1191, 1192, 1193, 1194, 1195, 1196, 1197], 'to_end': 7} 101* {'fen': '8/8/8/6k1/2K5/7Q/8/8 b - -', 'moves_to_mate': 8, 'parent': 1, 'color': False, 'result': 1, 'processed': True, 'sequence': [101], 'children': [101, 102, 103], 'to_end': 8} 17* {'fen': '6k1/8/5K2/8/8/7Q/8/8 b - -', 'moves_to_mate': 2, 'parent': 31639, 'color': False, 'result': 1, 'processed': True, 'sequence': [106380], 'children': [106380], 'to_end': 2} 70638* {'fen': '5k2/8/5K2/8/8/7Q/8/8 w - -', 'moves_to_mate': 1, 'parent': 70638, 'color': True, 'result': 1, 'processed': True, 'sequence': [165316], 'children': [165314, 165315, 165316, 165317, 165318], 'to_end': 1} 106380* {'fen': '2Q2k2/8/5K2/8/8/8/8/8 b - -', 'moves_to_mate': 0, 'parent': 106380, 'color': False, 'result': 1, 'processed': True, 'sequence': [], 'children': [], 'to_end': 0} 165316* Node ID: 1, Moves to Mate: 9, Result: 1 . . . . . . . Q . . . . . . . . . . . . . . . . . . . . . . k . . . K . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Node ID: 17, Moves to Mate: 8, Result: 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . k . . . K . . . . . . . . . . . . Q . . . . . . . . . . . . . . . .
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  a chess endgame problem, almost solved but not quite max22 0 167 Mar-31-2024, 06:14 PM
Last Post: max22
  optimum chess endgame with D=3 pieces doesn't give an exact moves_to_mate variable max22 1 287 Mar-21-2024, 09:31 PM
Last Post: max22
  Problem with datetime [SOLVED] AlphaInc 3 2,788 Apr-22-2022, 01:33 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020