| 555 | } |
| 556 | if (!_selection) |
| 557 | { |
| 558 | return false; |
| 559 | } |
| 560 | |
| 561 | // let |
| 562 | // rest = number of players that did not vote yet |
| 563 | // first = number of players that voted for the most popular choice |
| 564 | // second = number of players that voted for the second most popular choice |
| 565 | // voting is done when |
| 566 | // first>=second+rest |
| 567 | |
| 568 | int first = 0, second = 0; |
| 569 | int rest = identities.Size() - sum; |
| 570 | GetValue(&first, &second); |
| 571 | LOG_DEBUG(Network, "First {}, second {}, rest {}", first, second, rest); |
| 572 | return Poseidon::VoteSelectionComplete(first, second, rest); |
| 573 | } |
| 574 | |
| 575 | const AutoArray<char>* Voting::GetValue(int* n, int* n2) const |
| 576 | { |
| 577 | if (Size() == 0) |
| 578 | { |
| 579 | return nullptr; |
| 580 | } |
| 581 | |
| 582 | AUTO_STATIC_ARRAY(const Vote*, values, 32); |
| 583 | AUTO_STATIC_ARRAY(int, votes, 32); |
| 584 | for (int i = 0; i < Size(); i++) |
| 585 | { |
| 586 | int found = -1; |
| 587 | const char* value = Get(i).value.Data(); |
| 588 | int valueSize = Get(i).value.Size(); |
| 589 | for (int j = 0; j < values.Size(); j++) |
| 590 | { |
| 591 | if (values[j]->HasValue(value, valueSize)) |
| 592 | { |
| 593 | found = j; |
| 594 | break; |
| 595 | } |
| 596 | } |
| 597 | if (found >= 0) |
| 598 | { |
| 599 | votes[found]++; |
| 600 | } |
| 601 | else |
| 602 | { |
| 603 | values.Add(&Get(i)); |
| 604 | votes.Add(1); |
| 605 | } |
| 606 | } |
| 607 | const Vote* best = nullptr; |
| 608 | int maxVotes = 0; |
| 609 | for (int i = 0; i < votes.Size(); i++) |
| 610 | { |
| 611 | if (votes[i] > maxVotes) |
| 612 | { |
| 613 | maxVotes = votes[i]; |
| 614 | best = values[i]; |