ChessHub icon indicating copy to clipboard operation
ChessHub copied to clipboard

elo ratings for chess bots

Open moonpatel opened this issue 1 year ago • 17 comments

Right now the ELO rating for the chess bot is hardcoded and player have no option to choose a rating to play with. You need to create a dropdown list in the play menu to select ELO rating of chess bot and create a bot instance accordingly in the backend in /backend/chess-bot.js. You can refer to this page to learn more about chess engine commands -> https://gist.github.com/DOBRO/2592c6dad754ba67e6dcaec8c90165bf

You will need setoption command for settings various parameters of the chess engine such as ELO strength.

moonpatel avatar Oct 12 '23 18:10 moonpatel

Please assign this issue to me!

y-ashaswini avatar Oct 13 '23 10:10 y-ashaswini

Sure go ahead @y-ashaswini

moonpatel avatar Oct 13 '23 11:10 moonpatel

Greetings. Needed the connection string to your backend instance. Backend doesn't run without that.

Cheers yashaswini

y-ashaswini avatar Oct 14 '23 05:10 y-ashaswini

Greetings. Needed the connection string to your backend instance. Backend doesn't run without that.

Cheers yashaswini

You can use the local mongodb server connection string (mongodb://localhost:27017) for development stage in your .env file.

moonpatel avatar Oct 14 '23 13:10 moonpatel

Greetings. Needed the connection string to your backend instance. Backend doesn't run without that.

Cheers yashaswini

Local instance does not works in docker containers though. If you are using docker containers you can setup a sample database on mongodb atlas for free.

moonpatel avatar Oct 14 '23 15:10 moonpatel

You can use this connection string mongodb+srv://moonpatel:[email protected]/ @y-ashaswini

moonpatel avatar Oct 15 '23 20:10 moonpatel

AH thank you tons @moonpatel . Will use this.

y-ashaswini avatar Oct 16 '23 07:10 y-ashaswini

@moonpatel , it looks like the 'save changes' button on the profile page isn't functioning very well. It gives an error saying 'user number so-and-so not found', though i've just successfully created a new user, and of course, the user exists since there is a username and a password. its only the first last names and the country, city names that i'm unable to set.

also, i figured out the instances of the chessbot setting it's elo rating, but not the user's default user elo rating. please point me towards the directory/ module in question!

thanks :)

y-ashaswini avatar Oct 17 '23 19:10 y-ashaswini

@moonpatel , it looks like the 'save changes' button on the profile page isn't functioning very well. It gives an error saying 'user number so-and-so not found', though i've just successfully created a new user, and of course, the user exists since there is a username and a password. its only the first last names and the country, city names that i'm unable to set.

also, i figured out the instances of the chessbot setting it's elo rating, but not the user's default user elo rating. please point me towards the directory/ module in question!

thanks :)

There seems to be some bug in the 'Save changes' button. I will open an issue for that later on. That page is only for adding additional details for the user.

Right now there is no ELO rating for the user. You just need to allow the user to set an ELO rating for the chessbot on the play with computer page. Add an input element with some ELO ratings options and below the choose color input element. Make sure to pull the changes before proceeding further.

image

moonpatel avatar Oct 17 '23 20:10 moonpatel

Hey @moonpatel , I've set up the rating bit, but haven't quite been able to test it because the computer never performs a move - black never moves if I choose white, is that an issue yet to be solved?

Also, there's a certain part in socket.js

socket.on('INIT', async (data) => { if(data.color === 'b') { console.log(data.color); const botMove = await nextMove({position:chess.fen()}); console.log({ from: botMove.substring(0, 2), to: botMove.substring(2) }); chess.move({from:botMove.substring(0,2),to:botMove.substring(2)}); setTimeout(() => { socket.emit("CHESS_BOT_MOVE",{from:botMove.substring(0,2),to:botMove.substring(2)}) }, 500); } });

where it performs this only when the color is black, but if the user chooses black, this would break down, won't it?

y-ashaswini avatar Oct 18 '23 18:10 y-ashaswini

In the sense, "nextMove" from chessbot.js never gets called, because the within socket.on("INIT", async(data)=>{...}) in socket.js, the async function and the await nextMove() part never runs ..!

y-ashaswini avatar Oct 18 '23 18:10 y-ashaswini

Hey @moonpatel , I've set up the rating bit, but haven't quite been able to test it because the computer never performs a move - black never moves if I choose white, is that an issue yet to be solved?

Also, there's a certain part in socket.js

socket.on('INIT', async (data) => { if(data.color === 'b') { console.log(data.color); const botMove = await nextMove({position:chess.fen()}); console.log({ from: botMove.substring(0, 2), to: botMove.substring(2) }); chess.move({from:botMove.substring(0,2),to:botMove.substring(2)}); setTimeout(() => { socket.emit("CHESS_BOT_MOVE",{from:botMove.substring(0,2),to:botMove.substring(2)}) }, 500); } });

where it performs this only when the color is black, but if the user chooses black, this would break down, won't it?

I solved that issue and merged it to the main branch you can pull it to see changes in your local branch. @y-ashaswini

moonpatel avatar Oct 18 '23 18:10 moonpatel

