discord-tictactoe icon indicating copy to clipboard operation
discord-tictactoe copied to clipboard

Option to choose how hard the game is

Open mnzasa-files opened this issue 3 years ago • 6 comments

is it possible to win vs the ki and how? can anyone explain me?

mnzasa-files avatar May 23 '21 21:05 mnzasa-files

Hello @mnzasa-files, In theory, the AI of the module is unbeatable, because I am using the Minmax algorithm under the hood. Check more on how this works here: https://www.neverstopbuilding.com/blog/minimax

I was thinking of adding levels of difficulty in the module (like an error rate). What do you think of that?

utarwyn avatar May 24 '21 10:05 utarwyn

Yes, It would nice when you can choose how Hard the game is.

mnzasa-files avatar May 24 '21 11:05 mnzasa-files

Hey! Apologies for reviving and old thread, however I'm interested in attempting to add in a failure rate, to customise difficulty. Where abouts would i need to add this? (what file, line, etc)

BamBoozledMC avatar Feb 08 '22 23:02 BamBoozledMC

Hello @BamBoozledMC, thank you for looking into this addition! But indeed it's not the simplest one..

AI algorithm is located in the AI.ts file inside the method called minimax, check the code here:

https://github.com/utarwyn/discord-tictactoe/blob/6d40d2d02de24b60968c61d134812e59e4a14732/src/tictactoe/AI.ts#L49-L88

I already tried to work on this (look into this commit: 93c00bd), but the algorithm is not easy so I'm really interested if you have an idea to add a notion of difficulty level in the Minimax algorithm.

utarwyn avatar Feb 10 '22 11:02 utarwyn

is this even possible to beat? i mean i have been trying for hours and i cant beat the bot.

gomarrota avatar Mar 06 '22 05:03 gomarrota

is this even possible to beat? i mean i have been trying for hours and i cant beat the bot.

I'm pretty much certain its not, I've tried for a while. I don't see much point in there being an ai that you can't beat - in a game where you're meant to try to win - other than for practice. I've found that raising the value of depth that's taken away (const deep = this.minimax(game, depth - 1, (0, Player_1.getOpponent)(player));) in the AI.js file to something higher than 1 but lower than 2 works. I've set it to - 1.55 and it seems to be pretty balanced betweeen ai wins, player wins and draws. Its not the best solution but it works

FaderR avatar Mar 11 '22 19:03 FaderR

And this feature is now available (YES!!) in both versions 3.2.0 (discord.js v13) and 4.1.0 (discord.js v14).

Use configuration key aiDifficulty to customize difficulty level of the bot! Check this PR to have more information on it 💯

ℹ️ Default value is still Unbeatable to do not break running bots.

npm project page: https://www.npmjs.com/package/discord-tictactoe Releases page: https://github.com/utarwyn/discord-tictactoe/releases

utarwyn avatar Jan 19 '23 19:01 utarwyn