FUNCTION C_ACTION(aSudoku, nRPos, nCPos, nNumber)
LOCAL nBlock := 0, nPos := 0
IF EMPTY( aSudoku[nRPos][nCPos] )
aSudoku[nRPos][nCPos] := nNumber // nNumber = selected number
// MsgAlert( "Row : " + ALLTRIM(STR(nRPos)) + CRLF + ;
// "Col : " + ALLTRIM(STR(nCPos)), "Position" )
IF nRPos < 4 // BLOCK 1- 3
IF nCPos < 3
nBlock := 1
nPos := GET_POS( nRPos, nCPos, 1, 1 ) // Row, Col
ELSEIF nCPos > 3 .and. nCPos < 7
nBlock := 2
nPos := GET_POS( nRPos, nCPos, 1, 4 )
ELSEIF nCPos > 6
nBlock := 3
nPos := GET_POS( nRPos, nCPos, 1, 7 )
ENDIF
ELSEIF nRPos > 3 .and. nRPos < 7 // BLOCK 4- 6
IF nCPos < 3
nBlock := 4
nPos := GET_POS( nRPos, nCPos, 4, 1 )
ELSEIF nCPos > 3 .and. nCPos < 7
nBlock := 5
nPos := GET_POS( nRPos, nCPos, 4, 4 )
ELSEIF nCPos > 6
nBlock := 6
nPos := GET_POS( nRPos, nCPos, 4, 7 )
ENDIF
ELSEIF nRPos > 6 // BLOCK 7- 9
IF nCPos < 3
nBlock := 7
nPos := GET_POS( nRPos, nCPos, 7, 1 )
ELSEIF nCPos > 3 .and. nCPos < 7
nBlock := 8
nPos := GET_POS( nRPos, nCPos, 7, 4 )
ELSEIF nCPos > 6
nBlock := 9
nPos := GET_POS( nRPos, nCPos, 7, 7 )
ENDIF
ENDIF
//MsgAlert( "Block : " + ALLTRIM(STR(nBlock)) + CRLF + ;
// "Pos : " + ALLTRIM(STR(nPos)), "Position" )
ENDIF
RETURN(NIL)
// -------
FUNCTION GET_POS( nRPos, nCPos, nRow, nCol )
LOCAL nPos := 0 // calculated position inside the block-matrix 3x3
//MsgAlert( "Click Row : " + ALLTRIM(STR(nRPos)) + CRLF + ;
// "Click Col : " + ALLTRIM(STR(nCPos)) + CRLF + ;
// "Top Block Row : " + ALLTRIM(STR(nRow)) + CRLF + ;
// "Left Block Col : " + ALLTRIM(STR(nCol)), "Click Position" )
IF nRPos = nRow .and. nCPos = nCol
nPos := 1
ELSEIF nRPos = nRow .and. nCPos = nCol + 1
nPos := 2
ELSEIF nRPos = nRow .and. nCPos = nCol + 2
nPos := 3
ELSEIF nRPos = nRow + 1 .and. nCPos = nCol
nPos := 4
ELSEIF nRPos = nRow + 1 .and. nCPos = nCol + 1
nPos := 5
ELSEIF nRPos = nRow + 1 .and. nCPos = nCol + 2
nPos := 6
ELSEIF nRPos = nRow + 2 .and. nCPos = nCol
nPos := 7
ELSEIF nRPos = nRow + 2 .and. nCPos = nCol + 1
nPos := 8
ELSEIF nRPos = nRow + 2 .and. nCPos = nCol + 2
nPos := 9
ENDIF
// MsgAlert( nPos, "Block Position" )
RETURN nPos
Marcelo Via Giglio wrote:Holo,
many years ago (2006) I started to do a Sudoko game, to solve and generate, it can be resized, and accept right mouse click to mark possible solution, you can fill all without use the keyboard (using the numbers in the bar).... it is a early version maybe you can use it and improve
https://app.box.com/s/7j5584ob8fgvfek25a2is9krnsso9zpo
saludos
Marcelo
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 46 guests