How do I create a simple Sudoku?

Get help using Construct 2

Post » Fri Jun 20, 2014 6:42 am

Hi,

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

Thank you :)
B
15
S
3
G
5
Posts: 396
Reputation: 4,977

Post » Fri Jun 20, 2014 8:33 am

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.

arrayfor.jpg


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

Thanks for any help getting behind the logic.
You do not have the required permissions to view the files attached to this post.
B
15
S
3
G
5
Posts: 396
Reputation: 4,977

Post » Fri Jun 20, 2014 9:19 am

Upload your capx, we don't have nearly enough information to work with
B
6
S
2
Posts: 79
Reputation: 608

Post » Fri Jun 20, 2014 9:36 am

here it is, but its useless. I am still working on the first step which is setting the array values.

appended.capx
You do not have the required permissions to view the files attached to this post.
B
15
S
3
G
5
Posts: 396
Reputation: 4,977

Post » Fri Jun 20, 2014 10:24 am

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.
B
6
S
2
Posts: 79
Reputation: 608

Post » Fri Jun 20, 2014 10:36 am

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.
B
15
S
3
G
5
Posts: 396
Reputation: 4,977

Post » Fri Jun 20, 2014 11:16 am

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
B
6
S
2
Posts: 79
Reputation: 608

Post » Fri Jun 20, 2014 3:59 pm

Exactly. Is there any way to get this check for the Y-Axis?
B
15
S
3
G
5
Posts: 396
Reputation: 4,977

Post » Fri Jun 20, 2014 11:08 pm

xeed wrote: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)
B
6
S
2
Posts: 79
Reputation: 608

Post » Sat Jun 21, 2014 4:57 am

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

I dont know the internals of lastIndexOf expression to use for the Y-axis.
B
15
S
3
G
5
Posts: 396
Reputation: 4,977

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 42 guests