Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    Chess Game

    Beginners
    3
    10
    421
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • F
      faz808 F last edited by pianofire

      I'm working on a chess program which reads a chess pgn file and displays the moves in a timely fashion.
      In the following code snippet, changing b to b=82 (w=82) moves white bishop onto black bishop OK - and
      changing w to w=12 (b=12) moves black bishop onto white bishop - but white bishop still shows.
      I can't see the obvious answer.

      clear()
      image = loadimage("Untied Games/Chess board", false)
      pieces = loadimage("Untied Games/Chess pieces", false)
      b=12
      w=82
      clear()
      drawImage( image, 0,0,2)
      drawImage( pieces, {0,0,80,130},{b,400,100/2,100/2})
      drawImage( pieces, {80,0,80,130},{w,400,100/2,100/2})
      update()
      sleep(122)
      

      Any help would be appreciated. Thanks

      pianofire vinicity 2 Replies Last reply Reply Quote 0
      • F
        faz808 F last edited by

        This post is deleted!
        1 Reply Last reply Reply Quote 0
        • pianofire
          pianofire Fuze Team @faz808 last edited by

          @faz808 I have tidied that up for you!

          Note: if you add ``` around your code it formats better

          1 Reply Last reply Reply Quote 0
          • pianofire
            pianofire Fuze Team last edited by

            It looks like you are drawing the black bishop and the white bishop on the same square. So whichever draw operation happens last will be the one that is on top (in this case the white one). I think that you will need to track which pieces haven't been captured and only draw those. One way to do this might be to convert the images into sprites and then just set the sprite.visible property to false for pieces that have been captured.

            F 1 Reply Last reply Reply Quote 0
            • F
              faz808 F @pianofire last edited by

              @pianofire Thanks. I knew you'd have the answer. If I can get this part running the rest should be fairly straight forward.
              A typical pgn file looks like this: d2-d4 d7-d5 (white-black) etc... I'm hoping that I just need to read the file, convert a1 to h8 board positions to screen coordinates, pick up the appropriate black or white sprite and move it to the new position.

              1 Reply Last reply Reply Quote 0
              • vinicity
                vinicity F @faz808 last edited by

                @faz808 said in Chess Game:

                I'm working on a chess program which reads a chess pgn file and displays the moves in a timely fashion.

                Just out of curiosity (and because I am also working on a chess program), how do you plan to create the pgn files in the first place? Will you perhaps have a "chess recorder" so you can make the moves and generate the file, or are you doing some sort of file editor thing?

                1 Reply Last reply Reply Quote 0
                • F
                  faz808 F last edited by

                  I'm not quite sure yet. But my idea is something like this...
                  '''loop to end of pgn file
                  BB$="a2-a4 c2-c4" // etc..
                  AA$=mid$(BB$,0,5)
                  L$=mid$(AA$,0,1)
                  N$=mid$(AA$,1,1)
                  LL$=mid$(AA$,3,1)
                  NN$=mid$(AA$,4,1)
                  y_from=9-((asc(N$))-48)
                  x_from=(asc(L$))-64
                  y_to=9-((asc(NN$))-48)
                  x_to=(asc(LL$))-64'''

                  This should convert A4 etc to a x,y screen coordinate. Or a look up table A1$=22,22, A2$=32,22 etc.
                  Problem is lack of MID$,LEFT$,RIGHT$.

                  1 Reply Last reply Reply Quote 0
                  • F
                    faz808 F last edited by pianofire

                    Sorry I can't seem to get this format thing right.

                    BB$="a2-a4 c2-c4" // etc..
                    AA$=mid$(BB$,0,5)
                    L$=mid$(AA$,0,1)
                    N$=mid$(AA$,1,1)
                    LL$=mid$(AA$,3,1)
                    NN$=mid$(AA$,4,1)
                    y_from=9-((asc(N$))-48)
                    x_from=(asc(L$))-64
                    y_to=9-((asc(NN$))-48)
                    x_to=(asc(LL$))-64 
                    

                    Is that better?

                    1 Reply Last reply Reply Quote 0
                    • pianofire
                      pianofire Fuze Team last edited by

                      You need to put the ``` on a separate line (I have fixed it for you)

                      1 Reply Last reply Reply Quote 0
                      • F
                        faz808 F last edited by

                        Thanks pianofire

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post