- Blind mode tutorial
lichess.org
Donate

Using API to automatically have a bot send challenges to other bots

Hello! Sorry if this is too specific/niche.

I'm working on a chess bot (melsh_bot), and I'm trying to have it automatically send challenges to other bots, so that it would have a more an accurate rating, so that when I modify my bot, I can just come back after a couple of hours to see how the rating has changed, instead of manually challenging other bots.

The lichess bot code doesn't seem to have code to handle that automatically, so I tried making the function.
I added this to the lichess.py file:

def challenge_user(self, username):
challenge_data = "{'rated':false 'clock.limit':30 'clock.increment':1}"
x = self.api_post(ENDPOINTS["challenge"].format(username), data=challenge_data, headers ={"Content-Type": "application/x-www-form-urlencoded"})
return(x)

and added ENDPOINTS["challenge"] as "/api/challenge/{}"

When testing (by having my bot send a challenge to my human account), this almost works, but for some reason, the time control of the challenge is always set to Unlimited, instead of being 1/2 + 1, which it should be based on the data I sent.

Would anyone know what I'm doing wrong?

Hello! Sorry if this is too specific/niche. I'm working on a chess bot (melsh_bot), and I'm trying to have it automatically send challenges to other bots, so that it would have a more an accurate rating, so that when I modify my bot, I can just come back after a couple of hours to see how the rating has changed, instead of manually challenging other bots. The lichess bot code doesn't seem to have code to handle that automatically, so I tried making the function. I added this to the lichess.py file: def challenge_user(self, username): challenge_data = "{'rated':false 'clock.limit':30 'clock.increment':1}" x = self.api_post(ENDPOINTS["challenge"].format(username), data=challenge_data, headers ={"Content-Type": "application/x-www-form-urlencoded"}) return(x) and added ENDPOINTS["challenge"] as "/api/challenge/{}" When testing (by having my bot send a challenge to my human account), this almost works, but for some reason, the time control of the challenge is always set to Unlimited, instead of being 1/2 + 1, which it should be based on the data I sent. Would anyone know what I'm doing wrong?

Update: Figured it out, and to avoid being DenverCoder9 (https://xkcd.com/979/), I'll share the solution

I made 2 changes

  1. used a dictionary instead of a string
  2. used the string "false", instead of the boolean False

Here is the function:
def challenge_user(self, username):
payload = {"rated": "false", "clock.limit": 60, "clock.increment": 1}
return self.api_post(ENDPOINTS["challenge"].format(username), data=payload, headers ={"Content-Type": "application/x-www-form-urlencoded"})

To be honest, I have no idea why this works now, when it didn't work before, but that's just how coding goes sometimes

Update: Figured it out, and to avoid being DenverCoder9 (https://xkcd.com/979/), I'll share the solution I made 2 changes 1. used a dictionary instead of a string 2. used the string "false", instead of the boolean False Here is the function: def challenge_user(self, username): payload = {"rated": "false", "clock.limit": 60, "clock.increment": 1} return self.api_post(ENDPOINTS["challenge"].format(username), data=payload, headers ={"Content-Type": "application/x-www-form-urlencoded"}) To be honest, I have no idea why this works now, when it didn't work before, but that's just how coding goes sometimes

Noob here, could you explain the reason to create and use a bot for this site?
Thank you in advance!

Noob here, could you explain the reason to create and use a bot for this site? Thank you in advance!

#3 to test a developers program.

#3 to test a developers program.

@BelowAvgDonk Here's blog post about lichess bots: https://lichess.org/blog/WvDNticAAMu_mHKP/welcome-lichess-bots

For me particularly, I am making a chess engine from scratch as a hobby and for fun. I want to know how good my engine is, so I use lichess to play it against other bots and other humans, because once it's set up, it's much more hassle-free than running local games.

@BelowAvgDonk Here's blog post about lichess bots: https://lichess.org/blog/WvDNticAAMu_mHKP/welcome-lichess-bots For me particularly, I am making a chess engine from scratch as a hobby and for fun. I want to know how good my engine is, so I use lichess to play it against other bots and other humans, because once it's set up, it's much more hassle-free than running local games.

Oh, I get it now. Thank you for the explanation and I hope you create a crushing engine! Sounds like a great hobby as well!

Oh, I get it now. Thank you for the explanation and I hope you create a crushing engine! Sounds like a great hobby as well!

This topic has been archived and can no longer be replied to.