How do I create a simple Sudoku?

0 favourites
  • 12 posts
From the Asset Store
Background Story generation templates. See the Arcade demo.
  • Hi,

    what is the easiest way to compare all possible X and Y of a 9x9 array against each other with c2?

    Thank you

  • The actual problem is that a While under a For condition stops the For-Loop, in every case.

    I dont know if this a bug or my fault.

    [attachment=0:1ngqiysm][/attachment:1ngqiysm]

    Array is 9x9. So Textlenght (str(len(hud.Text)) for hud here should be 9 chars, but its only 1.

    Thanks for any help getting behind the logic.

  • Upload your capx, we don't have nearly enough information to work with

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • here it is, but its useless. I am still working on the first step which is setting the array values.

    [attachment=0:3atfazr1][/attachment:3atfazr1]

  • I'm guessing that what you're trying to do is create a solved Sudoku array by simply generating random numbers onto every position until they no longer conflict with the Sudoku rules.

    There's a whole bunch of problems with what you're doing.

    First, your While loop gets stuck whenever arrayXinc = Array.CurX and arrayYinc = Array.CurY, because the while condition tests if the array element is equal to itself (which of course is always true), so you get an infinite loop.

    Aside from that, generating a random number in a slot until it 'doesn't break the sudoku rules' and then moving to the next is not a valid Sudoku generating algorithm. You will undoubtedly reach a point where there is no possible number for the current slot. There are several Sudoku generating patterns out there that you can use, but in the mean time, I suggest you simply pick a set of pre-generated puzzles and store them statically in arrays. Work out the gameplay side of things first and then focus on how to generate your own puzzles. It's not a trivial matter.

  • Thank you. There is no need at performance; I just would like to kick this game as c2 capx - with a self-generated matrix.

    the loopindex in the last capx is set to -1, so it should always be the last value checked against the actual.

    At the moment, I think the best solution is "lastIndexOf", but this expression seems to checks the whole array; not only one dimension. I also cant find an example which shows how to use this expression correctly.

  • lastIndexOf gives you the X index of the last match of the value you are searching for.

    So, if your bidimensional array is

    1 2 1 2

    3 4 5 6

    7 2 1 5

    lastIndexOf(7) should return 0, because that is the X index of the last appearance of the value 7

  • Exactly. Is there any way to get this check for the Y-Axis?

  • Exactly. Is there any way to get this check for the Y-Axis?

    you can implement your own YIndexOf function and then call it in expressions with Function.Call("YIndexOf", Array.UID, element)

  • Thank you. But what should be done in this function?

    I dont know the internals of lastIndexOf expression to use for the Y-axis.

  • You can do a neater version of the function using the "Array -> For each XY element" condition instead of a nested for, but this way is more efficient because it loops backwards on the array and stops as soon as it finds the last element that matches your search.

    There's a slight problem with this however: this implementation assumes that rows have higher priority in the ordering of elements than columns. This means that in this array

    0 2 4

    3 5 2

    4 2 1

    The 'last' 2 would be the one on (1,2), and so LastYIndexOf(2) would return 2

    While if you gave higher priority to columns, the last element would actually be the 2 on (2,1) and so LastYIndexOf(2) would return 1

    You have to take this into consideration when filling your array. It's not a big problem though, since general convention is to give rows higher priority anyways.

  • Thank you very much.

    Edit: this event is checking the whole array instance here, not the rows & the columns seperated - the main problem remains.

    For Sudoku I need to check for same values each row and column - itself.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)