How do I make a Moving Unpredictable Chess Piece?

Hi, So I am trying to make a AI Chess Game but I don’t know how to script it. So I started on making the Rook and finished modeling it. But I ran into the problem of I don’t know how to make it move. So I want it to move like a actual Rook moves (Vertically and Horizontally) but I also want it to move unpredictable but not move off the board. So my question is, is there anyway to do that.

Here is a picture of the Rook:

To do this you would have to give your chess AI a mental map of the available tiles. You would then have to calculate it’s options by checking for vacant spaces that can be reached with that specific piece( in
the rook’s case, all spaces horizontal and vertically that aren’t blocked by another piece ).

In terms of choosing a square, you could either do it by random, or use something like a neural network to create a smart AI that plays based off of training. This can get very complicated though, and I would only recommend it if you are willing to take the time to study it.
Here is a great roblox resource on that:

You should definitely give the topic of “chess AI” a Google, as I found quite a few topics on this subject elsewhere.

Here is one article I found that contains some useful information:

Hopefully this is helpful!


Thanks, can you explain it to me like I am a 5 year old not knowing how to script and even do multiplication?

I really wish I could help you further, but I don’t know if I can, as I have not deeply studied the subject.

Unfortunately, I doubt there I anything available for you to just copy and paste over, so you would have to do the research to put it together yourself. The best advice I can give you is to just do some googling and see if you can figure stuff out one step at a time.

Just a heads up though, that if you do go for the neural network approach it’s optimal to be sufficient in calculus.

Ok thanks, I will look into the Neural Networks thing.

Maybe use math.random? Or you can implement some game logic which changes a piece’s moves based on the player’s move. I would use raycasting to see if there is a piece around another piece.

Actually there was a tutorial on Free code camp too, and you will have to spend some time for it, learning and understanding how the algorithm works. Otherwise I don’t think its possible so easily.

Also this is off topic, but isn’t Devforum only for 13+…

A chess Board is a 8 by 8 grid.
This means you can create a 8 by 8 table that will hold the pieces positions.

When moving pieces you can make a list of table points it can move to.
for example a castle moves straight: {{1,0},{2,0},{0,1},{0,2}} and so on
while a bishop can move diagonally: {{1,1},{2,2},{-1,-1}}

You will have to check for ocupied squares along its path.
So from the pieces current grid position you can add the point from its movement array so if the castle was at {3,4} and it picked {0,2} as the movement it would then be at {3,6}. You would have to check the point to ensure it is within the 8 by 8 grid before allowing it to move. If it isn’t within the 8 by 8 grid it is not a valid move.

This means you could actually make a better AI that could allow it to check for pieces that it can take and perhaps further on even predict future moves.

1 Like

It is for only 13 years old but I said “Could you explain it to me like I am 5 years old” To try and make it more understanding to me.

Don’t drag yourself for it, neural networks are extremely complicated and require a lot of practice and learning, I’m an advanced scripter and I struggle to understand it. Just be patient, keep your head up, and keep trying until you master it. The only way to learn something is to try and never give up. :slight_smile:

Sorry if this come off as motivational fluff, but it’s honestly try the truth, complicated subjects don’t come instantaneously

Well i don’t recommend making a AI as that too advanced for your level, i would really recommend gnomecode (youtuber) or something, and then do it more simple like a player 1v1. If you watch it carefully and understand everything you will understand that:
I’m making a chess game for almost a month from now. So i recommend making a raycast to select pieces, and using and abusing canquery, so you use the raycast to check if the part is parent of a piece and if it has been clicked, if yes then that’s the selected piece, then clone it, make a for i statement and pass by all parts to make them a different material or something. Then you turn off cancollide and canquery in all pieces and with that selected piece make it appear by positioning it on the square with the humanoidrootpart. then you can check if the player clicks and if he does the piece moves there, as you won’t be changing the selected piece that i told up. That’s the basic, then for the limitations it’s another thing