Created
May 15, 2018 08:55
-
-
Save xpdlf1004/f525d41e0770526ba93f19140536dbe4 to your computer and use it in GitHub Desktop.
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
function run(bytes playerData, uint8[4] eventTypes, uint8[2][4] eventColors) public onlyOperator { | |
require(playerData.length == 128 * PLAYER_SIZE); | |
_initRandom(); | |
uint8[] memory colorSelection = new uint8[](8); | |
colorSelection[0] = 0; | |
colorSelection[1] = 1; | |
colorSelection[2] = 0; | |
colorSelection[3] = 1; | |
colorSelection[4] = 0; | |
colorSelection[5] = 1; | |
colorSelection[6] = 0; | |
colorSelection[7] = 1; | |
_shuffle(colorSelection); | |
uint[4] memory totalScores; | |
for (uint8 i = 0; i < 4; i++) { | |
uint8 majorColor = eventColors[i][colorSelection[i]]; | |
uint8 minorColor = eventColors[i][colorSelection[i]^1]; | |
uint[4] memory roundScores = _round(playerData, EventType(eventTypes[i]), EventColor(majorColor), EventColor(minorColor)); | |
totalScores[0] += roundScores[0]; | |
totalScores[1] += roundScores[1]; | |
totalScores[2] += roundScores[2]; | |
totalScores[3] += roundScores[3]; | |
} | |
AllFinished(totalScores[0], totalScores[1], totalScores[2], totalScores[3]); | |
uint maxScore; | |
uint maxCount; | |
uint8[4] memory candidates; | |
for (i = 0; i < 4; i++) { | |
if (maxScore < totalScores[i]) { | |
maxScore = totalScores[i]; | |
maxCount = 0; | |
candidates[maxCount++] = i + 1; | |
} else if (maxScore == totalScores[i]) { | |
candidates[maxCount++] = i + 1; | |
} | |
} | |
assert(maxCount > 0); | |
if (maxCount == 1) { | |
WinnerTeam(candidates, candidates[0]); | |
} else { | |
WinnerTeam(candidates, candidates[_random256() % maxCount]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment