Skip to content

Instantly share code, notes, and snippets.

@almirsarajcic
Last active December 14, 2015 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save almirsarajcic/5064644 to your computer and use it in GitHub Desktop.
Save almirsarajcic/5064644 to your computer and use it in GitHub Desktop.
Function returns decimal player slot for $player_slot returned by DOTA2 WebAPI. $player_slot∈(0, 4)∪(128, 132) result∈(0, 9)
<?php
function determine_playerslot($player_slot)
{
$binary = sprintf('%08b', $player_slot);
$team = substr($binary, 0, 1);
$slot = bindec(substr($binary, 1));
return $team * 5 + $slot;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment