Ejemplo n.º 1
0
    private void Start()
    {
        Debug.Log("Some jerks showed up:");
        for (int i = 0; i < JerkCount; i++)
        {
            var jerkVote = new InputVote
            {
                VoterID         = Guid.NewGuid().ToString(),
                DirectionChoice = null,
                Weight          = JerkWeight
            };
            Debug.Log($"\t{jerkVote.VoterID} is a jerk");
            _votes.Add(jerkVote);
        }

        StartCoroutine(co_BeAJerk());
    }
Ejemplo n.º 2
0
    //private void Update()
    //{
    //    var inputDirection = CalculateVotedInput_Discrete();
    //    MazeController.SetTilt(inputDirection);
    //}

    public void ApplyVote(InputVote vote)
    {
        var existingVote = Votes.FirstOrDefault(v => v.VoterID == vote.VoterID);

        if (existingVote == null)
        {
            var choice = (vote.DirectionChoice.HasValue) ? Enum.GetName(typeof(ChoosableDirection), vote.DirectionChoice) : "Nothing";
            Debug.Log($"New voter registered: {vote.VoterID} with weight {vote.Weight} chose {choice}");
            //Copying the new vote so it can't be modified by reference
            existingVote = new InputVote
            {
                VoterID         = vote.VoterID,
                DirectionChoice = vote.DirectionChoice,
                Weight          = vote.Weight
            };
            Votes.Add(existingVote);
        }
        else if (existingVote.DirectionChoice == vote.DirectionChoice)
        {
            //Don't waste time if the vote hasn't actually changed
            return;
        }
        else
        {
            var oldChoice = (existingVote.DirectionChoice.HasValue) ? Enum.GetName(typeof(ChoosableDirection), existingVote.DirectionChoice) : "Nothing";
            var newChoice = (vote.DirectionChoice.HasValue) ? Enum.GetName(typeof(ChoosableDirection), vote.DirectionChoice) : "Nothing";
            Debug.Log($"Updating vote {existingVote.VoterID} with weight {existingVote.Weight} from {oldChoice} to {newChoice}");

            if (existingVote.DirectionChoice.HasValue)
            {
                Choices[existingVote.DirectionChoice.Value].tally -= existingVote.Weight;
            }
            existingVote.DirectionChoice = vote.DirectionChoice;
        }

        if (existingVote.DirectionChoice.HasValue)
        {
            Choices[existingVote.DirectionChoice.Value].tally += existingVote.Weight;
        }

        //Debug.Log("Tallies have changed");
        TalliesHaveChanged = true;
    }