find pest positions
This commit is contained in:
1 parent
c0c4373ba0
commit
d6fe50e69a
3 files changed
+106
-16
No files matched your search
@@ -694,18 +694,6 @@ class PlayerPropsDrop extends Widget
|
||||
|
||||
public function generateLineUp(): void
|
||||
{
|
||||
// {
|
||||
// "975216": 6,
|
||||
// "1122806": 9,
|
||||
// "1003010": 11,
|
||||
// "881215": 16,
|
||||
// "158277": 18,
|
||||
// "221636": 19,
|
||||
// "2282985": 21,
|
||||
// "1631268": 23,
|
||||
// "1064039": 25,
|
||||
// "922559": 34
|
||||
// }
|
||||
if ($this->activeLineUp && $this->team_id) {
|
||||
|
||||
$players = $this->prepareLineUp();
|
||||
@@ -728,19 +716,19 @@ class PlayerPropsDrop extends Widget
|
||||
} else {
|
||||
if (isset($hirarchy[$position])) {
|
||||
$position = $hirarchy[$position][0];
|
||||
$fitered = $players->where('pos', $position)->sortByDesc('min')->first();
|
||||
$fitered = $players->where('pos', $position)->whereNotIn('id', $id_used)->sortByDesc('min')->first();
|
||||
if (isset($fitered['id'])) {
|
||||
$lineup[$fitered['id']] = ['id' => $fitered['id'], 'place' => $place, 'position' => $position];
|
||||
$id_used[] = $fitered['id'];
|
||||
} elseif (isset($hirarchy[$position][1])) {
|
||||
$position = $hirarchy[$position][1];
|
||||
$fitered = $players->where('pos', $position)->sortByDesc('min')->first();
|
||||
$fitered = $players->where('pos', $position)->whereNotIn('id', $id_used)->sortByDesc('min')->first();
|
||||
if (isset($fitered['id'])) {
|
||||
$lineup[$fitered['id']] = ['id' => $fitered['id'], 'place' => $place, 'position' => $position];
|
||||
$id_used[] = $fitered['id'];
|
||||
} elseif (isset($hirarchy[$position][2])) {
|
||||
$position = $hirarchy[$position][2];
|
||||
$fitered = $players->where('pos', $position)->sortByDesc('min')->first();
|
||||
$fitered = $players->where('pos', $position)->whereNotIn('id', $id_used)->sortByDesc('min')->first();
|
||||
if (isset($fitered['id'])) {
|
||||
$lineup[$fitered['id']] = ['id' => $fitered['id'], 'place' => $place, 'position' => $position];
|
||||
$id_used[] = $fitered['id'];
|
||||
@@ -762,7 +750,9 @@ class PlayerPropsDrop extends Widget
|
||||
foreach ($this->players as $k => $record) {
|
||||
$id = $record['id'];
|
||||
if (isset($lineup[$id])) {
|
||||
|
||||
$this->boxes[$lineup[$id]['place']] = $record;
|
||||
|
||||
$this->players[$k]['active'] = 1;
|
||||
$this->players[$k]['pos'] = $lineup[$id]['position'];
|
||||
|
||||
@@ -778,4 +768,97 @@ class PlayerPropsDrop extends Widget
|
||||
$this->storePlacement();
|
||||
}
|
||||
}
|
||||
|
||||
public function majorFormations(): array
|
||||
{
|
||||
// 343+
|
||||
// 352
|
||||
// 433+
|
||||
// 442+
|
||||
// 4231
|
||||
// 4321+
|
||||
// 4312+
|
||||
// 4411+
|
||||
return [
|
||||
'343+' => [9, 16, 23, 4, 11, 25, 32, 6, 34, 21],
|
||||
'352' => [9, 16, 23, 4, 11, 17, 25, 32, 20, 21],
|
||||
'433+' => [2, 9, 23, 30, 11, 18, 25, 6, 34, 21],
|
||||
'442+' => [2, 9, 23, 30, 4, 11, 25, 32, 20, 21],
|
||||
'4231' => [2, 9, 23, 30, 10, 24, 12, 19, 26, 21],
|
||||
'4321+' => [2, 9, 23, 30, 11, 18, 25, 12, 26, 21],
|
||||
'4312+' => [2, 9, 23, 30, 11, 18, 25, 19, 20, 21],
|
||||
'4411+' => [2, 9, 23, 30, 4, 11, 25, 32, 19, 21],
|
||||
];
|
||||
}
|
||||
|
||||
public function generateBestLineUp(): void
|
||||
{
|
||||
if (! $this->team_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
$all_lineups = [];
|
||||
|
||||
$players = $this->prepareLineUp();
|
||||
|
||||
$hirarchy = PositionHirarchie::load();
|
||||
|
||||
$major_formations = self::majorFormations();
|
||||
|
||||
foreach ($major_formations as $formation_name => $formation_positions) {
|
||||
|
||||
$lineup = [];
|
||||
|
||||
$id_used = [];
|
||||
|
||||
foreach ($formation_positions as $place) {
|
||||
|
||||
$position = $this->activeBoxes[$place];
|
||||
|
||||
$player = $players->where('pos', $position)->whereNotIn('id', $id_used)->sortByDesc('min')->first();
|
||||
|
||||
if (isset($player['id'])) {
|
||||
$lineup[$player['id']] = ['id' => $player['id'], 'min' => $player['min'], 'place' => $place, 'position' => $position];
|
||||
$id_used[] = $player['id'];
|
||||
} else {
|
||||
if (isset($hirarchy[$position])) {
|
||||
$position = $hirarchy[$position][0];
|
||||
$player = $players->where('pos', $position)->whereNotIn('id', $id_used)->sortByDesc('min')->first();
|
||||
if (isset($player['id'])) {
|
||||
$lineup[$player['id']] = ['id' => $player['id'], 'min' => $player['min'], 'place' => $place, 'position' => $position];
|
||||
$id_used[] = $player['id'];
|
||||
} elseif (isset($hirarchy[$position][1])) {
|
||||
$position = $hirarchy[$position][1];
|
||||
$player = $players->where('pos', $position)->whereNotIn('id', $id_used)->sortByDesc('min')->first();
|
||||
if (isset($player['id'])) {
|
||||
$lineup[$player['id']] = ['id' => $player['id'], 'min' => $player['min'], 'place' => $place, 'position' => $position];
|
||||
$id_used[] = $player['id'];
|
||||
} elseif (isset($hirarchy[$position][2])) {
|
||||
$position = $hirarchy[$position][2];
|
||||
$player = $players->where('pos', $position)->whereNotIn('id', $id_used)->sortByDesc('min')->first();
|
||||
if (isset($player['id'])) {
|
||||
$lineup[$player['id']] = ['id' => $player['id'], 'min' => $player['min'], 'place' => $place, 'position' => $position];
|
||||
$id_used[] = $player['id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$all_lineups[$formation_name] = $lineup;
|
||||
}
|
||||
|
||||
$tmp = [];
|
||||
foreach ($all_lineups as $formation_name => $lineup) {
|
||||
$tmp[$formation_name] = array_sum(array_column($lineup, 'min'));
|
||||
}
|
||||
$formation_name = array_search(max($tmp), $tmp);
|
||||
|
||||
$this->dispatch('update-lineup', $formation_name);
|
||||
|
||||
$this->lineUpUpdate($formation_name);
|
||||
|
||||
$this->generateLineUp();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user