MV Trying to make a chess engine

I know, I know... I am not by far the first one who is attempting this... But the requests about this keep on coming and.. Well... Someone has to follow up on this! What I am talking about? A chess engine of course!

Chess.gif


I am not sure if there has been a successful chess engine in RPG maker yet, but if there is, I couldn't find them. (And believe me, I've been looking. Because, to be honest, this is waaaaaaaaaaaaay too much work for my taste! Haha.) So, since it seems like there is no complete chess system for RPG maker yet, I will make one! Or at least, I amgoing to try...

And if I can pull it off, I will (most likely) share it will all of you!

I still have plenty to do, but... It kind of starts to look like a real chess game! How about that?

At first I will attempt a player vs player mode, since this will spare me the hassle of an AI... But if I can even do it, then after the PvP mode, I might attempt a real chess AI.

For now, a PvP mode is enough challenge for me, though.

Oh, and not only will it be PvP, it will actually be hot-seat pvp. So both players play on the same system.
I would love to be able to have 2 players play over the internet, but... uhm... I don't know how. 😉

For now it is mostly a wild idea, but hopefully soon I can show you all my very own chess engine for MV! And if I can... I'll teach all of you how to make one yourself!

Edit: I made a new full thread in the forum for completed games, since this is no longer just an idea.
I'm so tempted to offer you a friendly rivalry on this to compete for the best chess system. 😛
I'm so tempted to offer you a friendly rivalry on this to compete for the best chess system. 😛
Honestly, if you think you can pull it off, go for it! 😀 I did not invent chess, and well... plenty of RPG maker users have asked for it over the years.

I won't make this into a competition, though. Because... well... Because, I am pretty sure (like 99%) that I can do it. It just might take me a very, very long time. 😛 I don't think I can have this done in a weekend. And then I am not even thinking of animations and stuff. 😛

But just because I won't do it as a competition, doesn't mean I wouldn't love to see if you can do it, and how you would. I'd say: Go for it! Maybe, if one of us gets stuck halfway trough, we can even help each other out.
creating the base of chess is easy, making to work with AI is the hardest
to do, specially with all the pieces on it.

there is 1 or 2 that wanted to make a mini game, but it's to hard to create
the AI and movement and when and how for each mark on the board.

but if you manage it, you would be the first one in succeeding it 🙂
but I'm also curious how far you can make it to work 🙂
I don't think the AI is the hardest part though... Well, the thing that I struggle with most is: How do I prevent pieces to move, while other pieces are in the way?

For example, Rook on A1 to D1, should be impossible when there is a piece on B1 or C1.

Once I tackle that problem, the AI wouldn't be too bad. Well... For a simple game that is. I will surely not be making an AI that can think 3 or more steps ahead. 😛 Haha. I could make a simple AI, but not a chess computer.

EDIT: Oh, another think I might have a problem with, is the system recognizing check and checkmate. 😛
I don't think the AI is the hardest part though... Well, the thing that I struggle with most is: How do I prevent pieces to move, while other pieces are in the way?

For example, Rook on A1 to D1, should be impossible when there is a piece on B1 or C1.

Once I tackle that problem, the AI wouldn't be too bad. Well... For a simple game that is. I will surely not be making an AI that can think 3 or more steps ahead. 😛 Haha. I could make a simple AI, but not a chess computer.
Oh, i think youre underthinking the AI of chess. 😀 Its hard man, really hard... alot of choices ect...
I actually wanted a few months back to make an chess event but when i thought further it just became clear that i wont do it, its just too much for eventing alone.

And funny enough, the problem youre stating there, that one never even came to mind for me, i was scared enough just thinking about an AI. ^^

Now, im asuming you want to do it with events alone, if you add scripting to the mix, im sure alot of things will be much easier.
Oh, i think youre underthinking the AI of chess. 😀 Its hard man, really hard... alot of choices ect...
I actually wanted a few months back to make an chess event but when i thought further it just became clear that i wont do it, its just too much for eventing alone.

And funny enough, the problem youre stating there, that one never even came to mind for me, i was scared enough just thinking about an AI. ^^

Now, im asuming you want to do it with events alone, if you add scripting to the mix, im sure alot of things will be much easier.
Oh no, I realize it is a tough cookie. It will be a challenge and I do not take it lightly. But I have made AI's before, for my card game and my board game. This one will be next level, but I have quite an idea on how to do it. It is a lot of work and I will make many mistakes before I get it right, but I am 99% sure I can do it. With a loooooooooooooooooooot of patience. 😛

But, I am not really about the AI for another reason also: I focus on PvP for now. 😛 Haha.

With eventing only? 😛 I do not know much javascript, but I will use things like arrays and complicated formula's. (I might not know javascript, but math is my gig.) 😛 Oh, and I will make use of yanfly plugins. I need those for things like click-trigger and move routes. 😛

