Sudoku Problem

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
User avatar
bshivam2001
Posts: 214
Joined: July 27th, 2013, 6:57 am
Location: India

Sudoku Problem

Post by bshivam2001 » August 9th, 2013, 8:02 am

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
Attachments
Sudoku.rar
(53.9 KiB) Downloaded 163 times
'If you can't make it good, at least make it look good'

User avatar
LuisR14
Posts: 1248
Joined: May 23rd, 2013, 3:52 pm
Location: USA
Contact:

Re: Sudoku Problem

Post by LuisR14 » August 9th, 2013, 3:18 pm

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 :P
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 :mrgreen: --

clau007
Posts: 15
Joined: July 30th, 2013, 8:36 pm
Location: Italy

Re: Sudoku Problem

Post by clau007 » August 9th, 2013, 7:05 pm

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];

User avatar
bshivam2001
Posts: 214
Joined: July 27th, 2013, 6:57 am
Location: India

Re: Sudoku Problem

Post by bshivam2001 » August 10th, 2013, 7:30 am

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. :lol: :!:
'If you can't make it good, at least make it look good'

User avatar
LuisR14
Posts: 1248
Joined: May 23rd, 2013, 3:52 pm
Location: USA
Contact:

Re: Sudoku Problem

Post by LuisR14 » August 10th, 2013, 7:23 pm

actually he did say it right :P, your brain must've somehow read it backwards :lol:
in 5*9 + 1, 5 is cY and 1 is cX and 9 would be the board width :P
in multi-dim array you would only have to use [cX][cY] :P
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 :mrgreen: --

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: Sudoku Problem

Post by LuX » August 10th, 2013, 9:28 pm

Or just say the formula: "index = y * width + x", as in "index = multiple of rows so far and add the X offset"
ʕ •ᴥ•ʔ

User avatar
LuisR14
Posts: 1248
Joined: May 23rd, 2013, 3:52 pm
Location: USA
Contact:

Re: Sudoku Problem

Post by LuisR14 » August 11th, 2013, 1:04 am

yea we intellectual types seem to over-complicate the way we explain stuff :lol:
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 :mrgreen: --

Post Reply