Hello, I have to write a client/server sea battle game using shared memory and (posix) semiphores to communicate between them.
A short description for the implementation:
2 clients connect to the server, each client places their ships on his field and then the round-based game starts where each client selects a field on the opponents field to fire at until all ships of one client are destroyed.
My question is:
How do I need to set up the semiphores (and how many) to make sure that the access to the shared memory is being rotated between the 2 clients each round so one of them doesn't accidentally get to play 2 consecutive rounds?
Would 2 semiphores to alternate between server/client access and something like a flag in the shared memory to indicate which one of the clients is the next one to play work?
Or perhaps there is a more "proper" way to do it, relying solely on semiphores?