So... No, not eventing only, I guess. But there is no chess plugin I can use (if so, I quit this project emidiately and download that plugin instead. Haha)
Oh no, I realize it is a tough cookie. It will be a challenge and I do not take it lightly. But I have made AI's before, for my card game and my board game. This one will be next level, but I have quite an idea on how to do it. It is a lot of work and I will make many mistakes before I get it right, but I am 99% sure I can do it. With a loooooooooooooooooooot of patience. 😛

But, I am not really about the AI for another reason also: I focus on PvP for now. 😛 Haha.

With eventing only? 😛 I do not know much javascript, but I will use things like arrays and complicated formula's. (I might not know javascript, but math is my gig.) 😛 Oh, and I will make use of yanfly plugins. I need those for things like click-trigger and move routes. 😛

So... No, not eventing only, I guess. But there is no chess plugin I can use (if so, I quit this project emidiately and download that plugin instead. Haha)
Well, then all i got to say, cant wait to see how you do it and wish you best of luck. 😀
For the AI I'd suggest an existing implementation, e.g. Stockfish.

For long moves you just need to check all tiles on the line, i.e. a loop. That should be easy enough, since everything's either horizontal/vertical or diagonal.
Well, then all i got to say, cant wait to see how you do it and wish you best of luck. 😀
IF I can actually do it. 😛


For the AI I'd suggest an existing implementation, e.g. Stockfish.

For long moves you just need to check all tiles on the line, i.e. a loop. That should be easy enough, since everything's either horizontal/vertical or diagonal.
You mean like an existing AI database? Hmmm... But to put that in my system, do I not have to have my engine made the same way as the engine the AI was made for?

Yeah, I think I have figured out how to recognize blocked moves... I numbered all my tiles So 1 row up would be ID - 10 and a column to the right would be ID +1.

So 1 step to the upper right would be ID -9 and upper left is ID -11. I can loop that till I either hit a piece or go off the board. So, that I think I got down. This does include the knights move, which is rather weird, but in my system it is -21, -19, -12, -8, +8, +12, +19 or +21. Only 8 tiles to land on, so that is rather easy.

(Btw, nice to see you here. 😛 I normally run into you on the steam fora when I need javascript help. 😛 )
IF I can actually do it. 😛



You mean like an existing AI database? Hmmm... But to put that in my system, do I not have to have my engine made the same way as the engine the AI was made for?

Yeah, I think I have figured out how to recognize blocked moves... I numbered all my tiles So 1 row up would be ID - 10 and a column to the right would be ID +1.

So 1 step to the upper right would be ID -9 and upper left is ID -11. I can loop that till I either hit a piece or go off the board. So, that I think I got down. This does include the knights move, which is rather weird, but in my system it is -21, -19, -12, -8, +8, +12, +19 or +21. Only 8 tiles to land on, so that is rather easy.

(Btw, nice to see you here. 😛 I normally run into you on the steam fora when I need javascript help. 😛 )
Huh, why 10 tho?
Chess boards got 8x8 tiles, so up would be 8, not 10.
Yes, you are right. But I also made tiles outside the board, which will block the players movement.

Otherwise, if a piece is on D8 (all the way to the right) and I want to move it one to the right, it ends up on the first tile of the next row, which would be C1. So, there is a virtual D9 and D0, which you can not land on, but are still checked by the engine.

edit: Also, that is much easier to calculate. +30 is 3 rows down, and -22 is to steps upper left. 😛 Much easier than - 18 is 2 steps upper left. 😛
So there will be a bit of JS to actually implement stockfish, it probably will be just setting up his ELO and then you input your board state to it, and it spits out its movement for you to mimic in yours. I guess you are doing all this by eventing? Maybe you can get a coder to make that translation for you using this https://github.com/nmrugg/stockfish.js/

But if you really want to build the AI, I would be using Minimax with pruning, not all chess engines uses that, but its probably the easiest to implement to some degree of success (stockfish uses the same logic). This one I would strongly recommend doing in JS, but the results are really good! Just an overview of how it works:

Minimax is used for zero-sum games, which is basically, when there is a winner, there is a loser, either you win, you draw or you lose and your opponent either loses, draws or wins respectively.

It basically checks if you can win on your turn, then it checks if your opponent can win on his next turn, then it checks all possible positions for how the future board will look and if there is someone winning or losing and so on. That is why in engines you can usually set up "depth". Depth would be how far the AI would make to have the board states.

Since in Chess the number of turns are incredibly large, no engine until today was able to "solve" chess, so they never reach the end of the depth. That means in all, for the AI to work nicely, it will need to evaluate the board state also to see if its future positions will be good or not, since it can't reach the end of the game.

