I'm building my own chess engine for endgames in Python But I've got stuck

A place for game announcements, and for people to discuss games being made.
Forum rules
Please read the sticky before creating a new topic. Linking to Kickstarter/Crowdfunded games requires a demo. Updates to Patreon-backed games may be posted once every 2 months. Adult content should not be posted in this forum.
Post Reply
Message
Author
max22234
Newbie
Posts: 1
Joined: Sun Mar 03, 2024 9:21 am
Contact:

I'm building my own chess engine for endgames in Python But I've got stuck

#1 Post by max22234 »

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

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

Code: Select all

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:

Final 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
. . . . . . . .
. . . . . . . . 

Post Reply

Who is online

Users browsing this forum: Duhop