Esempio n. 1
0
    private void AssignTeams()
    {
        var numberOfTeams = (uint)this.TeamsCsv.Split(",").Length;

        var hashSum = 0;

        var players = PlayersCsv.Split(",");

        for (uint playerIndex = 0; playerIndex < numberOfTeams; playerIndex++)
        {
            var addressHash = players[playerIndex] + players[(playerIndex + 1) % numberOfTeams];

            foreach (var letter in addressHash)
            {
                hashSum += letter;
            }
        }

        var shifterNumber = hashSum % (TeamsCsv.LastIndexOf(",") - 1); // find random point in the string

        var randomCommaIndex  = TeamsCsv.IndexOf(',', shifterNumber);
        var stringBeforeComma = TeamsCsv.Substring(0, randomCommaIndex);
        var stringAfterComma  = TeamsCsv.Substring(randomCommaIndex + 1);

        var randomisedTeamsCsv = stringAfterComma + "," + stringBeforeComma;

        this.AssignedTeamsCsv = randomisedTeamsCsv;

        foreach (var team in randomisedTeamsCsv.Split(","))
        {
            AssignedTeams.Add(team.Trim());
        }
    }
Esempio n. 2
0
    public void DeclareResult(string winningTeam, string secondPlace, string thirdPlace)
    {
        Assert(Message.Sender == Owner);
        Assert(winningTeam != secondPlace);

        var assignedTeams = AssignedTeamsCsv.Split(",");
        var players       = PlayersCsv.Split(",");
        var nickNames     = PlayersNickNames.Split(",");

        winningTeam = winningTeam.Trim().ToLower();
        secondPlace = secondPlace.Trim().ToLower();
        thirdPlace  = thirdPlace.Trim().ToLower();

        Assert(winningTeam != secondPlace);
        Assert(secondPlace != thirdPlace);
        Assert(thirdPlace != winningTeam);

        Assert(TeamsCsv.Contains(winningTeam));
        Assert(TeamsCsv.Contains(secondPlace));
        Assert(TeamsCsv.Contains(thirdPlace));

        var winner = uint.MaxValue;
        var second = uint.MaxValue;
        var third  = uint.MaxValue;

        for (uint i = 0; i < assignedTeams.Length; i++)
        {
            var team = assignedTeams[i];

            if (team == winningTeam)
            {
                winner = i;
            }

            if (team == secondPlace)
            {
                second = i;
            }

            if (team == thirdPlace)
            {
                third = i;
            }
        }

        Result =
            $"{nickNames[winner]}({players[winner]}) : {assignedTeams[winner]} : {(FirstPrizeSatoshis / SatoshiMuliplier)} {Currency(Message.ContractAddress)}\r\n" +
            $"{nickNames[second]}({players[second]}) : {assignedTeams[second]} : {(SecondPrizeSatoshis / SatoshiMuliplier)} {Currency(Message.ContractAddress)}\r\n" +
            $"{nickNames[third]}({players[third]}) : {assignedTeams[third]} : {(ThirdPrizeSatoshis / SatoshiMuliplier)} {Currency(Message.ContractAddress)}";

        TransferFunds(new Address(players[winner]), FirstPrizeSatoshis);
        TransferFunds(new Address(players[second]), SecondPrizeSatoshis);
        TransferFunds(new Address(players[third]), ThirdPrizeSatoshis);
    }