Hey Guys,
New Member here.
I just completed the beginner series and wanted to make sudoku game
I use the cursor from TicTacToe
But I have problems in converting from cursor's x and y to index number.
I have attached my Project, please go through it tell me the Problem and Solution.
Thanks in Advance,
Shivam
Sudoku Problem
- bshivam2001
- Posts: 214
- Joined: July 27th, 2013, 6:57 am
- Location: India
Sudoku Problem
- Attachments
-
- Sudoku.rar
- (53.9 KiB) Downloaded 163 times
'If you can't make it good, at least make it look good'
Re: Sudoku Problem
x would pretty much be equal to index % <num per row> (which would be any number between 0 and <num per row>) and
y would be equal to index / <num rows> (which would be any number between 0 and <num rows>)
so to convert x and y to index you just reverse the operation, multiply y by <num per row> and add x
y would be equal to index / <num rows> (which would be any number between 0 and <num rows>)
so to convert x and y to index you just reverse the operation, multiply y by <num per row> and add x
always available, always on, about ~10 years c/c++, java[script], win32/directx api, [x]html/css/php/some asp/sql experience. (all self taught)
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat --
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat --
Re: Sudoku Problem
Yep, LuisR14 is right.
For example, with cX = 1 and cY = 5 you would be at the index 5*9 + 1 into your board.
Anyways, if you still find this unintuitive you should consider using a bidimensional array instead (a matrix). Something like this: Board[x][y];
For example, with cX = 1 and cY = 5 you would be at the index 5*9 + 1 into your board.
Anyways, if you still find this unintuitive you should consider using a bidimensional array instead (a matrix). Something like this: Board[x][y];
- bshivam2001
- Posts: 214
- Joined: July 27th, 2013, 6:57 am
- Location: India
Re: Sudoku Problem
Thank You LuisR14 and clau007.
I'll try this method.
By the way, i tried using a multi-dimensional array but I got some error. So I switched to one dimensional array.
Anyways, thank you once again
Regards,
Shivam
[EDIT]
The way you told didn't work. The cX and cY got swiched somehow.
So, I am using board[9][9] right now.
I'll try this method.
By the way, i tried using a multi-dimensional array but I got some error. So I switched to one dimensional array.
Anyways, thank you once again
Regards,
Shivam
[EDIT]
The way you told didn't work. The cX and cY got swiched somehow.
So, I am using board[9][9] right now.
'If you can't make it good, at least make it look good'
Re: Sudoku Problem
actually he did say it right , your brain must've somehow read it backwards
in 5*9 + 1, 5 is cY and 1 is cX and 9 would be the board width
in multi-dim array you would only have to use [cX][cY]
in 5*9 + 1, 5 is cY and 1 is cX and 9 would be the board width
in multi-dim array you would only have to use [cX][cY]
always available, always on, about ~10 years c/c++, java[script], win32/directx api, [x]html/css/php/some asp/sql experience. (all self taught)
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat --
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat --
Re: Sudoku Problem
Or just say the formula: "index = y * width + x", as in "index = multiple of rows so far and add the X offset"
ʕ •ᴥ•ʔ
Re: Sudoku Problem
yea we intellectual types seem to over-complicate the way we explain stuff
always available, always on, about ~10 years c/c++, java[script], win32/directx api, [x]html/css/php/some asp/sql experience. (all self taught)
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat --
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat --