• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Binairo Board

Ax209

Member
Hi everyone. I was wondering if anyone would be kind enough to help me with this headscratcher.

I'm looking to create a puzzle in my game. I've got most of it figured out, but I simply cannot find a way to randomly generate the puzzles from the get-go.

What I'm looking to do is create a table. For example 10 x 10. Each entry in the grid can either be a 1 or a 0, positive or neveative, red or blue, whatever. Each of the 100 cells needs to randomly be one or the other, with a few caveats.

1) Each row/column must have an even amount of zeros to ones.

2) Each column must be unique in it's order to other columns (or row if it is a row).

3) Each column/row much have no more than x (probably between 2 and 4) of the same colour in it's order.

I've had a look online for algorithms to create such a board, but I've been having no luck. I can obviously handcraft a few but nowhere near enough for the amount I'd need.

If anyone can help me with this, I'd be very appreciative! Thanks in advance!
 

Ido-f

Member
Probably someone could come up with a better way, but this might be ok:

Alongside the resulting ds_grid, keep a list of all cells yet to be set (each list entry can be a 2 sized array representing the grid coordinates of the cell, or you can keep 2 list entries for each cell).
Choose a random cell from this list and choose true or false randomly ( " = choose(true, false);" ).
Check if setting the cell to the chosen value would violate one of the rules.
If it won't, set it to that value and remove the cell from the list.
If it would, check if setting it to the other option violates on of the rules.
If it won't, set it and remove the cell from the list.
If it would violate one of the rules, then the cell can't be set, reset the grid and start over.
 

Alexx

Member
Sounds Fun!!
I'll try and make an example.

Will post back when done or when I admit defeat!

Edit:
Just to clarify:
1 Each row/column must have an even amount of zeros to ones.
By this you mean five each of 0 and 1?

3) Each column/row much have no more than x (probably between 2 and 4) of the same colour in it's order.
Probably? You need to decide on this, as I would approach this differently depending on value.
 
Last edited:

curato

Member
Honestly, if it was me I would go down your list. 1 if you want and even number of 1's and 0's just fill them in a fx way. then do a random shuffle per row and column to make sure it random. then check against 3 and see shuffle again if needed. Number 2 I am not 100% what you are trying to do but it sounds the pickiest. I would look at the uniqueness and move just the offending items. you could loop through again and make sure the corrections didn't make you violate the other rules. Making games like this on the fly are great but puzzles are hard because you are trading time with level design to time writing AI to do your level design.
 

Ax209

Member
uld go down your list. 1 if you want and even number of 1's and 0's just fill them in a fx way. then do a random shuffle per row and column to make sure it random. then check against 3 and see shuffle again if needed. Number 2 I am not 100% what you are trying to do but it sound
Sounds Fun!!
I'll try and make an example.

Will post back when done or when I admit defeat!

Edit:
Just to clarify:

By this you mean five each of 0 and 1?


Probably? You need to decide on this, as I would approach this differently depending on value.

Haha well I appreciate the attempt, friend.

The variations of this game include rules of 2 and 3 being the maximum you can have together, but without thinking about how anyone would perform this, I thought it might be possible to alter a variable in the code to determine the maxumum number of same-colours in a line, but honestly I'd be happy with each. I'm grateful you're even trying at all! You're far smarter than I!

And yes, each row and each column should have an even number of both 0's and 1's.
 

Alexx

Member
I'll give it some thought and give it a go tomorrow, it's getting late here.

Edit: Couldn't come up with anything worth sharing. I could only think of a brute force method, probably not what you are looking for.
 
Last edited:
Top