I have a rather simple chess endgame Python code implementinng `negamax strategy` given below but it behaves strange.Negamax means that when both players play fully rationally the best move leading to the quickest mate or the longest defense by both sides.It prints correctly this position, but the best move `Kb2c2` is not even considered when I have printed all legal moves.I'm even unable to force the code `consider` at any stage of searching the best move by white king `K`.I would like if some can dig into the code and tell me what's wrong **huh** The output: . . . . . . . .. . . k . . . .. . . . . . . .. . . . . . . .. . . . . . . .. . . . . . . .. K . p . . . .. . . . . . . . Na tahu je: bílý (white to move in Czech language)b2c3<LegalMoveGenerator at 0x1d473d26b50 (Ke8, Kd8, Kc8, Ke7, Kc7, Ke6, Kd6, Kc6, d1=Q, d1=R, d1=B, d1=N+)><LegalMoveGenerator at 0x1d473d26250 (Kd4, Kc4, Kb4, Kd3, Kb3, Kxd2, Kc2, Kb2)><LegalMoveGenerator at 0x1d473d24050 (Kf8, Kd8, Kf7, Ke7, Kd7, d1=Q+, d1=R+, d1=B, d1=N)><LegalMoveGenerator at 0x1d473d25e10 (Ke5, Kd5, Kc5, Ke4, Kc4, Ke3, Kd3, Kc3)><LegalMoveGenerator at 0x1d473d25110 (Kg8, Ke8, Kg7, Kf7, Ke7, d1=Q, d1=R, d1=B, d1=N)><LegalMoveGenerator at 0x1d473d27110 (Kf6, Ke6, Kd6, Kf5, Kd5, Kf4, Ke4, Kd4)> The code:[python]import chessimport timeimport threading # Globální proměnná pro sledování počtu prohledaných pozicpositions_count = 0 def update_positions_count(last_time_printed): global positions_count while not board.is_game_over(): if time.time() - last_time_printed > 1: print(f"\rProhledaných pozic: {positions_count}", end='') last_time_printed = time.time() def evaluate_board(board, depth): global positions_count positions_count += 1 if board.is_checkmate(): return 10000 - depth if board.is_stalemate() or board.can_claim_draw(): return 0 return None # ... negamax, find_best_move ...# Negamax algoritmusdef negamax(board, depth, alpha, beta, color): evaluated = evaluate_board(board, depth) if evaluated is not None: return color * evaluated if depth == 0 or board.is_game_over(): return 0 max_eval = float('-inf') print(board.legal_moves) for move in board.legal_moves: board.push(move) eval = -negamax(board, depth - 1, -beta, -alpha, -color) board.pop() max_eval = max(max_eval, eval) alpha = max(alpha, eval) if alpha >= beta: break return max_eval def find_best_move(board, depth): best_move = None best_value = float('-inf') alpha = float('-inf') beta = float('inf') color = 1 if board.turn else -1 print(f"Na tahu je: {'bílý' if board.turn else 'černý'}") for move in board.legal_moves: print(move.uci()) # Vypíše tahy ve formátu UCI if move.uci() == "c1c2": # Příklad pro tah bílého krále print("HERE") board.push(move) board_value = -negamax(board, depth - 1, -beta, -alpha, -color) board.pop() if board_value > best_value: best_value = board_value best_move = move return best_move # Hlavní část kódu#start_position = "8/8/8/8/8/7Q/k7/2K5 w - - 0 1"#start_position = "8/3k4/8/8/8/8/1K6/8 w - - 0 1"start_position = "8/3k4/8/8/8/8/1K1p4/8 w - - 0 1"board = chess.Board(start_position)depth = 11 # Můžete zvážit snížení hloubky pro rychlejší výsledkylast_time_printed = time.time() positions_count_thread = threading.Thread(target=update_positions_count, args=(last_time_printed,), daemon=True)positions_count_thread.start() print(board)print() while not board.is_game_over(): best_move = find_best_move(board, depth) if best_move is not None: board.push(best_move) print("\n", board) # Vytiskne šachovnici po provedení nejlepšího tahu else: print("Žádný další legální tah není možný.") break print("\nKonec hry")[/python]
I would like to download X games of any chess.com bot for the tool I'm developing. Is that possible? Thanks in advance for your help.
x-5560766384 Jan 20, 2024
For end point https://api.chess.com/pub/match/{ID} whilst in registration, when new players register for the match the endpoint updates quickly (almost in real time). However if the roster gets locked then the field "locked": only updates at the next cycle, which could be as long as 12 hours, by which time the match could have started. This field is only of any value if it updates as quickly as new member registrations.
DeepshikaKarthick Jan 8, 2024
Approximately how long do you have to wait for a response from chess.com regarding oAuth login access? I filled out the form some time ago but have not received any response.
jardele4 Jan 5, 2024
Answer: When a member is accessing the site via the mobile app! It seems that via the app, a member is permanently 'logged on' and so never updates the "last_online" setting. This cropped up here: Games Played Long After Last Online Date? But I thought it might be new information for many in this club, so wanted to draw attention to it. It's something I've been using for years to weed out 'absent' club admins who get nominated to look after teams in the leagues I help run but it seems that doesn't work so well any more 🙄
jardele4 Jan 3, 2024
In some profile data I downloaded for informal research, I noticed some cases where games were played long after the last_online date. There were several of these in my sample set of 53, so it doesn't look like an isolated occurrence. Is this a known issue? If so, it seems that my best bet would be to look at the date the last game was played. Here's an example: https://www.chess.com/member/RobinsRevenge0 Last game was on November 7, 2023, but their profile data shows they were last online on June 20, 2023: [{'name': 'RobinsRevenge0', 'status': 'closed:fair_play_violations', 'date_created': '2021-01-18 00:05:08 UTC', 'last_online': '2023-06-20 01:05:19 UTC', 'country': 'CA', 'url': 'https://www.chess.com/member/RobinsRevenge0'}] Used get_player_profile() from the (unofficial) chessdotcom library in Python, if that's relevant.
stephen_33 Jan 2, 2024
Hi,I have a website where the user can enter his nickname from chess.com. When he does this, the website checks his played games once a day, saves it in the database and generates statistics. I want to change the manual username entry to logging in via oauth the chess.com server. I want to make sure that the username the player provides actually belongs to him. The server provides access tokens. My question is: should I save tokens for each user (access and refresh token) and add them to the query for data of each user in turn when I retrieve information about their games? Now, having their usernames, I simply download the data I need from the API without adding tokens and everything works. Please advise.Thanks!
mlody87pl Dec 31, 2023
Under https://www.chess.com/events, if any event is going on, chess.com will show the live games. How are the moves and clock times determined in real time? Is there an external API to get this information?
ChipDaWolf Dec 29, 2023
Hello, I'm hoping to use the API to query a user's games archive and then walk the archive for games that have been evaluated by chess.com to search for positions with m3 or less. Based on the the Published Data API doc I'm not entirely sure this is possible. Is there currently any API support for seeing people's premium game evaluations?
winstonpurkiss Dec 8, 2023
I really like the game review feature at chess.com. I would be very interested if there is an API that allows me to submit a PGN for a game and to receive game review response. Any plans for this? It could allow Chess GUIs to integrate with chess.com.
ShadowDeveloper Dec 8, 2023
They stole my championship. I cannot have this stay as such... I am not number zero: i triumphed and I want to see my opponents score underneath mine... anyone has had such troubles ? Have you found a way to get your due respect from Chess.com through service help/contact support means?
ThroughtonsHeirAlexHebert Dec 7, 2023
I am processing game result codes right now and have questions about some of them. Any help would be appreciated. I got the game result codes from https://www.chess.com/news/view/published-data-api#game-results I have questions about the following codes 1- Abandoned: What is the difference between abandoned and resigned? 2- Lose: Why would it say lose? Why wouldnt it say resigned, or checkmated? I want to know if these are used and if I should expect them to come up in endpoints. I have been checking some of them and most say "win" or "checkmated" or "agreed" etc...
ShawnBierman Dec 7, 2023
So I have a python program that's querying the API and it's been working fine. A week ago or so I told support I had two accounts and it was approved. Well, now my program has been fine making calls to get PGN data from my newer account, but today I went to pull PGN data from the other account (SimpleChessBrah), and the JSON returned is an error message with error 503, with the message: An internal error has occurred. Please contact Chess.com Developer's Forum for further help https://www.chess.com/club/chess-com-developer-communityHelp would be appreciated.
simplechessbro11 Dec 5, 2023
I don't think this exists, but it would be nice if chess.com could have a setting where you get notified whenever a new member joins your club(s). Could this possibly happen sometime? (btw I was told I should make a topic about this in this club; here is is: chess.com/clubs/forum/view/suggestion-notifications-for-new-members-in-clubs Chess.com Community Club)
I'm running a script that was working fine just yesterday, but today it blocks trying to get the games from this player: https://www.chess.com/stats/daily/chess/eddierapster Here we see there's some daily games that should be at least in the "finished", yet the API returns an empty list: https://api.chess.com/pub/player/eddierapster/matches Any clue what happens here?
Martin_Stahl Dec 2, 2023
Hey everyone, I am new to the world of coding and am going to start a major in data analytics soon. I did a little IBM course to get a feel for the subject, but the projects were very much engineered, and didn't feel like I was actually doing anything. So, I decided that on my first 'real world' project, I would make something that can grab the API for my stats so I can make a regression plot for my Elo or just some neat graphs or something. It didn't take long for me to get my first error, and after consulting with the almighty chat-gpt, I have been led here to try and solve my problem. The error I am getting is a 403 error which seems to indicate that my authentication is being blocked. Any help would be appreciated, and is this project something I can even do?
Takin_These Nov 30, 2023
Hey, I wanted to program something that could say what move was played and then when I thinked I could say what move I want to play and the program plays it on chess.com (for example with a bot). So that I could train to play blinfolded. Do you know if something like that already exist ? and if not, do you know what api I can use to get and control my navigator (which can be anything, like opera or chrome) or even my chess com account to do so ? Thank you.
Louloufou63 Nov 28, 2023
Hey guys, was wondering if anyone could help me in doing the following task:- take a game link as input- grab the pgn from that game in such a format that I can modify it to do things like: -- remove ratings, -- change and use variables to modify usernamesthen print the pgn Preferably in python. I've seen many posts about using many pgns or pgns of a certain user, so was wondering if this was even possible! Thanks.
ninjaswat Nov 27, 2023
Sharing some scripts I've created. They are functional and I could make them more user-friendly if there is any interest. Chess Power Tools is a collection of scripts that can help do the following: Export chess games from Chess.com in JSON and PGN format (chesscom-export) Import chess games from PGN to SQLite DB (pgn2sqlite) The next script I'm planning is for more analysis. For example, expand the SQLite DB to include a table for moves and fields such as: Position (FEN) Engine evaluation Move evaluation Centipawn loss and more (I'm taking suggestions)
chesslover0003 Nov 26, 2023
I've been working on Chess Time for almost 2 years on and off as a way to calculate your play time on Chess.com. I just made a big update on the design and the stats that are available. It's quite nice what you can do with the public API. Now you can track your nemesis and victim players – it's pretty neat to see those stats in action! https://www.chesstime.io/ The app was built with React and Typescript. There is no backend yet but I'm looking into the possibility of building one. Here's a sneak peak: A nice breakdown of the win/loss/draw conditions The player that you played the most games with and the player that you have won/lost/drew the most against. As you can see, I love playing against bots.
Purecojones Nov 23, 2023