Created
May 24, 2021 22:33
-
-
Save germandiagogomez/9ed37e49d7512f5372097f0af3be27d6 to your computer and use it in GitHub Desktop.
Free functions in ChaiScript
This file contains 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
def nextPlayer(player) { | |
return ((player + 1) % 4) | |
} | |
// typed (optional) | |
def nextPlayer2(int player) { | |
return ((player + 1) % 4) | |
} | |
def getPlayerPositionRelativeTo(refPlayer, targetPlayer) { | |
if (refPlayer == targetPlayer) { | |
return BottomPlayer | |
} | |
var diff = 0 | |
var curr = nextPlayer(refPlayer) | |
++diff | |
while (curr != targetPlayer) { | |
curr = nextPlayer(curr) | |
++diff | |
} | |
if (diff == 0) { | |
return BottomPlayer | |
} | |
else if (diff == 1) { | |
return LeftPlayer | |
} | |
else if (diff == 2) { | |
return FrontPlayer | |
} | |
else if (diff == 3) { | |
return RightPlayer | |
} | |
else { | |
throw("Error calculating the player position. This is a bug") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment