How would I make an NPC which can make chess moves depending on opponent's moves?

  1. What do you want to achieve?
    An NPC who is intelligent and can make chess moves, similar to a real life person.

  2. What is the issue? Include screenshots / videos if possible!
    I don’t know if this is possible for Roblox.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have only been thinking of solutions. My most reasonable one is to classify moves and act accordingly. E.g. if a pawn moves, the system classifies it as development, and thus develops its own pieces. If a knight moves in to attack, it classifies it as an attack and then reacts. My second solution, which is easier, is to make such an algorithm, that is successful no matter what, which is easy to make, but hard to think of.

I want to listen to what the community thinks and how people would actually achieve this.
Maybe connect it with a player from another server with the same rating? My second idea isn’t very good because an algorithm is not flexible and its like playing blindfolded. People can also make use of the fact that the system is not noting its surroundings.

For something like this you could assign a score to each piece and a score to each movement point.

When it’s the AI’s turn you go through all possible moves and choose the one with the highest score.

For example:
Move Pawn: +1 movement score
Knight takes Bishop: +3 Movement score, +4 Capture Bishop score
Queen moves to Check: +2 Movement score, +1 Check score

So in this case the AI would use it’s knight to take the bishop.

You would probably need to run this through at least 2 layers to work well. (So for each possible move you run all the possible subsequent moves in the next turn and use the move that can provide the highest outcome of score.)

There are many articles and videos online relating to making an AI that plays chess, and most of those solutions will also be possible in Roblox!

1 Like

Thank you! This is a very smart idea. This is quite applicable because of the limited options that chess pieces typically have. I’ll have to play more chess and check out a few articles! Thanks! Besides this idea. If anybody has any other ideas to how I could achieve this, please send them!

1 Like

adding a bit here as well, this is not LUA, but someone named “Code Bullet” made a decent chess ai from scratch

1 Like

Oh thanks! I’ll certainly watch it!