Author Topic: Four in a Row - R&D  (Read 1087 times)

zedd151

  • Member
  • ****
  • Posts: 592
  • -------------
Re: zedds
« Reply #15 on: May 04, 2018, 09:45:03 AM »
Not trying to run desktop windows 10 on your phone are you?  :dazzled:
 

Only if it were truly possible  :P    :lol:

Nah, I just meant I dont have the means to use the bootable usb tool... Or burn an iso to disk.

chicken/egg scenario.


pss If I could run .exe files on the phone I'd have been coding already.   :biggrin: 

« Last Edit: May 07, 2018, 01:00:15 PM by zedd151 »
@ Micros**t  --> 

Coming Soon "Taming Ten" - A tutorial for taming Windows 10, to gain more control over YOUR OWN computer.

HSE

  • Member
  • ****
  • Posts: 676
  • <AMD>< 7-32>
Re: zedds "4-in-line" research
« Reply #16 on: May 04, 2018, 11:19:55 AM »
pss If I could run .exe files on the phone I'd have been coding already.   :biggrin:

But you can! Just another OS... and another processor... and almost another programming language   :biggrin:

Very funny  :t   

zedd151

  • Member
  • ****
  • Posts: 592
  • -------------
Re: zedds "4-in-line" research
« Reply #17 on: May 04, 2018, 02:14:14 PM »

But you can! Just another OS... and another processor... and almost another programming language   :biggrin:


Jeez!  Seems everyone is really getting a kick outta my current situation.

For those people; just think, someday it could happen to you.    :shock: 

 :P    8)
@ Micros**t  --> 

Coming Soon "Taming Ten" - A tutorial for taming Windows 10, to gain more control over YOUR OWN computer.

zedd151

  • Member
  • ****
  • Posts: 592
  • -------------
Re: zedds "4-in-line" research
« Reply #18 on: May 04, 2018, 04:06:07 PM »
4 in line game.
-------------
game start - empty "board"
-------------

Code: [Select]
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
x x x x x x x

all locations are empty, playable positions are marked with an "x". players piece marked by "1", computer "2".

With the knowledge that this is a "gravity" based game, we know that there is a maximum of 7 available positions at any point in the game, always the lowest available position in any column. available means any position not already filled with either players piece or computers piece.

so every time either computer or player makes a move, the corresponding number is placed in chosen column at lowest available position. an x is placed in the row just above the newly moved piece, to signify new available position in chosen column (unless top already reached and column is full)

After a couple of moves by both sides:
Code: [Select]
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 x 0 0 0
0 x 0 1 x 0 0
x 2 x 1 2 x x
Only the nodes containing "x" in any position need be checked. If there is a zero in any node that node is invalid at this point and need not be checked.

a node is any 4 connecting positions in line, either vertically, horizontally, or diagonally.

Now we need a logical way to represent the positions, as well as a simple way to quickly identify the nodes that need to be checked.

suppose in memory, our board is 56 bytes, corresponding to:
(ascii, since it will be console mode)
Code: [Select]

00 00 00 00 00 00 00 ff ;top row - x here means column is full
-----------------------
30 30 30 30 30 30 30 ff
30 30 30 30 30 30 30 ff
30 30 30 30 30 30 30 ff
30 30 30 78 30 30 30 ff
30 78 30 31 78 30 30 ff
78 32 78 31 32 78 78 ff
where the positions filled with ff (-1) are invalid positions, used for alignment only and not displayed.

--- more to follow ---

@ Micros**t  --> 

Coming Soon "Taming Ten" - A tutorial for taming Windows 10, to gain more control over YOUR OWN computer.

felipe

  • Member
  • ****
  • Posts: 827
  • Eagles are just great!
Re: zedds "4-in-line" research
« Reply #19 on: May 05, 2018, 01:56:17 AM »
Ah, i see what you mean now by four in line. I actually have played this game in a DOS version named four. Was very funny and challenging  :biggrin:. I think checking the diagonal nodes will be the hard part.  :idea:
Felipe.

zedd151

  • Member
  • ****
  • Posts: 592
  • -------------
Re: zedds "4-in-line" research
« Reply #20 on: May 05, 2018, 04:38:57 AM »
Ah, i see what you mean now by four in line.

So as not to be confused with Hasbro's Connect Four ®™ .  They are very protective of their trademarked product and its name.
Quote
I think checking the diagonal nodes will be the hard part.  :idea:
No not really, but the code will surely have a lot of nested "if" statements, until I figure out a better way to do it,
@ Micros**t  --> 

Coming Soon "Taming Ten" - A tutorial for taming Windows 10, to gain more control over YOUR OWN computer.

zedd151

  • Member
  • ****
  • Posts: 592
  • -------------
Skeleton of a program
« Reply #21 on: May 06, 2018, 01:31:43 AM »
Here is the skeleton I so blatantly stole from my 4x4 console version - reworked a bit to be more useful here.

Code: [Select]
removed buggy code  :P

I will keep adding to it, or modifying it until the game is completed.
Doing this kind of stuff is tedious on a phone.  :badgrin:  I should have computer up and running before this games completion.


« Last Edit: May 06, 2018, 02:45:50 PM by zedd151 »
@ Micros**t  --> 

Coming Soon "Taming Ten" - A tutorial for taming Windows 10, to gain more control over YOUR OWN computer.

zedd151

  • Member
  • ****
  • Posts: 592
  • -------------
UPDATE!!!!!
« Reply #22 on: May 06, 2018, 04:28:26 AM »
Coming soon in glorious 64 bit, high definition, living color, and in 4D....

zedds game.    :biggrin:
@ Micros**t  --> 

