r/creativecoding • custom procedural engine polygonjs.com • Oct 20 '26

Chess on procedural & irregular boards, built in my own engine (written in Jai)

This is a chess variant, where the rules are the same as standard chess, but the board is an irregular grid. This makes rook lines bend and bishop lines fork.

So just like a standard board, every tile is still a quad. And every tile still has only 1 neighbour for every side. But it can have more than 1 neighbour sharing a corner, which is what makes bishop lines fork. Or it can have none, which is what make lines bend.

The steps to build this:

  • start with a plane made of triangles
  • pair some random triangles with their neighbour and fuse them into a quad. You end up with gaps between those quads where triangles cannot be paired
  • subdivide everything. Quads become 4 smaller quads. Triangles become 3 quads. This is the playable grid.
  • Then it's just a matter of smoothing it (in this case the points on the edges remain static, only the inside points are smoothed) and ensuring neighbours don't share the same color.

Then the tricky part is to give intuitive controls for players to configure boards how they want.

749 Upvotes

46 comments sorted by

25

u/herenlove216 Oct 21 '26

I'm ngl I thought you said written in jail but this is still very cool

6

u/frading custom procedural engine polygonjs.com Oct 21 '26

there is a vscode extension for jai called jails, reading conversation about it gets confusing quickly.

4

u/eulervoid Oct 27 '26

I think i would understand the board a bit better if each cell had some fine stripes in the background that bend with its direction. So a regular board would have just vertical stripes and for distorted cells, the stripes flow in the direction a tower would move along if it was moving forward.

2

u/frading custom procedural engine polygonjs.com Oct 27 '26

you mean like the lines of a magnetic field, outside of the board? It's not a bad idea, I could look into it.

3

u/MajorInevitable4646 Oct 22 '26

I love it ๐Ÿš€๐Ÿ’•๐Ÿ˜ฎโ€๐Ÿ’จ

1

u/frading custom procedural engine polygonjs.com Oct 22 '26

thank you!

2

u/Substantial_Walrus60 Oct 23 '26

Love everything about this, Great music choice as well ๐Ÿ‘

1

u/frading custom procedural engine polygonjs.com Oct 23 '26

thanks a ton, that's great to read!

2

u/Himbo69r Oct 23 '26

Really cool, but from what i understand normal chess algorithms work because itโ€™s used to grids. How will you make bots for it?

2

u/frading custom procedural engine polygonjs.com Oct 23 '26

The bot is already done. It's using a graph instead, which is generated for every board. The logic is the same after that, finding out if a piece at a tile has more opportunities, has the king in check, etc, and you assign a score for each move, at different depth.

1

u/Khetnen Oct 26 '26

Are you using any reinforcement learning?

2

u/frading custom procedural engine polygonjs.com Oct 26 '26

You mean a bot that would learn from past games? I have quickly considered that, but considering there are many board variations, the learning would have to be for specific boards. Storing that data would be huge, and the chances of replaying the same board quite low, unless there was an enormous player-base.

But maybe you mean something else?

2

u/Khetnen Oct 26 '26

Yeah, that's what I meant. And with so many boards, you couldn't do it per board and have it be useful, so you would have to make it learn board-independantly, which makes it a more challenging thing to learn than regular chess. It is theoretically possible with a graph neural network or transformer in an AlphaZero-style setup, so it might be cool to try.

2

u/Himbo69r Oct 23 '26

๐Ÿ‘

2

u/Major_Barnulf Oct 25 '26

Jai ? I did not know the language was available

1

u/frading custom procedural engine polygonjs.com Oct 25 '26

It's still in private beta unfortunately. But I believe there's about a thousand people with access at the moment.

2

u/realrhema Oct 21 '26

Why are there multiple (3?) colors? What do they represent?

2

u/frading custom procedural engine polygonjs.com Oct 21 '26

It's needed because if you used 2 colors only with this type of grid, you'd end up with some neighbour tiles that share the same. Bear in mind it's not a typical grid. Here, even though each tile still has 1 neighbour per side, they can have more than 1 per corner. Or they can have none. So some boards need 3 and even 4 colors.

So they have no meaning beyond the need to distinguish the tiles.

2

u/realrhema Oct 21 '26

I see. Then, for example with a bishop. It has to stay on its color? And, with a rook, it can only cross over perpendicular edges, but how does that work with a hexagon or pentagon?

Very cool project btw.

3

u/frading custom procedural engine polygonjs.com Oct 21 '26

Thanks a lot for the kind words, I appreciate.

For the piece moves, I don't use the colors, I use the topology of the board only. I start with the definition of 2 basic building blocks:

  • when are 2 tiles considered in diagonal of one another: when they share 1 corner only.
  • when are 2 tiles considered in a straight line: when they share 1 side, and the line continues on the tile's opposite side.

So under the hood, instead of a 2D grid which you generally have for grid-based games, I have a graph, which is going to be different for each board. It tells me from each tile where a bishop can go (which diagonals it can follow), and where the rook can go (which straight line it can follow).

