0

I have an issue with the lichess API, where my bot cannot play a move in the game where it is being challenged. It can accept the challenge, but not play in it. What am I doing wrong?

# Code to accept the challenge/make moves

  # Start playing the game
  response = requests.post(
       "https://lichess.org/api/bot/game/open",
        headers=headers,
        data={
            "variant": "standard",
            "gameId": challenge_id
        })

   if response.status_code != 200:
        # Handle the case where the game could not be started
        print(f"Error starting game: {response.json()['error']}")
    else:
        game_id = response.json()["id"]
        print(
            f"Started game {game_id} against {challenger_username} ({time_control})")

        # Play the game
        while True:
            # Wait for the bot's turn
            wait_for_my_turn(game_id)

            # Calculate the bot's move
            move = "e2e4"  # placeholder until lichess API works

            # Make the move
            response = requests.post(
                f"https://lichess.org/api/bot/game/{game_id}/move", headers=headers, params={"move": move})

            if response.status_code != 200:
                # Handle the case where the move could not be made
                print(f"Error making move: {response.json()['error']}")
                break

            # Check if the game is over
            if response.json()["status"] != "started":
                break  # placeholder until lichess API works

0 Answers0