Coming Soon "Taming Ten" - A tutorial for taming Windows 10, to gain more control over YOUR OWN computer.

zedd151

  • Member
  • ****
  • Posts: 592
  • -------------
Four in a Row.
« Reply #23 on: May 07, 2018, 10:33:36 AM »
Coming soon in glorious 64 bit, high definition, living color, and in 4D....

Well, not exactly...   :greensml:
Windows version of Four in a Row. (I like the name better than 4 in line)

Code: [Select]
        include \masm32\include\masm32rt.inc

        WinMain     proto
        LoadPix     proto :dword, :dword
        randb       proto :dword       
        painting    proto :dword

    .data
        hInstance   dd 0
        hWnd        dd 0

        hBoard      dd 0
        hRed        dd 0
        hBlue       dd 0
        column      dd 0
        board       db 35 dup (0)
        zz          db 7 dup (-1)

        wc              WNDCLASSEX  <>
        bord           db "board.bmp", 0
        blue            db "blue.bmp", 0
        red             db "red.bmp", 0

        szDisplayName   db "Four in a Row", 0
        szClassName     db "Game", 0

    .code

    start:
        invoke WinMain
        invoke ExitProcess, hInstance

    WinMain proc
    local msg:MSG, Wwd:dword, Wht:dword, Wtx:dword, Wty:dword

        push ebx
        invoke GetModuleHandle, NULL
        mov hInstance, eax
        mov wc.cbSize, sizeof WNDCLASSEX
        mov wc.style, CS_HREDRAW or CS_VREDRAW or CS_BYTEALIGNWINDOW
        mov wc.lpfnWndProc, offset WndProc
        m2m wc.hInstance, hInstance
        invoke CreateSolidBrush, 00000000h
        mov wc.hbrBackground, eax
        mov wc.lpszClassName, offset szClassName
        invoke LoadCursor, NULL, IDC_ARROW
        mov wc.hCursor, eax
        invoke RegisterClassEx, addr wc

        mov Wwd, 448
        mov Wht, 384
        lea edi, Wtx
        mov edx, Wwd
        mov ebx, 0
        @@:
        push edx
        invoke GetSystemMetrics, ebx
        pop edx
        shr eax, 1
        shr edx, 1
        sub eax, edx
        mov [edi], eax
        lea edi, Wty
        mov edx, Wht
        inc ebx
        cmp ebx, 2
        jnz @b

        invoke CreateWindowEx, 0, addr szClassName,
        addr szDisplayName, 90080800h, Wtx, Wty, Wwd, Wht, 0, 0, hInstance, 0
        mov hWnd, eax
        invoke ShowWindow, hWnd, SW_SHOWNORMAL
        invoke UpdateWindow, hWnd

    StartLoop:

        invoke GetMessage, addr msg, 0, 0, 0
        cmp eax, 0
        je ExitLoop
        invoke DispatchMessage, addr msg
        jmp StartLoop

    ExitLoop:
        pop ebx
        ret
    WinMain endp

    WndProc proc hWin:dword, uMsg:dword, wParam:dword, lParam:dword
        .if uMsg == WM_CREATE
   
            invoke LoadImage, 0, addr bord, IMAGE_BITMAP, 0, 0, 50h
            mov hBoard, eax
            invoke LoadImage, 0, addr red, IMAGE_BITMAP, 0, 0, 50h
            mov hRed, eax
            invoke LoadImage, 0, addr blue, IMAGE_BITMAP, 0, 0, 50h
            mov hBlue, eax
   
        .elseif uMsg == WM_LBUTTONDOWN
       
            push eax
            mov eax, lParam
            and eax, 0FFFFh
            shr eax,6
            inc eax
            mov column, eax
            pop eax
   
        .elseif uMsg == WM_LBUTTONUP
            push esi
            lea esi, board
           
            .if column == 1
              .if byte ptr [esi+35] == -1
              jmp is1
              .if byte ptr [esi+28] == -1
              jmp is1
              .if byte ptr [esi+21] == -1
              jmp is1
              .if byte ptr [esi+14] == -1
              jmp is1
              .if byte ptr [esi+7] == -1
              jmp is1
              .if byte ptr [esi] == -1
              jmp is1
              .endif
              .endif
              .endif
              .endif
              .endif
              .endif
            .endif
            jmp over1
            is1:
            over1:

            inc esi
            .if column == 2
              .if byte ptr [esi+35] == -1
              jmp is2
              .if byte ptr [esi+28] == -1
              jmp is2
              .if byte ptr [esi+21] == -1
              jmp is2
              .if byte ptr [esi+14] == -1
              jmp is2
              .if byte ptr [esi+7] == -1
              jmp is2
              .if byte ptr [esi] == -1
              jmp is2
              .endif
              .endif
              .endif
              .endif
              .endif
              .endif
            .endif
            jmp over2
            is2:
            over2:

            inc esi
            .if column == 3
              .if byte ptr [esi+35] == -1
              jmp is3
              .if byte ptr [esi+28] == -1
              jmp is3
              .if byte ptr [esi+21] == -1
              jmp is3
              .if byte ptr [esi+14] == -1
              jmp is3
              .if byte ptr [esi+7] == -1
              jmp is3
              .if byte ptr [esi] == -1
              jmp is3
              .endif
              .endif
              .endif
              .endif
              .endif
              .endif
            .endif
            jmp over3
            is3:
            over3:

            inc esi
            .if column == 4
              .if byte ptr [esi+35] == -1
              jmp is4
              .if byte ptr [esi+28] == -1
              jmp is4
              .if byte ptr [esi+21] == -1
              jmp is4
              .if byte ptr [esi+14] == -1
              jmp is4
              .if byte ptr [esi+7] == -1
              jmp is4
              .if byte ptr [esi] == -1
              jmp is4
              .endif
              .endif
              .endif
              .endif
              .endif
              .endif
            .endif
            jmp over4
            is4:
            over4:

            inc esi
            .if column == 5
              .if byte ptr [esi+35] == -1
              jmp is5
              .if byte ptr [esi+28] == -1
              jmp is5
              .if byte ptr [esi+21] == -1
              jmp is5
              .if byte ptr [esi+14] == -1
              jmp is5
              .if byte ptr [esi+7] == -1
              jmp is5
              .if byte ptr [esi] == -1
              jmp is5
              .endif
              .endif
              .endif
              .endif
              .endif
              .endif
            .endif
            jmp over5
            is5:
            over5:

            inc esi
            .if column == 6
              .if byte ptr [esi+35] == -1
              jmp is6
              .if byte ptr [esi+28] == -1
              jmp is6
              .if byte ptr [esi+21] == -1
              jmp is6
              .if byte ptr [esi+14] == -1
              jmp is6
              .if byte ptr [esi+7] == -1
              jmp is6
              .if byte ptr [esi] == -1
              jmp is6
              .endif
              .endif
              .endif
              .endif
              .endif
              .endif
            .endif
            jmp over6
            is6:
            over6:

            inc esi
            .if column == 7
              .if byte ptr [esi+35] == -1
              jmp is7
              .if byte ptr [esi+28] == -1
              jmp is7
              .if byte ptr [esi+21] == -1
              jmp is7
              .if byte ptr [esi+14] == -1
              jmp is7
              .if byte ptr [esi+7] == -1
              jmp is7
              .if byte ptr [esi] == -1
              jmp is7
              .endif
              .endif
              .endif
              .endif
              .endif
              .endif
            .endif
            jmp over7
            is7:
            over7:


   
        .elseif uMsg == WM_PAINT
            invoke painting, hWnd

        .elseif uMsg == WM_CLOSE
            invoke PostQuitMessage, NULL
            return 0

        .endif
        invoke DefWindowProc, hWin, uMsg, wParam, lParam
        ret
    WndProc endp

    randb proc base:dword
    local random_seed:dword
        invoke GetTickCount
        add eax, random_seed
        xor edx, edx
        mov ecx, 127773
        div ecx
        mov ecx, eax
        mov eax, 432836
        mul edx
        sub ecx, eax
        xor edx, edx
        mov eax, ecx
        mov random_seed, ecx
        div base
        mov eax, edx
        inc eax
        ret
    randb endp

    painting proc hWin:dword
    local tX:dword, tY:dword, hDC:dword, hMemDC:dword, numb:dword
        push esi
        push edi
        push ebx
        invoke GetWindowDC, hWin
        mov hDC, eax
        invoke CreateCompatibleDC, NULL
        mov hMemDC, eax

        invoke SelectObject, hMemDC, hBoard
        invoke BitBlt, hDC, 0, 0, 448, 384, hMemDC, 0, 0, SRCCOPY

        ;invoke SelectObject, hMemDC, hRed
        ;invoke BitBlt, hDC, 0, 0, 64, 64, hMemDC, 0, 0, SRCCOPY

        ;invoke SelectObject, hMemDC, hBlue
        ;invoke BitBlt, hDC, 0, 0, 64, 64, hMemDC, 0, 0, SRCCOPY

        invoke DeleteDC, hMemDC
        invoke DeleteDC, hDC
        pop ebx
        pop edi
        pop esi
        ret
    painting endp

    end start

