From 0293e3a40ab27616e28a95cd995835ac09d265b4 Mon Sep 17 00:00:00 2001 From: hide_d Date: Sun, 3 May 2020 03:36:21 +0900 Subject: [PATCH] =?UTF-8?q?=ED=86=A0=EB=84=88=EB=A8=BC=ED=8A=B8=20?= =?UTF-8?q?=EB=B2=84=EA=B7=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/c_tournament.php | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/hwe/c_tournament.php b/hwe/c_tournament.php index accbc55d..05fb6c85 100644 --- a/hwe/c_tournament.php +++ b/hwe/c_tournament.php @@ -48,14 +48,27 @@ if($btn == '참가') { } $general['gold'] -= $admin['develcost']; - $occupied = []; - foreach($db->queryFirstColumn('SELECT grp FROM tournament WHERE grp < 10 GROUP BY grp HAVING count(*)=8') as $grp){ - $occupied[$grp] = true; + $freeSlot = [ + 1=>8, + 2=>8, + 3=>8, + 4=>8, + 5=>8, + 6=>8, + 7=>8, + 8=>8, + ]; + foreach($db->query('SELECT count(*) as cnt, grp FROM tournament WHERE grp < 10 GROUP BY grp') as $grpInfo){ + if($grpInfo['cnt'] == 8){ + unset($freeSlot[$grpInfo['grp']]); + } + $freeSlot[$grpInfo['grp']] = 8 - $grpInfo['cnt']; } - $grpCount = count($occupied); + + $fullGrpCnt = 8 - count($freeSlot); - if($grpCount < 8) { - $grp = Util::choiceRandom(array_keys($occupied)); + if($freeSlot) { + $grp = Util::choiceRandom(array_keys($freeSlot)); $grpMemberCount = $db->queryFirstField('SELECT count(*) FROM tournament WHERE grp=%i', $grp); $db->insert('tournament', [ 'no'=>$general['no'],