Available functions

Game development with Board Game Arena Studio
Post Reply
User avatar
cora89
Posts: 29
Joined: 14 June 2012, 20:29

Available functions

Post by cora89 »

is there a list of functions available ? With args and descriptions.
For example :
I have to add a card in the player's hand from the deck.
I'm sure it already exists (stoneage must have it) but i did not find it in reversi or hearts...
Hearts makes moves between players or 13 from the deck but not just one to add in hand.

It may be a silly question but please, be gentle. ;)
User avatar
sourisdudesert
Administrateur
Posts: 4630
Joined: 23 January 2010, 22:02

Re: Available functions

Post by sourisdudesert »

Hi,

I've started to document the "deck" component there:
http://en.doc.boardgamearena.com/Deck

This is (unfortunately) still uncomplete.

To add a card from the deck to a player hand, you can use the following:
$card = $this->cards->pickCard( 'deck', $player_id );

Afterwards, you generally notify the player about his new card:

self::notifyPlayer( $player_id, 'newCard', '', array(
'card' => $card
) );

All the best,
User avatar
cora89
Posts: 29
Joined: 14 June 2012, 20:29

Re: Available functions

Post by cora89 »

ok, i wasn't sure that the pickCard function worked without the first argument.
And i was searching a concatenation function to add it in the hand...
i'll go back to work.
Thx :D
User avatar
Quinarbre
Posts: 140
Joined: 15 December 2013, 23:26

Re: Available functions

Post by Quinarbre »

Hi,

How is auto-reshuffling supposed to work ?
- I create a deck, putting all the cards in the 'deck' location
- I can pickCard and playCard, played cards do go to the 'discard'
- but when the 'deck' is empty, pickCard doesn't work anymore and the deck isn't reconstitued.

I've tried many variants :
- using pickCards(1, ..)
- shuffling the deck initially or not
- adding a 3rd boolean argument to pickCard
nothing solves the issue.

What am I doing wrong ?
Thanks.
User avatar
pikiou
Posts: 389
Joined: 03 October 2011, 05:36

Re: Available functions

Post by pikiou »

This answer is not gonna help at all, but this is exactly why I never used this component: a few arrays do the the same job and you have full control.
User avatar
daikinee
Posts: 32
Joined: 19 November 2011, 01:19

Re: Available functions

Post by daikinee »

Quinarbre wrote:Hi,

How is auto-reshuffling supposed to work ?
- I create a deck, putting all the cards in the 'deck' location
- I can pickCard and playCard, played cards do go to the 'discard'
- but when the 'deck' is empty, pickCard doesn't work anymore and the deck isn't reconstitued.

I've tried many variants :
- using pickCards(1, ..)
- shuffling the deck initially or not
- adding a 3rd boolean argument to pickCard
nothing solves the issue.

What am I doing wrong ?
Thanks.
Got the same bug and tried different things without success.

Can we have an answer from the BGA developers?
User avatar
tarini
Posts: 45
Joined: 11 July 2013, 22:36
Location: italy
Contact:

Re: Available functions

Post by tarini »

pikiou wrote:This answer is not gonna help at all, but this is exactly why I never used this component: a few arrays do the the same job and you have full control.
pikiou is completely right
User avatar
daikinee
Posts: 32
Joined: 19 November 2011, 01:19

Re: Available functions

Post by daikinee »

Please read my carefully:
daikinee wrote: Can we have an answer from the BGA developers?
I don't think pikiou is a BGA developers and has access to the PHP source code.

I would prefer the "Deck" class or the documentation is corrected than using my own class, cause i'm a lazy as a sysadmin guy ;-)
User avatar
pikiou
Posts: 389
Joined: 03 October 2011, 05:36

Re: Available functions

Post by pikiou »

Thanks tarini ^^

Daikinee I am a BGA developer just like you and I do have partial access to the PHP source code of the framework, but I think you're looking for a BGA admin.

The reason I never used the Deck class is that the PHP library does all I ever needed, transparently.
pickCard( $location, $player_id ) => $player['hand'][] = array_pop($deck)
pickCards( $nbr, $location, $player_id ) => $player['hand'] = array_merge($player['hand'], array_splice($deck, -$nbr))

Now to emulate the features around $location_arg, I use array_column. It's not yet available on BGA (requires PHP >= 5.5) so I use a version attached at the end of this post.
How does it work? Imagine you have this deck of cards:

Code: Select all

$deck = Array(
   Array('id' => 2, 'type' => 'weapon'),
   Array('id' => 5, 'type' => 'spell'),
   Array('id' => 3, 'type' => 'weapon'));
array_column($deck, 'type') returns Array('weapon', 'spell', 'weapon')
And you can do whatever you want with that:

Code: Select all

$weaponCardKeys = array_intersect(array_column($deck, 'type'), Array('weapon'));
$weaponCards = array_intersect_key($deck, $weaponCardKeys);
$deckWithoutWeapons = array_values(array_diff_key($deck, $weaponCardKeys));
I'm not saying you should avoid the Deck component, but if you want to use array manipulation instead, these hacks could help ^^

Here is the array_column function:

Code: Select all

   function array_column($input = null, $columnKey = null, $indexKey = null) {
      $params = func_get_args();
      if (!is_array($params[0])) {
         trigger_error('array_column() expects parameter 1 to be array, ' . gettype($params[0]) . ' given', E_USER_WARNING);
         return null;
      }

      if (!is_int($params[1]) && !is_float($params[1]) && !is_string($params[1]) && $params[1] !== null && !(is_object($params[1]) && method_exists($params[1], '__toString'))
      ) {
         trigger_error('array_column(): The column key should be either a string or an integer', E_USER_WARNING);
         return false;
      }

      if (isset($params[2]) && !is_int($params[2]) && !is_float($params[2]) && !is_string($params[2]) && !(is_object($params[2]) && method_exists($params[2], '__toString'))
      ) {
         trigger_error('array_column(): The index key should be either a string or an integer', E_USER_WARNING);
         return false;
      }

      $paramsInput = $params[0];
      $paramsColumnKey = ($params[1] !== null) ? (string) $params[1] : null;

      $paramsIndexKey = null;
      if (isset($params[2])) {
         if (is_float($params[2]) || is_int($params[2])) {
            $paramsIndexKey = (int) $params[2];
         } else {
            $paramsIndexKey = (string) $params[2];
         }
      }

      $resultArray = array();

      foreach ($paramsInput as $row) {
         $key = $value = null;
         $keySet = $valueSet = false;

         if ($paramsIndexKey !== null && array_key_exists($paramsIndexKey, $row)) {
            $keySet = true;
            $key = (string) $row[$paramsIndexKey];
         }

         if ($paramsColumnKey === null) {
            $valueSet = true;
            $value = $row;
         } elseif (is_array($row) && array_key_exists($paramsColumnKey, $row)) {
            $valueSet = true;
            $value = $row[$paramsColumnKey];
         }

         if ($valueSet) {
            if ($keySet) {
               $resultArray[$key] = $value;
            } else {
               $resultArray[] = $value;
            }
         }
      }
      return $resultArray;
   }
Post Reply

Return to “Developers”