It's not much, but it's what I've coded thus far in my spare time. Nowhere near completed yet.

later--> Added a little code to check which column the mouse was clicked in.
« Last Edit: May 07, 2018, 01:25:29 PM by zedd151 »
@ Micros**t  --> 

Coming Soon "Taming Ten" - A tutorial for taming Windows 10, to gain more control over YOUR OWN computer.

zedd151

  • Member
  • ****
  • Posts: 592
  • -------------
Re: zedds "Four in a Row" research
« Reply #24 on: May 07, 2018, 12:57:35 PM »
A different approach...

Code: [Select]
        include \masm32\include\masm32rt.inc

        WinMain     proto
        LoadPix     proto :dword, :dword
        randb       proto :dword       
        DisplayBmp  proto :dword, :dword, :dword, :dword, :dword
    .data
        hInstance   dd 0
        hWnd        dd 0
        hDC         dd 0
        hMemDC      dd 0
        hBoard      dd 0
        hRed        dd 0
        hBlue       dd 0
        column      dd 0
        row         dd 0
        board       db 35 dup (0)
        zz          db 7 dup (-1)
        xx          dd 0
        yy          dd 0

        wc              WNDCLASSEX  <>
        bord            db "board.bmp", 0
        blue            db "blue.bmp", 0
        red             db "red.bmp", 0
        stWin           db "STATIC",0
        szDisplayName   db "Four in a Row", 0
        szClassName     db "Game", 0

    .code

    start:
        invoke WinMain
        invoke ExitProcess, hInstance

    WinMain proc
    local msg:MSG, Wwd:dword, Wht:dword, Wtx:dword, Wty:dword

        push ebx
        invoke GetModuleHandle, NULL
        mov hInstance, eax
        mov wc.cbSize, sizeof WNDCLASSEX
        mov wc.style, CS_HREDRAW or CS_VREDRAW or CS_BYTEALIGNWINDOW
        mov wc.lpfnWndProc, offset WndProc
        m2m wc.hInstance, hInstance
        invoke CreateSolidBrush, 00000000h
        mov wc.hbrBackground, eax
        mov wc.lpszClassName, offset szClassName
        invoke LoadCursor, NULL, IDC_ARROW
        mov wc.hCursor, eax
        invoke RegisterClassEx, addr wc

        mov Wwd, 448
        mov Wht, 384
        lea edi, Wtx
        mov edx, Wwd
        mov ebx, 0
        @@:
        push edx
        invoke GetSystemMetrics, ebx
        pop edx
        shr eax, 1
        shr edx, 1
        sub eax, edx
        mov [edi], eax
        lea edi, Wty
        mov edx, Wht
        inc ebx
        cmp ebx, 2
        jnz @b

        invoke CreateWindowEx, 0, addr szClassName,
        addr szDisplayName, 90080800h, Wtx, Wty, Wwd, Wht, 0, 0, hInstance, 0
        mov hWnd, eax
        invoke ShowWindow, hWnd, SW_SHOWNORMAL
        invoke UpdateWindow, hWnd

    StartLoop:

        invoke GetMessage, addr msg, 0, 0, 0
        cmp eax, 0
        je ExitLoop
        invoke DispatchMessage, addr msg
        jmp StartLoop

    ExitLoop:
        pop ebx
        ret
    WinMain endp

    WndProc proc hWin:dword, uMsg:dword, wParam:dword, lParam:dword
        .if uMsg == WM_CREATE
            invoke DisplayBmp, hWin, 100, 0, 0, 20
   
        .elseif uMsg == WM_LBUTTONDOWN
       
            mov eax, lParam
            and eax, 0FFFFh
            shr eax,6
            inc eax
            mov column, eax
   
            lea eax, board
           
            .if column == 1
              mov yy, 0
              .if byte ptr [eax+35d] == -1
              mov row, 1
              mov xx, 320
              jmp is1
              .elseif byte ptr [eax+28d] == -1
              mov row, 2
              jmp is1
              .elseif byte ptr [eax+21d] == -1
              mov row, 3
              jmp is1
              .elseif byte ptr [eax+14d] == -1
              mov row, 4
              jmp is1
              .elseif byte ptr [eax+7d] == -1
              mov row, 5
              jmp is1
              .elseif byte ptr [eax] == -1
              mov row, 6
              jmp is1
              .endif
            .endif
            jmp over1
            is1:
            invoke DisplayBmp, hWin, 120, yy, xx, 30
            over1:

   
        .elseif uMsg == WM_PAINT

        .elseif uMsg == WM_CLOSE
            invoke PostQuitMessage, NULL
            return 0

        .endif
        invoke DefWindowProc, hWin, uMsg, wParam, lParam
        ret
    WndProc endp

    randb proc base:dword
    local random_seed:dword
        invoke GetTickCount
        add eax, random_seed
        xor edx, edx
        mov ecx, 127773
        div ecx
        mov ecx, eax
        mov eax, 432836
        mul edx
        sub ecx, eax
        xor edx, edx
        mov eax, ecx
        mov random_seed, ecx
        div base
        mov eax, edx
        inc eax
        ret
    randb endp

    DisplayBmp proc hParent:DWORD,bmpID:DWORD,x:DWORD,y:DWORD,ID:DWORD
        LOCAL hModule:DWORD
        LOCAL hBmp   :DWORD
        LOCAL hImage :DWORD
        invoke GetModuleHandle,NULL
        mov hModule, eax
        invoke CreateWindowEx,WS_EX_LEFT,
                ADDR stWin,NULL,
                WS_CHILD or WS_VISIBLE or SS_BITMAP,
                x,y,0,0,hParent,ID,
                hModule,NULL
        mov hImage, eax
        invoke LoadBitmap,hModule,bmpID
        mov hBmp, eax
        invoke SendMessage,hImage,STM_SETIMAGE,IMAGE_BITMAP,hBmp
        mov eax, hImage
        ret
    DisplayBmp endp

    end start

