Search code examples
vb.netchess

Making a chess multiplayer game


I am trying to make a Chess multiplayer game in Visual Basic. Its a two player which will be played in a normal way and not even over LAN.
So far, I am done designing the board.

My logic is:
First, on clicking any square, the click event handler will check whether a piece resides on that square. If not, then it checks if a piece is to be moved to that square. If both are negative, then it does nothing.

Now, the problem with this is, how do I code the click events? Also, I have represented the board using a 2dimensional array. But how do I update the positions after every move? And how do I check whether legal move is being executed? One more thing I want to add is whenever a piece is clicked, the possible legal squares should be highlighted.

For this, what I did was, for every click event on any square it checked if there was a piece. If there was a piece, then it highlighted all possible moves for that piece using If-Else-If logic, but it turned out to be too cumbersome and too long. And another problem which arose was, how do I know that if the user clicks an empty square to move the piece there?

Please help me.


Solution

  • "But how do I update the positions after every move?"

    When the piece is about to be moved:

    Check if the piece can move like that. (Like bishop can only move diagonally)

    Check that your teams piece is not on the position your about to move.

    Make a second array where the move is already happened.

    Check if the move was legal. (Its your turn but the your king is kill-able with one move)

    To check this you need:

    To get your kings position

    And then look up all the possible moves for the opponent

    check if a move can land on your kings position.