Skip to content

Commit 8195de3

Browse files
alexp8Sneer-ra2Copilot
authored
Develop (#408)
* UI part and DB migration. * fix .clan view not found, enable new 2v2 matching logic * Added faction policy service. * Added point system simulation. * Route for point system simulation. * Changes according to code review. * Added default values. * Fixed counting factions played per month. * Minor improvements. * feature/show observers page (#405) * add a page to view observers * Update cncnet-api/app/Http/Controllers/AdminController.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * include user alias in observers page * 2v2 match fix * fix duplicate team member --------- Co-authored-by: Sneer <forum@snear.de> Co-authored-by: Sneer-ra2 <116219243+Sneer-ra2@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 68bfd8f commit 8195de3

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

cncnet-api/app/Extensions/Qm/Matchup/TeamMatchupHandler.php

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ public function matchup(): void
2626
return;
2727
}
2828

29-
// Fetch all other players in the queue
30-
$opponents = $this->quickMatchService->fetchQmQueueEntry($this->history, $this->qmQueueEntry);
29+
// Fetch all other players in the queue and exclude current player
30+
$opponents = $this->quickMatchService->fetchQmQueueEntry($this->history, $this->qmQueueEntry)
31+
->filter(function($entry) {
32+
return $entry->id !== $this->qmQueueEntry->id;
33+
})->values();
3134
$count = $opponents->count() + 1;
3235
$timeInQueue = $this->qmQueueEntry->secondsinQueue();
3336
Log::debug("FindOpponent ** inQueue={$playerInQueue}, players in q: {$count}, for ladder={$ladder->abbreviation}, seconds in Queue: {$timeInQueue}");
@@ -39,7 +42,10 @@ public function matchup(): void
3942
$matchableOpponents = $this->getEntriesInPointRange2v2($this->qmQueueEntry, $matchableOpponents);
4043

4144
$opponentCount = $matchableOpponents->count();
42-
Log::debug("FindOpponent ** inQueue={$playerInQueue}, amount of matchable opponent after point filter: {$opponentCount} of {$count}");
45+
$matchableNames = $matchableOpponents->map(function($entry) {
46+
return $entry->qmPlayer?->player?->username ?? 'Unknown';
47+
})->implode(', ');
48+
Log::debug("FindOpponent ** inQueue={$playerInQueue}, amount of matchable opponent after point filter: {$opponentCount} of {$count}. Names: [{$matchableNames}]");
4349

4450
// Count the number of players we need to start a match
4551
// Excluding current player
@@ -74,6 +80,11 @@ public function matchup(): void
7480
Log::debug("Team A (" . $teamAPlayers->count() . "): " . $teamALog);
7581
Log::debug("Team B (" . $teamBPlayers->count() . "): " . $teamBLog);
7682

83+
// Ensure both teams have exactly two players
84+
if ($teamAPlayers->count() !== 2 || $teamBPlayers->count() !== 2) {
85+
Log::warning("Team size error: Team A has {$teamAPlayers->count()} players, Team B has {$teamBPlayers->count()} players. Expected 2 each.");
86+
}
87+
7788
$players = $teamAPlayers->merge($teamBPlayers);
7889

7990
$commonQmMaps = $this->quickMatchService->getCommonMapsForPlayers($ladder, $players);
@@ -92,6 +103,12 @@ public function matchup(): void
92103
$this->matchHasObservers = true;
93104
}
94105

106+
// Throw exception if team sizes are not exactly two
107+
if ($teamAPlayers->count() !== 2 || $teamBPlayers->count() !== 2) {
108+
Log::warning("Team size error: Team A has {$teamAPlayers->count()} players, Team B has {$teamBPlayers->count()} players. Expected 2 each.");
109+
throw new \RuntimeException("Team size error: Team A has {$teamAPlayers->count()} players, Team B has {$teamBPlayers->count()} players. Expected 2 each.");
110+
}
111+
95112
// Start the match with all other players and other observers if there is any
96113
$this->createTeamMatch($commonQmMaps, $teamAPlayers, $teamBPlayers, $observers, $stats);
97114
}
@@ -191,12 +208,21 @@ public function getEntriesInPointRange2v2(QmQueueEntry $currentQmQueueEntry, Col
191208
private function getCombinations(Collection $items, int $size): Collection
192209
{
193210
$array = $items->all();
211+
$allNames = collect($array)->map(function($entry) {
212+
return $entry->qmPlayer?->player?->username ?? 'Unknown';
213+
})->implode(', ');
214+
Log::debug("getCombinations called with items: [{$allNames}] and size: {$size}");
194215
$results = [];
195216

196217
$recurse = function ($arr, $size, $start = 0, $current = []) use (&$results, &$recurse)
197218
{
198219
if (count($current) === $size)
199220
{
221+
// Debug log the combination
222+
$names = collect($current)->map(function($entry) {
223+
return $entry->qmPlayer?->player?->username ?? 'Unknown';
224+
})->implode(', ');
225+
Log::debug("getCombinations: [{$names}]");
200226
$results[] = $current;
201227
return;
202228
}

cncnet-api/app/Http/Services/QuickMatchService.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,7 +1653,9 @@ public function getRandomTeams($possibleMatches): array
16531653
public function getBestMatch2v2ForPlayer(QmQueueEntry $currentPlayer, Collection $matchableOpponents, LadderHistory $history): array
16541654
{
16551655

1656-
$players = $matchableOpponents->concat([$currentPlayer]);
1656+
// Ensure matchableOpponents does not contain the current player and is unique by id
1657+
$matchableOpponents = $matchableOpponents->filter(fn($opponent) => $opponent->id !== $currentPlayer->id)->unique('id')->values();
1658+
$players = $matchableOpponents->concat([$currentPlayer])->unique('id')->values();
16571659

16581660
$opponentsRating = [];
16591661
$currentPlayerRank = $currentPlayer->qmPlayer->player->points($history);
@@ -1672,17 +1674,16 @@ public function getBestMatch2v2ForPlayer(QmQueueEntry $currentPlayer, Collection
16721674
$opponentsRating
16731675
);
16741676

1675-
// $matchup = $this->findBestMatch($possibleMatches);
1676-
// $matchup = $this->getRandomTeams($possibleMatches);
16771677
$matchup = $this->findBestMatchRandomized($possibleMatches);
16781678

16791679
$g = function ($players, $match, $team)
16801680
{
1681+
// Only include unique players by id
16811682
return $players
16821683
->filter(fn(QmQueueEntry $qmQueueEntry) => in_array($qmQueueEntry->id, [
16831684
$match[$team]['player1'],
16841685
$match[$team]['player2']
1685-
]));
1686+
]))->unique('id')->values();
16861687
};
16871688

16881689
$teamAPlayers = $g($players, $matchup, 'teamA');

0 commit comments

Comments
 (0)