How do I program Chess game?

1 favourites
From the Asset Store
Beautiful Black & White Chess Pieces for Chess Game.
  • I have read lots of tutorials on how to make chess but those tutorials are on other programming language like javascript etc. I tried to follow those tutorial but I don't know how to implement that in construct.

    please anybody can guide me on how to start?

    If 8x8 array I feed players name like

    bR bN bB bQ bK bB bN bR

    bP bP bP bP bP bP bP bP

    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

    wP wP wP wP wP wP wP wP

    wR wN wB wQ wK wB wN wR

    then how can I move sprite position according to their names in the Array

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Programming chess is a big task, even if you want to do only the basic movement and logic, without the AI. I would suggest using a JS library like this one:

    github.com/jhlywa/chess.js

    All you need to do is call its methods and refresh sprites position on the layout.

  • I don't know how to call things from file. can just give me any example on how to call things? and do I have to download chess.js and import in construct ?

  • Here is a demo. Read the documentation for the library, there are many methods, I used just a couple to make a quick example.

    dropbox.com/s/j0gfaylmr53eoj1/ChessJS.c3p

  • You have used javascript programming in the sample and I don't have javascript knowledge nor other programming language. So instead of doing

    runtime.globalVars.textBoard = chess.ascii();

    how can I save chess.ascii() in textBoard directly?

  • BTW I created chessboard in construct and then I created movements for each player.

    there were few things which I didn't made yet, restricted moves for king, castling and en passent square.

  • runtime.globalVars.textBoard = chess.ascii();

    how can I save chess.ascii() in textBoard directly?

    That was saving chess.ascii() in textBoard directly.

    You don't need Javascript knowledge, I don't have it either.

    few things which I didn't made yet, restricted moves for king, castling and en passent square.

    You think there are only a few things left, but you don't realize how many different rules and restrictions there are in chess. If you look at the chess.js code, there are over 1900 lines of code! It's much easier to use the library, than creating all this logic yourself.

  • I didn't used this library and continued making chess myself from scratch.

    Reason I am not using library.

    1. I don't know how to call those library values into sprite positions.

    2. I want to make chess myself.

    as basic moves are created Now I am working on special moves.

    "castling" move is done

    "in passing" is done

    "kings" restricted moves also done.

    Now working on "restrict other players" if their move can kill king.

  • you were right its not easy.

    Can you little explain from your demo how can I convert those "textBoard" into sprite positions.

  • .ascii() is only for debugging.

    You can use .board() method to get an array with all pieces positions.

    Everything is explained here:

    github.com/jhlywa/chess.js

  • I have read there but still I didn't know what to do and how to do with this

    const chess = new Chess()
    
    chess.board()
    // -> [[{type: 'r', color: 'b'},
     {type: 'n', color: 'b'},
     {type: 'b', color: 'b'},
     {type: 'q', color: 'b'},
     {type: 'k', color: 'b'},
     {type: 'b', color: 'b'},
     {type: 'n', color: 'b'},
     {type: 'r', color: 'b'}],
     [...],
     [...],
     [...],
     [...],
     [...],
     [{type: 'r', color: 'w'},
     {type: 'n', color: 'w'},
     {type: 'b', color: 'w'},
     {type: 'q', color: 'w'},
     {type: 'k', color: 'w'},
     {type: 'b', color: 'w'},
     {type: 'n', color: 'w'},
     {type: 'r', color: 'w'}]]
    
  • I think you can load it into JSON object. Then use JSON data directly, or transfer it to an array/tilemap.

  • still out of my head

    but I'll think of it

  • Chess ai typically uses the "minimax algorithm" to decide its best move. This basically loops over all the pieces and plays them, then looks at all the outcomes and scores it, then does the same for all the player pieces. Thats a lot of calculations. It then picks the move with the best outcome. It does this a number of turns ahead. The more turns it looks ahead the smarter the ai is, but the more calculations it has to do.

    This is something that events are not good at and is also very slow in c3, thats why you need to use js.

  • ai is a long way away currently I am struggling on how to apply these api's in sprites.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)