multiplayer chess game, board data sync question

Options
Hello,

I am making a multiplayer chess game. I would like to ask what is the best way to share the board data? For example I have a 2d array of tile prefab objects that I am spawning the pieces on. My problem is that I have 2 separate local instances of this tile array.

I would like to ask what would be the best approach for that case? should I create another 2d array of strings (ids) for example and retain both in parallel? or there is a better approach? Having 2 different arrays feels a bit wrong.

Thanks

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @HarisKap,

    Thank you for choosing Photon!

    I think the best approach is to use custom room properties as board state.
    Each cell / tile is a custom room property.
    Since string is the type of the custom properties keys you can choose either index (single int) or coordinate (two ints).
    This way you need to modify only the cells that changed as a result of the piece that moved.
    The value of the custom room property should be either something to represent (piece type + color) or empty.

    You could also do this differently where you only set the actual pieces as room or even custom actor properties not the full board.
    Each custom property has the key set to the piece type (if room property also color, if actor properties then add a single extra custom property maybe for color) and the value is the coordinate of the piece on the board or something to present that the piece 'has been taken'.