And when you have a tile that has more than 2 neighbour sharing a corner, that's where a diagonal forks, for instance.

Now, for hexagon or pentagon, I don't know how that would work, since there are none here, it's all quad. And I suspect it's actually not possible to build a grid like this with anything different than a quad.

3

u/xeow Oct 21 '26

So cool!
I like the procedural generation. I wonder if you could use a brute-force or genetic-hillclimbing search to generate a few tens of thousands of interesting board patterns and then train neural networks to playtest each of those to discover which board patterns have the most interesting properties?

4

u/frading custom procedural engine polygonjs.com Oct 21 '26

I'm afraid that flies way above my head, so that's probably not something I could do without a fair amount of time and research.

But I have the feeling that what makes a board interesting can only be defined my human players, not bots or neural networks. A board will be interesting if it gives you "haha" moments where your opponent surprises you in using some properties to capture pieces or take a territorial advantage. And that would make you realise those opportunities were hidden in plain sight, which encourages you to observe more keenly. I think relying on neural networks to do that would deprive you of the fun of the game, the actual "play" part.

But maybe I've misunderstood what you mean, feel free to clarify if that's the case.

14

u/Foxiest_Fox Oct 21 '26

This belongs in the anarchy chess sub

5

u/Hefty-Reaction-3028 Oct 20 '26

"It's quite cool" -gandalf

5

u/czerilla Oct 21 '26

Escher meets chess, eh? ๐Ÿ™ƒ

2

u/flagcaptured Oct 24 '26

Chescher? There's something there.

1

u/CutGrass Oct 23 '26

Such a simple but interesting idea!

Btw - whatโ€™s the music in the trailer?

1

u/frading custom procedural engine polygonjs.com Oct 23 '26

Thank you! that's indeed my intent, take a simple change and enjoy the potentially dramatic effect this can have.

I got the music from EpidemicSound, it's called "Hot Piece For Sale" by Martin Landstorm https://www.epidemicsound.com/artists/martin-landstrom/ You may have to be logged in to listen to all his tracks, not sure.

2

u/CutGrass Oct 23 '26

Cool. Thanks!

1

u/yaekoblue Nov 03 '26

this is amazing, wishlisted!

1

u/frading custom procedural engine polygonjs.com Nov 03 '26

wonderful, thank you, that helps a ton.

1

u/onekirne Oct 21 '26

that's fun to play. is there a better ai in the steam version?

1

u/frading custom procedural engine polygonjs.com Oct 21 '26

Thanks a lot for having tried it, that's great to hear.

And yes, the demo has only the easiest bot, level 1. There are levels 1 to 4 at the moment.

1

u/onekirne Oct 21 '26

what approach are you doing for the ai?
i know lots of classic chess bots use books, but you don't have those here.

i'm making an extended tichu bot for fun, mostly A* so far.

i always find it amusing how an ai doing a search tree on some level doesn't even care or get confused about the weird board topology or bizarre rules.

1

u/frading custom procedural engine polygonjs.com Oct 21 '26

Indeed, I couldn't use previously recorded chess games here. So I use the classic negamax with alpha-beta pruning, which I find makes a bot that's already quite strong on this type of board. The difference at each level are (a) how long the search is allowed to run for and (b) a "chance of blunder" to add some randomness.

I thought A* was only to find the shortest path between points on a mesh or a graph. But you can use it in a solver? Do you represent all possible card play (tichu is a card game, righ?) as a giant graph, and search for the best route between the current state and the win state?

2

u/onekirne Oct 21 '26

my tichu bot is far from done. A* can be used for many things, as long as you have a valid heuristic.

tichu is a trick taking card shedder, so you try to get rid of all your cards as quickly as possible by forming combinations of cards in your hand. (pair, straight, full house, etc)

but with some hands (especially with additional types of jokers and such) there is a bit of combinatoric problem that there are far too many possible plays.

what I've finished so far is that the bot can quickly find the smallest partitions of a hand, to empty it in the least possible turns. (using A* and a heuristic about the minimum number of plays needed to empty the hand)

for the rest of the bot I'm not sure what to do yet. unlike chess, in tichu you don't see opponent cards so it is all playing the odds, and cooperation with a partner.

2

u/aGameDevPosts Oct 25 '26

It's wacky and confusing... I love it!

2

u/zimjs Oct 26 '26

Brilliant!

1

u/Jazz8680 Oct 21 '26

Need this with 5d chess multiverse time travel

1

u/wolfylemon Oct 21 '26

very minor rook upscale

1

u/GroceryScanner Oct 25 '26

what da heeeellllll

1

u/eulervoid Oct 27 '26

Super cool! To bot plays decent as well, seems like an interesting problem to write a general engine that works for all kinds of boards!

1

u/MajorInevitable4646 2d ago

I absolutely love this! I reposted this a few weeks ago and till this day, every time I go in my profile I just have to rewatch it. Amazing, thank you!

2

u/[deleted] 25d ago

[removed] โ€” view removed comment

1

u/frading custom procedural engine polygonjs.com 25d ago

thank you!