Using static control for "pieces". A little quirky just now, in that the row must be clicked twice for the static image to appear....
only row 1 works for now...


Later --->>>

I found out what the problem is.   :icon_redface:
And I'm working on fixing it.
« Last Edit: May 07, 2018, 04:57:36 PM by zedd151 »
@ Micros**t  --> 

Coming Soon "Taming Ten" - A tutorial for taming Windows 10, to gain more control over YOUR OWN computer.

zedd151

  • Member
  • ****
  • Posts: 592
  • -------------
Re: Four in a Row R&D
« Reply #25 on: May 07, 2018, 04:56:41 PM »
Now, something I can work with...

       
Code: [Select]
        include \masm32\include\masm32rt.inc

        WinMain     proto
        LoadPix     proto :dword, :dword
        randb       proto :dword       
        DisplayBmp  proto :dword, :dword, :dword, :dword, :dword
    .data
        count       dd 0
        hInstance   dd 0
        hWnd        dd 0
        hDC         dd 0
        hMemDC      dd 0
        hBoard      dd 0
        hRed        dd 0
        hBlue       dd 0
        column      dd 0
        row         dd 0
        topx        db 7 dup (0)
        board       db 35 dup (0)
        zz          db 7 dup (-1)
        xx          dd 0
        yy          dd 0
        done        dd 0

        wc              WNDCLASSEX  <>
        bord            db "board.bmp", 0
        blue            db "blue.bmp", 0
        red             db "red.bmp", 0
        stWin           db "STATIC",0
        szDisplayName   db "Four in a Row", 0
        szClassName     db "Game", 0

    .code

    start:
        invoke WinMain
        invoke ExitProcess, hInstance

    WinMain proc
    local msg:MSG, Wwd:dword, Wht:dword, Wtx:dword, Wty:dword

        push ebx
       
        invoke GetModuleHandle, NULL
        mov hInstance, eax
        mov wc.cbSize, sizeof WNDCLASSEX
        mov wc.style, CS_HREDRAW or CS_VREDRAW or CS_BYTEALIGNWINDOW
        mov wc.lpfnWndProc, offset WndProc
        m2m wc.hInstance, hInstance
        invoke CreateSolidBrush, 0000ffffh
        mov wc.hbrBackground, eax
        mov wc.lpszClassName, offset szClassName
        invoke LoadCursor, NULL, IDC_ARROW
        mov wc.hCursor, eax
        invoke RegisterClassEx, addr wc

        mov Wwd, 469
        mov Wht, 428
        lea edi, Wtx
        mov edx, Wwd
        mov ebx, 0
        @@:
        push edx
        invoke GetSystemMetrics, ebx
        pop edx
        shr eax, 1
        shr edx, 1
        sub eax, edx
        mov [edi], eax
        lea edi, Wty
        mov edx, Wht
        inc ebx
        cmp ebx, 2
        jnz @b

                             
        invoke CreateWindowEx, WS_EX_OVERLAPPEDWINDOW, addr szClassName,
        addr szDisplayName, WS_OVERLAPPEDWINDOW, Wtx, Wty, Wwd, Wht, 0, 0, hInstance, 0
        mov hWnd, eax
        invoke ShowWindow, hWnd, SW_SHOWNORMAL
        invoke UpdateWindow, hWnd

    StartLoop:
      invoke GetMessage,ADDR msg,NULL,0,0
      cmp eax, 0
      je ExitLoop
      invoke TranslateMessage, ADDR msg
      invoke DispatchMessage,  ADDR msg
      jmp StartLoop
    ExitLoop:
        pop ebx
        ret
    WinMain endp

    WndProc proc hWin:dword, uMsg:dword, wParam:dword, lParam:dword
    LOCAL Ps     :PAINTSTRUCT
        .if uMsg == WM_CREATE
                   
   
        .elseif uMsg == WM_LBUTTONDOWN
       
            mov eax, lParam
            and eax, 0FFFFh
            shr eax,6
            inc eax
            mov column, eax
   
            lea eax, board
            dec eax
            add eax, column

           
            .if column == 1
              mov yy, 0
            .elseif column == 2
              mov yy, 64
            .elseif column == 3
              mov yy, 128
            .elseif column == 4
              mov yy, 192
            .elseif column == 5
              mov yy, 256
            .elseif column == 6
              mov yy, 320
            .elseif column == 7
              mov yy, 384
            .endif
           
              call movit




   
        .elseif uMsg == WM_PAINT
       
       
