News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

sudoku avatar creator

Started by zedd151, April 30, 2024, 08:05:44 AM

Previous topic - Next topic

zedd151

#15
Added puzzle file loading and keyboard presses.
If a wrong value is entered, the background for the cell turns red indicating error.
Still a work in progress, a lot more work to be done.

In the current menu, there is "Reset Game". Actually to reset the game, simply reload it. I will put "Undo Last"(move) in its place, to undo the last move if an invalid move was flagged (red background).
Also right now the solution is hard coded, I may put a simple 'validator' in it to check for valid moves, instead of keeping the solution lying around.
latest version attached in post #1

zedd151

#16
I am currently playing around with testing "autoprint" to generate the bitmap automatically when a digit is placed - bypassing the need to click "Print Frame" for each frame. It needs a couple more tweaks... (currently also captures the 'selection' bg color which I don't particularly like)
latest version attached in post #1

Further notes...
Originally if a given digit is invalid in a cell, I allowed placing it but colored the background of the invalid cell red. Instead I will disallow placing an invalid digit into a cell. For normal game play, the red bg is okay, but since I am using the program to make bitmap frames for an avatar I will make the program more optimal for that need.

Once I have the program optimized for creating my avatars, I will release a playable version with some features that are better suited for playing the game of sudoku. (Time permitting, of course)

sinsi

Tried v3, clicking selected a cell but pressing keys did nothing, and the Load menu just blacked out the whole grid then crashed.
Faulting application name: lil_sudoku.exe, version: 0.0.0.0, time stamp: 0x66331c31
Faulting module name: USER32.dll, version: 10.0.22621.3447, time stamp: 0x1cb963cd
Exception code: 0xc000041d
Fault offset: 0x0002eb76
I'll rebuild it as debug and see what triggers it.
🍺🍺🍺

sinsi

You might be having trouble with EDX here
    lea edx, [ecx+eax]
    invoke SetBkMode, DC, TRANSPARENT
    invoke DrawText, DC, addr str1, 1, edx, DT_CENTER or DT_VCENTER
SetBkMode will likely trash EDX but you use it in DrawText.
🍺🍺🍺

zedd151

#19
Quote from: sinsi on May 02, 2024, 03:01:37 PMTried v3, clicking selected a cell but pressing keys did nothing, and the Load menu just blacked out the
is the file 'game.txt' in the same folder as the executable? It must be in the same folder as the executable. Also, the keys will not work if a game is not loaded first. I have been testing that program for quite some time, and have not had the issues that you are having.

Quote from: sinsi on May 02, 2024, 03:21:21 PMYou might be having trouble with EDX here
Now this I can fix... an oversight on my part

latest version attached in post #1

sinsi

game.txt, no games.txt

It's the EDX that makes DrawText fail.
🍺🍺🍺

zedd151

#21
Quote from: sinsi on May 02, 2024, 03:32:42 PMgame.txt, no games.txt
was a typo..
QuoteIt's the EDX that makes DrawText fail.
latest version attached in post #1

sinsi

No crashes now, but how do I replace what's in the selected cell? Related to that, for the game itself, there should be no indication that you've entered an incorrect number otherwise all you need to do is try every number until the red disappears  :biggrin:

If you're trying to get the window to exactly fit the client area (your CenterWindow), I recently found AdjustWindowRectEx.

On my 4K monitor the game is tiny :badgrin:
🍺🍺🍺

zedd151

#23
@ sinsi:
It's not really a game per se, but my avatar creator - hence the thread title.
Yes it is tiny. 127x127... avatar sized (the sudoku board, anyway)

This project is still under development (and may still contain some unnoticed errors)
Thanks for your feedback. Do you have any other suggestions?

As far as replacing an invalid digit, don't make mistakes and you won't have to replace any invalid digits. :tongue: there is no undo function (will be, maybe in the near future)

You can always cheat and look at my avatar. :biggrin: until I change it, that is...

It's not perfect, but it works for what I need it to do. :smiley:

zedd151

#24
From now on, instead of keeping previous versions attached within their respective posts, I have decided to only have the latest version attached to post #1
When I make a post announcing some change to the program, that new version will be attached to post #1, and any prior versions removed.

zedd151

I have been thinking....

Since I am developing this little toy concurrently with the continuing development  of my sudoku GUI, why not do them within the same program... some of the code is already shared between them.

The avatar creation stuff would be done in a separate DC and not visible in the sudoku GUI. It seems that it should be 'doable'... I will run some tests later this evening (my time, it's noon here right now)...

The sudoku GUI btw, will not be posted until it is finished for those who might be interested. Please be patient. :azn:

zedd151

#26
Found an erroneous piece of code when trying to capture a portion of the client area starting at another position other than 0, 0 in the "DCbmptoFile" procedure.
It kept on capturing with results that I did not expect.
First, I had mislabeled the calculated height and width as 'xx' and 'yy'. Now changed those to ww and hh respectively.
xx and yy are now the origin x and y.
Next, I had forgotten to address the source DC's origin during BitBlt (was hard coded at 0, 0)

original code:
        mov ecx, lprct
    assume ecx:ptr RECT  ;; set bitmap height & width from lprct (passed argument)
    mov eax, [ecx].right
    sub eax, [ecx].left
    mov xx, eax
    mov eax, [ecx].bottom
    sub eax, [ecx].top
    mov yy, eax
    assume ecx:nothing
   
    invoke CreateCompatibleBitmap, hDC, xx, yy
    mov hBmp, eax
    invoke SelectObject, tempDC, hBmp
    mov hOld, eax
    invoke BitBlt, tempDC, 0, 0, xx, yy, hDC, 0, 0, SRCCOPY
   
Which worked fine, as long as the origin was "0, 0" as in the lil_sudoku program.

Fixed the error, to have the origin anywhere within the client area:
        mov ecx, lprct
        assume ecx:ptr RECT  ;; set bitmap height & width from lprct (passed argument)
        mov edx, [ecx].left
        mov xx, edx
        mov eax, [ecx].right
        sub eax, edx
        mov ww, eax
        mov edx, [ecx].top
        mov yy, edx
        mov eax, [ecx].bottom
        sub eax, edx
        mov hh, eax
        assume ecx:nothing
        invoke CreateCompatibleBitmap, hDC, ww, hh
        mov hBmp, eax
        invoke SelectObject, tempDC, hBmp
        mov hOld, eax
        invoke BitBlt, tempDC, 0, 0, ww, hh, hDC, xx, yy, SRCCOPY

:smiley:

The full procedure:  :wink2:
;; converted to 32 bit by zedd151, from a 64 bit screen capture tool by Vortex.
;; modified by sudoku.

    DCbmptoFile proc hDC:dword, lprct:dword, lpOut:dword  ;; lpout is the output file name for the bitmap.
    local hBmp:dword, hOld:dword, tempDC:dword, ww:dword, hh:dword, xx:dword, yy:dword
    local hFile:dword, BmpSize:dword, SizeofDIB:dword, BWritten:dword, Bits:dword, pMem:dword
    local bm:BITMAP, BmpFileHdr:BITMAPFILEHEADER, BmpInfoHdr:BITMAPINFOHEADER
        push esi
        push edi
        push ebx
        push edx
        push ecx
        xor eax, eax
        lea edi, bm
        mov ecx, sizeof BITMAP
        rep stosb
        xor eax, eax
        lea edi, BmpFileHdr
        mov ecx, sizeof BITMAPFILEHEADER
        rep stosb
        xor eax, eax
        lea edi, BmpInfoHdr
        mov ecx, sizeof BITMAPINFOHEADER
        rep stosb
        lea edi, bm
        invoke CreateCompatibleDC, hDC
        mov tempDC, eax
        mov ecx, lprct
        assume ecx:ptr RECT  ;; set bitmap origin (xx, yy), height & width (hh, ww) from lprct (passed argument)
        mov edx, [ecx].left
        mov xx, edx
        mov eax, [ecx].right
        sub eax, edx
        mov ww, eax
        mov edx, [ecx].top
        mov yy, edx
        mov eax, [ecx].bottom
        sub eax, edx
        mov hh, eax
        assume ecx:nothing
        invoke CreateCompatibleBitmap, hDC, ww, hh
        mov hBmp, eax
        invoke SelectObject, tempDC, hBmp
        mov hOld, eax
        invoke BitBlt, tempDC, 0, 0, ww, hh, hDC, xx, yy, SRCCOPY
        invoke GetObject, hBmp, sizeof(BITMAP), edi
        mov BITMAP.bmBitsPixel[edi], 24
        xor edx, edx
        movzx eax, BITMAP.bmPlanes[edi]
        mul BITMAP.bmBitsPixel[edi]
        mov Bits, eax
        lea ecx, BmpInfoHdr
        mov BITMAPINFOHEADER.biSize[ecx], sizeof(BITMAPINFOHEADER)
        mov eax, ww
        mov BITMAPINFOHEADER.biWidth[ecx],eax
        mov eax, hh
        mov BITMAPINFOHEADER.biHeight[ecx],eax
        mov ax,BITMAP.bmPlanes[edi]
        mov BITMAPINFOHEADER.biPlanes[ecx],ax
        mov ax,BITMAP.bmBitsPixel[edi]
        mov BITMAPINFOHEADER.biBitCount[ecx],ax
        mov BITMAPINFOHEADER.biCompression[ecx], BI_RGB
        xor eax, eax
        mov BITMAPINFOHEADER.biSizeImage[ecx], eax
        mov BITMAPINFOHEADER.biXPelsPerMeter[ecx], eax
        mov BITMAPINFOHEADER.biYPelsPerMeter[ecx], eax
        mov BITMAPINFOHEADER.biClrUsed[ecx], eax
        mov BITMAPINFOHEADER.biClrImportant[ecx], eax
        xor edx, edx
        mov eax, BITMAP.bmWidth[ecx]
        mul Bits
        add eax, 31
        and eax, -32
        shr eax, 3
        mul BITMAP.bmHeight[ecx]
        mov BmpSize, eax
        invoke VirtualAlloc, 0, eax, MEM_COMMIT, PAGE_READWRITE
        mov pMem, eax
        invoke GetDIBits, tempDC, hBmp, 0, dword PTR BITMAP.bmHeight[edi], pMem, ADDR BmpInfoHdr, DIB_RGB_COLORS
        xor eax,eax
        invoke CreateFile, lpOut, GENERIC_WRITE, eax, eax, CREATE_ALWAYS, eax, eax
        mov hFile, eax
        mov eax, BmpSize
        add eax, sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)
        mov SizeofDIB, eax
        lea edx, BmpFileHdr
        mov BITMAPFILEHEADER.bfOffBits[edx], sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)
        mov eax, SizeofDIB
        mov BITMAPFILEHEADER.bfSize[edx], eax
        mov BITMAPFILEHEADER.bfReserved1[edx], 0
        mov BITMAPFILEHEADER.bfReserved2[edx], 0
        mov BITMAPFILEHEADER.bfType[edx], 'MB'
        lea esi, BWritten
        invoke WriteFile, hFile, ADDR BmpFileHdr, sizeof(BITMAPFILEHEADER), esi, 0
        invoke WriteFile,hFile, ADDR BmpInfoHdr, sizeof(BITMAPINFOHEADER), esi, 0
        invoke WriteFile, hFile, pMem, BmpSize, esi, 0
        push eax
        invoke CloseHandle, hFile
        invoke VirtualFree, pMem, 0, MEM_RELEASE
        invoke SelectObject, tempDC, hOld
        invoke DeleteObject, hBmp
        invoke DeleteDC, tempDC
        pop eax ;; returns TRUE if file written, else returns FALSE
        pop ecx
        pop edx
        pop ebx
        pop edi
        pop esi
        ret
    DCbmptoFile endp
    where hDC is the DC of the captured client area. lprct is the pointer to rectange captured, lpout is pointer to the output file name for the bitmap. Also now taking better care to preserve the registers. :tongue:


zedd151

As in my last couple of posts, I am working on 'big_sudoku' (will be renamed prior to going 'public')..  It will incorporate a smaller (avatar sized 127x127) board within the GUI. The game will be played on the normal sized' sudoku board, and the smaller board will echo what is taking place in the main board (user can choose whether to show and use the smaller board or not). The screen captures on the smaller board will be automatic as soon as a value is entered (on the main board), if the small board is enabled. My current avatar was created with the help of this setup (yes, in its partially finished state). Much easier to work with the larger cells and of course font. :biggrin:

More details will follow in the coming days. Hopefully it will be completed (and bug free?) by the end of summer, time permitting.

zedd151

Progess is slow, but I am making progress. I have devised a way to have the small (127x127) board and the Main sudoku board on the same DC, with the small (127x127) being invisible to the user - this simplifies matters a bit. (By not having to use multiple DC's) Now working on the core code now that the DC stuff is out of the way...

zedd151

The avatar creator project is on hiatus until ...

... some time ...

... later.