How to assign 2D array "coordinates" to a struct and retrieve them

I have a 2d array 5x7 (field) and a struct like the following, where T_x and T_y should be the coordinates of the cells owned by a player (that should be maximum 4 per each player)

`struct player{
        char name[10];
        int T_x[4];
        int T_y[4];

How can I assign the cell to a determined random player?
How can I check if a cell field's of the 2d array is already assigned to another player? (retrieving)
PS: the value of the cell's field cannot be changed, I define their value in the declaration part.

1 answer

  • answered 2018-02-13 03:17 Connor

    One suggestion for the latter question of checking if a cell is already assigned would be to have each cell be a struct itself, so you would have an array of struct cells. The struct cell could contain whatever data you would like in it and an integer flag to state whether the cell is already occupied or not, that way you do not have to change the value of the cell.