;-------------------- create lines in the game board ------------------     
   
        jmp ttt
        cords dd 0,64,128,192,256,320,384,448   ; ------- coordinates
        ttt:


        push esi
        push edi
        push ebx
       
        lea esi, cords
        mov edi, 448
        mov ebx, 448
       
        @@:
        invoke line, hWin, 0, 0, [esi], edi, [esi]
        add esi, 4
        cmp [esi], ebx
        jl @b
       
        lea esi, cords
        mov edi, 384
        mov ebx, 512
       
        @@:
        invoke line, hWin, 0,  [esi], 0, [esi], edi
        add esi, 4
        cmp [esi], ebx
        jl @b

        pop ebx
        pop edi
        pop esi

       
        invoke BeginPaint,hWin,ADDR Ps
        mov hDC, eax
        invoke EndPaint,hWin,ADDR Ps
        .elseif uMsg == WM_CLOSE
            invoke PostQuitMessage, NULL
            return 0

        .endif
        invoke DefWindowProc, hWin, uMsg, wParam, lParam
        ret
    WndProc endp

    movit proc
   
        .if byte ptr [eax+35] == -1
            mov row, 1
            mov xx, 320
            mov byte ptr [eax+35], 1
            mov byte ptr [eax+28], -1
            jmp is1
           
        .elseif byte ptr [eax+28] == -1
            mov row, 2
            mov xx, 256
            mov byte ptr [eax+28], 1
            mov byte ptr [eax+21], -1
            jmp is1
           
        .elseif byte ptr [eax+21] == -1
            mov row, 3
            mov xx, 192
            mov byte ptr [eax+21], 1
            mov byte ptr [eax+14], -1
            jmp is1
           
        .elseif byte ptr [eax+14] == -1
            mov row, 4
            mov xx, 128
            mov byte ptr [eax+14], 1
            mov byte ptr [eax+7], -1
            jmp is1
           
        .elseif byte ptr [eax+7] == -1
            mov row, 5
            mov xx, 64
            mov byte ptr [eax+7], 1
            mov byte ptr [eax], -1
            jmp is1
           
        .elseif byte ptr [eax] == -1
            mov row, 6
            mov xx, 0
            mov byte ptr [eax], 1
            mov byte ptr [eax-7], -1
            jmp is1
            is1:
            add xx, 3
            add yy, 3
            invoke DisplayBmp, hWnd, 120, yy, xx, 30
        .endif
        ret
    movit endp

    randb proc base:dword
    local random_seed:dword
        invoke GetTickCount
        add eax, random_seed
        xor edx, edx
        mov ecx, 127773
        div ecx
        mov ecx, eax
        mov eax, 432836
        mul edx
        sub ecx, eax
        xor edx, edx
        mov eax, ecx
        mov random_seed, ecx
        div base
        mov eax, edx
        inc eax
        ret
    randb endp

    DisplayBmp proc hParent:DWORD,bmpID:DWORD,x:DWORD,y:DWORD,ID:DWORD
        LOCAL hModule:DWORD
        LOCAL hBmp   :DWORD
        LOCAL hImage :DWORD
        invoke GetModuleHandle,NULL
        mov hModule, eax
        invoke CreateWindowEx,WS_EX_LEFT,
                ADDR stWin,NULL,
                WS_CHILD or WS_VISIBLE or SS_BITMAP,
                x,y,0,0,hParent,ID,
                hModule,NULL
        mov hImage, eax
        invoke LoadBitmap,hModule,bmpID
        mov hBmp, eax
        invoke SendMessage,hImage,STM_SETIMAGE,IMAGE_BITMAP,hBmp
        mov eax, hImage
        ret
    DisplayBmp endp

    end start

