Optimize Chess Code for Checkmate Delay

Job ID: 39620440

Budget: €250 – €750 EUR

I'm seeking assistance to optimize a Python chess program using the python-chess library. The current code, which can be found here: https://pastebin.com/vB0bLwXs, is not producing the optimal move for the white side. Instead of the desired move Aa4a1, it outputs a sub-optimal move Kg1h1, allowing black to deliver a quick checkmate with ce3e1. The goal is to adjust the code so that the program plays optimally for both sides, with the weaker side (white) aiming to delay checkmate as long as possible, while the stronger side (black) seeks to deliver checkmate swiftly.

Key Requirements:
- Analyze and fix the existing Python code to ensure optimal move selection for delaying checkmate.
- Utilize the python-chess library effectively to evaluate moves.
- Generate a list of dictionaries and recursively evaluate to_end and to_mate for optimal gameplay.
- Ensure the program plays optimally for both weaker and stronger sides.

Ideal Skills and Experience:
- Proficiency in Python programming.
- Experience with the python-chess library and chess algorithms.
- Strong understanding of chess strategies and move evaluation.
- Ability to debug and optimize existing code for improved performance.

Please review the bad output here: https://pastebin.com/uF7YwgEM. I'm open to providing further explanations or clarifications as needed. Thank you, Hynek.