Last active
December 14, 2015 09:28
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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