All columns are working as they should. Click on a column, and your piece is placed at the bottom-most vacant location in that column.   :biggrin:

Now to start working on the AI portion of the game.   :icon_eek:
After that is pretty much taken care of, I will then work on the "dynamic skill level". For more skilled players, will be more challenging. for less skilled players, it will be easier. I want to try to keep the computer versus human win ratio to a reasonable level, so it will be fun as well as challenging to play. Should be that the human player wins between 45 and 55 % of the games. But I may adjust those numbers during development of the game.

>> Later
Found a flaw in the design. I need to check whether the column is full....
« Last Edit: May 08, 2018, 05:13:38 AM by zedd151 »
@ Micros**t  --> 

Coming Soon "Taming Ten" - A tutorial for taming Windows 10, to gain more control over YOUR OWN computer.

zedd151

  • Member
  • ****
  • Posts: 592
  • -------------
Re: Four in a Row - R&D
« Reply #26 on: May 08, 2018, 12:30:09 AM »
some more code tweaks...

Code: [Select]
        include \masm32\include\masm32rt.inc

        WinMain     proto
        LoadPix     proto :dword, :dword
        randb       proto :dword       
        DisplayBmp  proto :dword, :dword, :dword, :dword, :dword
    .data
        count       dd 0
        hInstance   dd 0
        hWnd        dd 0
        hDC         dd 0
        hMemDC      dd 0
        hBoard      dd 0
        hRed        dd 0
        hBlue       dd 0
        column      dd 0
        row         dd 0
        topx        db 7 dup (0)
        board       db 35 dup (0)
        zz          db 7 dup (-1)
        xx          dd 0
        yy          dd 0
        done        dd 0

        wc              WNDCLASSEX  <>
        bord            db "board.bmp", 0
        blue            db "blue.bmp", 0
        red             db "red.bmp", 0
        stWin           db "STATIC",0
        szDisplayName   db "Four in a Row", 0
        szClassName     db "Game", 0

    .code

    start:
        invoke WinMain
        invoke ExitProcess, hInstance

    WinMain proc
    local msg:MSG, Wwd:dword, Wht:dword, Wtx:dword, Wty:dword

        push ebx
       
        invoke GetModuleHandle, NULL
        mov hInstance, eax
        mov wc.cbSize, sizeof WNDCLASSEX
        mov wc.style, CS_HREDRAW or CS_VREDRAW or CS_BYTEALIGNWINDOW
        mov wc.lpfnWndProc, offset WndProc
        m2m wc.hInstance, hInstance
        invoke CreateSolidBrush, 0000ffffh
        mov wc.hbrBackground, eax
        mov wc.lpszClassName, offset szClassName
        invoke LoadCursor, NULL, IDC_ARROW
        mov wc.hCursor, eax
        invoke RegisterClassEx, addr wc

        mov Wwd, 455
        mov Wht, 414
        lea edi, Wtx
        mov edx, Wwd
        mov ebx, 0
        @@:
        push edx
        invoke GetSystemMetrics, ebx
        pop edx
        shr eax, 1
        shr edx, 1
        sub eax, edx
        mov [edi], eax
        lea edi, Wty
        mov edx, Wht
        inc ebx
        cmp ebx, 2
        jnz @b

                             
        invoke CreateWindowEx, WS_EX_LEFT, addr szClassName,
        addr szDisplayName, WS_SYSMENU, Wtx, Wty, Wwd, Wht, 0, 0, hInstance, 0
        mov hWnd, eax
        invoke ShowWindow, hWnd, SW_SHOWNORMAL
        invoke UpdateWindow, hWnd

    StartLoop:
      invoke GetMessage,ADDR msg,NULL,0,0
      cmp eax, 0
      je ExitLoop
      invoke TranslateMessage, ADDR msg
      invoke DispatchMessage,  ADDR msg
      jmp StartLoop
    ExitLoop:
        pop ebx
        ret
    WinMain endp

    WndProc proc hWin:dword, uMsg:dword, wParam:dword, lParam:dword
    LOCAL Ps     :PAINTSTRUCT
        .if uMsg == WM_CREATE
                   
   
        .elseif uMsg == WM_LBUTTONDOWN

; ------- >>> streamlined the code below
       
            mov eax, lParam
            and eax, 0FFFFh
            shr eax,6
            mov column, eax
   
            lea eax, board
            add eax, column

            mov ecx, column
            shl ecx, 6  ; round off for bmp position
            mov yy, ecx

            call movit

; ------- >>> streamlined the code above


   
        .elseif uMsg == WM_PAINT
       
       
;-------------------- create lines in the game board ------------------     
   
        jmp ttt
        cords dd 0,64,128,192,256,320,384,448   ; ------- coordinates
        ttt:


        push esi
        push edi
        push ebx
       
        lea esi, cords
        mov edi, 448
        mov ebx, 448
       
        @@:
        invoke line, hWin, 0, 0, [esi], edi, [esi]
        add esi, 4
        cmp [esi], ebx
        jl @b
       
        lea esi, cords
        mov edi, 384
        mov ebx, 512
       
        @@:
        invoke line, hWin, 0,  [esi], 0, [esi], edi
        add esi, 4
        cmp [esi], ebx
        jl @b

        pop ebx
        pop edi
        pop esi

       
        invoke BeginPaint,hWin,ADDR Ps
        mov hDC, eax
        invoke EndPaint,hWin,ADDR Ps
        .elseif uMsg == WM_CLOSE
            invoke PostQuitMessage, NULL
            return 0

        .endif
        invoke DefWindowProc, hWin, uMsg, wParam, lParam
        ret
    WndProc endp

    movit proc
        .if byte ptr [eax-7] == -1
        jmp ww
        .endif
        .if byte ptr [eax+35] == -1
            mov row, 1
            mov xx, 320
            mov byte ptr [eax+35], 1
            mov byte ptr [eax+28], -1
            jmp is1
           
        .elseif byte ptr [eax+28] == -1
            mov row, 2
            mov xx, 256
            mov byte ptr [eax+28], 1
            mov byte ptr [eax+21], -1
            jmp is1
           
        .elseif byte ptr [eax+21] == -1
            mov row, 3
            mov xx, 192
            mov byte ptr [eax+21], 1
            mov byte ptr [eax+14], -1
            jmp is1
           
        .elseif byte ptr [eax+14] == -1
            mov row, 4
            mov xx, 128
            mov byte ptr [eax+14], 1
            mov byte ptr [eax+7], -1
            jmp is1
           
        .elseif byte ptr [eax+7] == -1
            mov row, 5
            mov xx, 64
            mov byte ptr [eax+7], 1
            mov byte ptr [eax], -1
            jmp is1
           
        .elseif byte ptr [eax] == -1
            mov row, 6
            mov xx, 0
            mov byte ptr [eax], 1
            mov byte ptr [eax-7], -1
            is1:
        .endif
       
            add xx, 3 ; adj for bmp size
            add yy, 3 ; adj for bmp size
           
            invoke DisplayBmp, hWnd, 120, yy, xx, 30
        ww:
        ret
    movit endp

    randb proc base:dword
    local random_seed:dword
        invoke GetTickCount
        add eax, random_seed
        xor edx, edx
        mov ecx, 127773
        div ecx
        mov ecx, eax
        mov eax, 432836
        mul edx
        sub ecx, eax
        xor edx, edx
        mov eax, ecx
        mov random_seed, ecx
        div base
        mov eax, edx
        inc eax
        ret
    randb endp

    DisplayBmp proc hParent:DWORD,bmpID:DWORD,x:DWORD,y:DWORD,ID:DWORD
        LOCAL hModule:DWORD
        LOCAL hBmp   :DWORD
        LOCAL hImage :DWORD
        invoke GetModuleHandle,NULL
        mov hModule, eax
        invoke CreateWindowEx,WS_EX_LEFT,
                ADDR stWin,NULL,
                WS_CHILD or WS_VISIBLE or SS_BITMAP,
                x,y,0,0,hParent,ID,
                hModule,NULL
        mov hImage, eax
        invoke LoadBitmap,hModule,bmpID
        mov hBmp, eax
        invoke SendMessage,hImage,STM_SETIMAGE,IMAGE_BITMAP,hBmp
        mov eax, hImage
        ret
    DisplayBmp endp

    end start
@ Micros**t  --> 

Coming Soon "Taming Ten" - A tutorial for taming Windows 10, to gain more control over YOUR OWN computer.

zedd151

  • Member
  • ****
  • Posts: 592
  • -------------
Re: Four in a Row - R&D
« Reply #27 on: May 08, 2018, 06:43:15 AM »
Changed the bmps for the game, and changed the data arrangement for the game board.
@ Micros**t  --> 

Coming Soon "Taming Ten" - A tutorial for taming Windows 10, to gain more control over YOUR OWN computer.

zedd151

  • Member
  • ****
  • Posts: 592
  • -------------
Re: Four in a Row - R&D
« Reply #28 on: May 08, 2018, 07:30:56 PM »
Further code reduction, and removing redundancies. Still a one-player game, lol.

Code: [Select]


        include \masm32\include\masm32rt.inc

        WinMain     proto
        randb       proto :dword       
        DisplayBmp  proto :dword, :dword, :dword, :dword, :dword
       
    .data
   
        topx        db 8 dup (0)
        board       db 40 dup (0)
        zz          db 8 dup (-1)

        count       dd 0
        hInstance   dd 0
        hWnd        dd 0
        hDC         dd 0
       
        hMemDC      dd 0
        hBoard      dd 0
        hRed        dd 0
        hBlue       dd 0
       
        column      dd 0
        xx          dd 0
        yy          dd 0
        done        dd 0
       
        wc              WNDCLASSEX  <>
        bord            db "board.bmp", 0
        blue            db "blue.bmp", 0
        red             db "red.bmp", 0
        stWin           db "STATIC",0
        szDisplayName   db "Four in a Row", 0
        szClassName     db "Game", 0

    .code

    start:
        invoke WinMain
        invoke ExitProcess, hInstance

    WinMain proc
    local msg:MSG, Wwd:dword, Wht:dword, Wtx:dword, Wty:dword

        push ebx
       
        invoke GetModuleHandle, NULL
        mov hInstance, eax
        mov wc.cbSize, sizeof WNDCLASSEX
        mov wc.style, CS_HREDRAW or CS_VREDRAW or CS_BYTEALIGNWINDOW
        mov wc.lpfnWndProc, offset WndProc
        m2m wc.hInstance, hInstance
        invoke CreateSolidBrush, 0000ffffh
        mov wc.hbrBackground, eax
        mov wc.lpszClassName, offset szClassName
        invoke LoadCursor, NULL, IDC_ARROW
        mov wc.hCursor, eax
        invoke RegisterClassEx, addr wc
       
        push ebx
        mov Wwd, 455
        mov Wht, 414
        lea edi, Wtx
        mov edx, Wwd
        mov ebx, 0
        @@:
        push edx
        invoke GetSystemMetrics, ebx
        pop edx
        shr eax, 1
        shr edx, 1
        sub eax, edx
        mov [edi], eax
        lea edi, Wty
        mov edx, Wht
        inc ebx
        cmp ebx, 2
        jnz @b
        pop ebx
                             
        invoke CreateWindowEx, WS_EX_LEFT, addr szClassName,
        addr szDisplayName, WS_SYSMENU, Wtx, Wty, Wwd, Wht, 0, 0, hInstance, 0
        mov hWnd, eax
        invoke ShowWindow, hWnd, SW_SHOWNORMAL
        invoke UpdateWindow, hWnd

    StartLoop:
      invoke GetMessage,ADDR msg,NULL,0,0
      cmp eax, 0
      je ExitLoop
      invoke TranslateMessage, ADDR msg
      invoke DispatchMessage,  ADDR msg
      jmp StartLoop
    ExitLoop:
        pop ebx
        ret
    WinMain endp

    WndProc proc hWin:dword, uMsg:dword, wParam:dword, lParam:dword
    LOCAL Ps     :PAINTSTRUCT
        .if uMsg == WM_CREATE
                   
   
        .elseif uMsg == WM_LBUTTONDOWN
       
; ---------------- further codesize optimizations below ---------------

            mov eax, lParam
            and eax, 0FFFFh
            shr eax,6 ; ------- column number (0-6)
            mov column, eax
            shl eax, 6 ; ------- y coord of row
            mov yy, eax
            lea eax, board
            add eax, column ; -------- location of column on board
            cmp byte ptr [eax-8], -1
            jz ww
            mov edx, 320
            hhh:
            mov ecx, edx           
            mov xx, ecx
            sar ecx, 3
        .if byte ptr [eax+ecx] == -1     ; if space is playable
            mov byte ptr [eax+ecx], 1    ; mark space occupied
            sub ecx, 8
            mov byte ptr [eax+ecx], -1   ; same column, mark space in row above playable
            add xx, 3 ; adj for bmp size
            add yy, 3 ; adj for bmp size
            invoke DisplayBmp, hWnd, 120, yy, xx, 30
            jmp ww
        .endif
            sub edx, 64
            jmp hhh
       
        ww:
; ---------------------------------------------------------------------


   
        .elseif uMsg == WM_PAINT
       
        jmp ttt
        cords dd 0,64,128,192,256,320,384,448   ; ------- coordinates
        ttt:
        push esi
        push edi
        push ebx
       
        lea esi, cords
        mov edi, 448
        mov ebx, 448
        @@:
        invoke line, hWin, 0, 0, [esi], edi, [esi]
        add esi, 4
        cmp [esi], ebx
        jl @b
        lea esi, cords
        mov edi, 384
        mov ebx, 512
        @@:
        invoke line, hWin, 0,  [esi], 0, [esi], edi
        add esi, 4
        cmp [esi], ebx
        jl @b

        pop ebx
        pop edi
        pop esi
       
        .elseif uMsg == WM_CLOSE
            invoke PostQuitMessage, NULL
            return 0

        .endif
        invoke DefWindowProc, hWin, uMsg, wParam, lParam
        ret
    WndProc endp

    randb proc base:dword
    local random_seed:dword
        invoke GetTickCount
        add eax, random_seed
        xor edx, edx
        mov ecx, 127773
        div ecx
        mov ecx, eax
        mov eax, 432836
        mul edx
        sub ecx, eax
        xor edx, edx
        mov eax, ecx
        mov random_seed, ecx
        div base
        mov eax, edx
        inc eax
        ret
    randb endp

    DisplayBmp proc hParent:DWORD,bmpID:DWORD,x:DWORD,y:DWORD,ID:DWORD
        LOCAL hModule:DWORD
        LOCAL hBmp   :DWORD
        LOCAL hImage :DWORD
        invoke GetModuleHandle,NULL
        mov hModule, eax
        invoke CreateWindowEx,WS_EX_LEFT,
                ADDR stWin,NULL,
                WS_CHILD or WS_VISIBLE or SS_BITMAP,
                x,y,0,0,hParent,ID,
                hModule,NULL
        mov hImage, eax
        invoke LoadBitmap,hModule,bmpID
        mov hBmp, eax
        invoke SendMessage,hImage,STM_SETIMAGE,IMAGE_BITMAP,hBmp
        mov eax, hImage
        ret
    DisplayBmp endp

    end start


Will put the "human player" code into a procedure before moving on to make the "computer player".
@ Micros**t  --> 

Coming Soon "Taming Ten" - A tutorial for taming Windows 10, to gain more control over YOUR OWN computer.

zedd151

  • Member
  • ****
  • Posts: 592
  • -------------
Re: Four in a Row - R&D
« Reply #29 on: May 08, 2018, 08:07:45 PM »
Okay, now I am finished with shortening the code that I have so far, and putting the "human player" code into its' own proc. Here it is in the attachment.
It is still a one-player game, so don't expect too much from it.
Now that is taken care of, I will start coding the "computer player". That should make it much more interesting, both for the player as well as the intrepid coder.   :biggrin:











@ Micros**t  --> 

Coming Soon "Taming Ten" - A tutorial for taming Windows 10, to gain more control over YOUR OWN computer.