1. Hey! Guest! The 34th GMC Jam will take place between August 22nd, 12:00 UTC (Thursday noon) and August 26th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

Binairo Board

Discussion in 'Programming' started by Ax8472, Aug 12, 2019.

  1. Ax8472

    Ax8472 Member

    Joined:
    Jul 15, 2016
    Posts:
    72
    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!
     
  2. Ido-f

    Ido-f Member

    Joined:
    Feb 19, 2018
    Posts:
    117
    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.
     
    Ax8472 likes this.
  3. Alexx

    Alexx Member

    Joined:
    Jun 21, 2016
    Posts:
    413
    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.
     
    Last edited: Aug 12, 2019
    Ax8472 likes this.
  4. curato

    curato Member

    Joined:
    Jun 30, 2016
    Posts:
    326
    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.
     
    Ax8472 likes this.
  5. Ax8472

    Ax8472 Member

    Joined:
    Jul 15, 2016
    Posts:
    72

    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.
     
  6. Alexx

    Alexx Member

    Joined:
    Jun 21, 2016
    Posts:
    413
    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: Aug 18, 2019
    Ax8472 likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice