play_loop(){ wait_for_someone_to_play(); /* someone has played when this returns */ if (it is not there turn) { send_them_a_message_saying_they_are_stupid(); continue; }; lock_card_inbox(); check_inbox_for_cards(); check_if_cards_in_inbox_can_be_played(); if (they can) { put_them_in_play(); send_your_go_packet_to_next_player(); } else { send_them_a_message_saying_they_are_stupid(); send_the_cards_back_to_their_inbox() } empty_card_inbox(); unlock_card_inbox(); continue;};on_packet_receive(){ if (it's 'someone is passing cards to play packet') { lock_card_inbox(); deserialise_cards_into_card_inbox(); unlock_card_inbox(); } if (it's a 'someone wants to play a card packet') { wakeup_play_loop_thread(); }}