Page 1 of 1

Custom notifications

Posted: 06 May 2020, 11:44
by Lilzer7
Hi !!

I'm currently working on a card game in which the last hand is the following :

Each player is dealt a card. You can see every other players' card but yours.

I'm trying to implement that but i'm having hard time with the notification part. I'm supposed to send a customized notification for each player, as i can't send information of the card the player is not supposed to know.

So basicly the easiest method would be to create one array for each player, in which i add every card but not the one the player has, and then send this individually through notifyPlayer.
But i'm not really satisfied with this option of creating all these arrays, as the content of each array is really simillar from one to another.

Do you know a better way of doing this ?

Re: Custom notifications

Posted: 06 May 2020, 13:22
by apollo1001
Probably worth having a look at the code for Hanabi...

Re: Custom notifications

Posted: 06 May 2020, 18:42
by shadowphiar
I think you do need to create separate arrays for each player's notification. One clean way to do this would be to create a single array which contains everything, then for each player, call array_filter to take out the secret information before sending the rest to the client.

Re: Custom notifications

Posted: 06 May 2020, 19:00
by Lilzer7
apollo1001 wrote: 06 May 2020, 13:22 Probably worth having a look at the code for Hanabi...
Thank you for your answer,

I checked on Hanabi project but I couldn't find what I was looking for. The main difference is that in my game, N cards are drawn simultaneously during the hand (one for each player), whearas in Hannabi, at most 1 card is drawn (during the active player turn) and even with only one card at a time, it takes N notification in the Hanabi code.
So I was trying to optimize it the better way, by minimizing the number of notifications, as well as the number of arrays.

I ended up doing this :

Code: Select all

$cards = array();
foreach ( $players as $player_id => $player ) {
	$cards[$player_id] = $this->cards->pickCardForLocation('deck', 'cardsontable', $player_id);
}
foreach ( $players as $player_id => $player ) {
	$all_cards_but_mine = array_diff_key($cards, array_flip([$player_id]));
	self::notifyPlayer($player_id, 'lastHand', 'Last hand', array ('other_cards' => $all_cards_but_mine ));
}


That's the best solution I found so far as it only takes $N$ notifications. I guess I'll keep going with this until I eventually find something better.

Anyway, thanks for your help ;)

Re: Custom notifications

Posted: 06 May 2020, 19:07
by Lilzer7
shadowphiar wrote: 06 May 2020, 18:42 I think you do need to create separate arrays for each player's notification. One clean way to do this would be to create a single array which contains everything, then for each player, call array_filter to take out the secret information before sending the rest to the client.
Oh thank you, I didn't know this, sounds nice !! As mentioned in my previous post, I used array_diff_key but at first glance your solution seems better. I will definitly take a look at that !

Thanks ;)