In the sense, "nextMove" from chessbot.js never gets called, because the within socket.on("INIT", async(data)=>{...}) in socket.js, the async function and the await nextMove() part never runs ..!

When the user starts playing the game a the client socket connects to the server socket and fires an INIT event which is caught by this event handler. This event hadler checks whether the player color is black and performs accordingly. You should try playing as black once. I have played as both black and white and it works fine.

moonpatel avatar Oct 18 '23 18:10 moonpatel

Are you still working on this @y-ashaswini ?

moonpatel avatar Oct 26 '23 19:10 moonpatel

Hey, yes, I was working on it, and I did set up parameters. But I hadn't been able to get the chessbot to run last week. I'll finish it up and push my changes in a few hours' time. Apologies for the delay, I got caught up in a few other things.

y-ashaswini avatar Oct 27 '23 11:10 y-ashaswini

Hey, yes, I was working on it, and I did set up parameters. But I hadn't been able to get the chessbot to run last week. I'll finish it up and push my changes in a few hours' time. Apologies for the delay, I got caught up in a few other things.

Ah no worries.

moonpatel avatar Oct 27 '23 21:10 moonpatel

Hey @moonpatel , I suppose you may pass on the issue to anyone else now, since for some reason all that I'd done is lost. I will have to do it from the beginning again, but that won't be convenient for anyone, so please go ahead and reassign it to someone else.

The next assignee can take a look at a few of the pointers I had developed upon, here:

player levels:

  { value: "1", label: "Novice (100 - 800)" },
  { value: "2", label: "Beginner (800 - 1200)" },
  { value: "3", label: "Intermediate (1200 - 1600)" },
  { value: "4", label: "Expert Level 1 (1600 - 1800)" },
  { value: "5", label: "Expert Level 2 (1800 - 1900)" },
  { value: "6", label: "Expert Level 3 (1900 - 2000)" },
  { value: "7", label: "Expert Level 4 (2000 - 2100)" },
  { value: "8", label: "Expert Level 5 (2100 - 2200)" },
  { value: "9", label: "Master Level 1 (2200 - 2300)" },
  { value: "10", label: "Master Level 2 (2300 - 2400)" }

(we could set the default value as level 2)

Parameters to set for each ELO level:

- Novice Player
Skill Level: 5
Depth: 8
Contempt: 10
UCI_LimitStrength: false
Approximate Elo Range: 100-800

- Beginner Player
Skill Level: 10
Depth: 12
Contempt: 15
UCI_LimitStrength: false
Approximate Elo Range: 800-1200

- Intermediate Player
Skill Level: 15
Depth: 14
Contempt: 20
UCI_LimitStrength: false
Approximate Elo Range: 1200-1600

- Expert Level 1
Skill Level: 17
Depth: 16
Contempt: 25
UCI_LimitStrength: false
Approximate Elo Range: 1600-1800

- Expert Level 2
Skill Level: 18
Depth: 18
Contempt: 30
UCI_LimitStrength: false
Approximate Elo Range: 1800-1900

- Expert Level 3
Skill Level: 19
Depth: 19
Contempt: 35
UCI_LimitStrength: false
Approximate Elo Range: 1900-2000

- Expert Level 4
Skill Level: 20
Depth: 20
Contempt: 40
UCI_LimitStrength: false
Approximate Elo Range: 2000-2100

- Expert Level 5
Skill Level: 20
Depth: 20
Contempt: 45
UCI_LimitStrength: false
Approximate Elo Range: 2100-2200

- Master Level 1
Skill Level: 20
Depth: 20
Contempt: 50
UCI_LimitStrength: false
Approximate Elo Range: 2200-2300

- Master Level 2
Skill Level: 20
Depth: 20
Contempt: 55
UCI_LimitStrength: false
Approximate Elo Range: 2300-2400

To set the elo ratings, modify mainly (append this below the color choice dropdown menu)

/frontent/Computer.jsx 

<Select
        defaultValue="2"
        my="20px"
        color="lime"
        name="rating"
        label={
	        <Text mx="auto" order={3}>
		        Select your rating
	        </Text>
        }
        placeholder="choose your color"
        data={[
	        { value: "1", label: "Novice (100 - 800)" },
	        { value: "2", label: "Beginner (800 - 1200)" },
	        { value: "3", label: "Intermediate (1200 - 1600)" },
	        { value: "4", label: "Expert Level 1 (1600 - 1800)" },
	        { value: "5", label: "Expert Level 2 (1800 - 1900)" },
	        { value: "6", label: "Expert Level 3 (1900 - 2000)" },
	        { value: "7", label: "Expert Level 4 (2000 - 2100)" },
	        { value: "8", label: "Expert Level 5 (2100 - 2200)" },
	        { value: "9", label: "Master Level 1 (2200 - 2300)" },
	        { value: "10", label: "Master Level 2 (2300 - 2400)" },
        ]}
/>

And modify the ELO ratings settings under INIT in :

/backend/socket.js

Thank you @moonpatel , I loved working my way around your repository, I really appreciate your coding practices. Cheers, and best of luck!

y-ashaswini avatar Oct 28 '23 07:10 y-ashaswini