This might look complex, and even programmers that never did this type of work thinks its a nightmare, but it isn't that hard to implement, what is hard is to evaluate the board state to apply the minimax, basically giving a rating if you are winning or if you are losing, because to do that, you need to play well the game and understand its concepts. When you are just above average like an ELO 1600 or something, you can already evaluate with somewhat precision if the board state looks favorable to white or black, when you can do that, the minimax is just making it all work together.
Yes, you are right. But I also made tiles outside the board, which will block the players movement.
In that case remember that a knight on an edge may jump over a 1-tile "off the board" border.
In that case remember that a knight on an edge may jump over a 1-tile "off the board" border.
That I do. 😛 I have 2 rows above and 2 rows under the board to prevent them falling off the table. Only one column left and right, because, the wai it sets up, it loops. (with 39 on the end of line line, and 40 on the beginning of the next)
1644080924926.png


So there will be a bit of JS to actually implement stockfish, it probably will be just setting up his ELO and then you input your board state to it, and it spits out its movement for you to mimic in yours. I guess you are doing all this by eventing? Maybe you can get a coder to make that translation for you using this https://github.com/nmrugg/stockfish.js/

But if you really want to build the AI, I would be using Minimax with pruning, not all chess engines uses that, but its probably the easiest to implement to some degree of success (stockfish uses the same logic). This one I would strongly recommend doing in JS, but the results are really good! Just an overview of how it works:

Minimax is used for zero-sum games, which is basically, when there is a winner, there is a loser, either you win, you draw or you lose and your opponent either loses, draws or wins respectively.

It basically checks if you can win on your turn, then it checks if your opponent can win on his next turn, then it checks all possible positions for how the future board will look and if there is someone winning or losing and so on. That is why in engines you can usually set up "depth". Depth would be how far the AI would make to have the board states.

Since in Chess the number of turns are incredibly large, no engine until today was able to "solve" chess, so they never reach the end of the depth. That means in all, for the AI to work nicely, it will need to evaluate the board state also to see if its future positions will be good or not, since it can't reach the end of the game.

This might look complex, and even programmers that never did this type of work thinks its a nightmare, but it isn't that hard to implement, what is hard is to evaluate the board state to apply the minimax, basically giving a rating if you are winning or if you are losing, because to do that, you need to play well the game and understand its concepts. When you are just above average like an ELO 1600 or something, you can already evaluate with somewhat precision if the board state looks favorable to white or black, when you can do that, the minimax is just making it all work together.
Wow, uhm... This is way above my paygrade. 😛 I hardly know anything about javascript. 😛 I see the files on github, but I have no idea what they are or what to do with them. 😛

I wish I could understand what it all meant, so I could use this. But in reality I have no clue where to start.

Just to be clear... This is the AI, right? For now I am first making it PvP. That way I can at least get the game mechanics going. I think I should be able to do that.
I would really love to use an actual AI, but then I really need some help putting it in my game. 😛
That I do. 😛 I have 2 rows above and 2 rows under the board to prevent them falling off the table. Only one column left and right, because, the wai it sets up, it loops. (with 39 on the end of line line, and 40 on the beginning of the next)
View attachment 215318


Wow, uhm... This is way above my paygrade. 😛 I hardly know anything about javascript. 😛 I see the files on github, but I have no idea what they are or what to do with them. 😛

I wish I could understand what it all meant, so I could use this. But in reality I have no clue where to start.

Just to be clear... This is the AI, right? For now I am first making it PvP. That way I can at least get the game mechanics going. I think I should be able to do that.
I would really love to use an actual AI, but then I really need some help putting it in my game. 😛
Oh yeah just for the AI haha, the PvP I think its all good the way you are making xD.

Its just that I saw you might be interested in making the AI, and Minimax is not a hard concept to understand. It might even be appliable via eventing, but with some limitations probably, but the concept of it is just awesome for board games in general :ywink: .

The stockfish I sent was more just if you get a coder that could put the commands in like plugin commands for you, if someone does it, then it should be easy to use it through eventing.
I actually made great progress today!! ALL the pieces are evented and tested! Not only that, I even managed to flip the board each turn (which added a couple more hours to the process...) The only thing still missing, is that the game does not yet recognize check or check-mate. That is really a challenge, but everything else is DONE!! I started 36 hours ago!

The game is finished and uploaded!
You can play it here:
https://johndoenews.itch.io/chess

Please let me know what you guys think of it!

I made a new full thread in the forum for completed games, since this is no longer just an idea.


Edit: Oops... Double post. I was excited and noticed after I clicked send. Sorry... Can't take it back now.
ah I can't castle 🙁

Anyway, nice work o/
ah I can't castle 🙁

Anyway, nice work o/
You're right. I forgot a few rules, and one of them is castling. 😛
I'll put those i soon, though.

Thanks for checking out the game.

I did make a new thread in the completed game section of the forum. Updates are put in there:

Original thread: https://forums.rpgmakerweb.com/threads/trying-to-make-a-chess-engine.144636/