Example #1
0
function downsizegame($downsizetype)
{
    global $GAME;
    $GAME['MoveMade'] = 1;
    $GAME['KickVote'] = '00000';
    $GAME['SecondRailMode'] = 0;
    $GAME['SecondDevelopMode'] = 0;
    $GAME['ContinueSellingMode'] = 0;
    if ($GAME['GameStatus'] == 'In Progress') {
        if (KickPlayer($GAME['PlayerToMove'], 3)) {
            return;
        }
        // If KickPlayer aborts the game then it will return true.
        // We don't want any shenanigans going on after a game is aborted.
    }
    $GAME['PlayersMissing']--;
    $GAME['PlayerMissing'][$GAME['PlayerToMove']] = 0;
    $GAME['PlayersMissingThatMatter']--;
    $GAME['PlayerMissingAndMatters'][$GAME['PlayerToMove']] = 0;
    dbquery(DBQUERY_WRITE, 'DELETE FROM "ReplacementOffer" WHERE "Game" = :game: AND "Colour" = :colour:', 'game', $GAME['GameID'], 'colour', $GAME['PlayerToMove']);
    $GAME['GameStatus'] = 'In Progress';
    if ($downsizetype) {
        $GAME['AltGameTicker'] .= '7A' . callmovetimediff();
    } else {
        $GAME['AltGameTicker'] .= '7B' . callmovetimediff();
    }
    $GAME['PlayerExists'][$GAME['PlayerToMove']] = 0;
    for ($i = 0; $i < $GAME['NumIndustrySpaces']; $i++) {
        if ($GAME['SpaceStatus'][$i] == $GAME['PlayerToMove']) {
            $GAME['SpaceStatus'][$i] = 8;
        }
    }
    for ($i = 0; $i < $GAME['RailPhase'] * $GAME['NumRailLinks'] + (1 - $GAME['RailPhase']) * $GAME['NumCanalLinks']; $i++) {
        if ($GAME['LinkStatus'][$i] == $GAME['PlayerToMove']) {
            $GAME['LinkStatus'][$i] = 8;
        }
    }
    switch ($GAME['CurrentPlayers']) {
        case 4:
            if ($GAME['Round'] < 3) {
                $GAME['NumRounds'] = 10;
            } else {
                if ($GAME['Round'] == 3) {
                    $GAME['NumRounds'] = 9;
                }
            }
            if (!$GAME['RailPhase'] or $GAME['Round'] < 4) {
                $GAME['EffectiveNumPlayers'] = 3;
            }
            $GAME['ShuffledDeck'] = array_reverse($GAME['ShuffledDeck']);
            if (count($GAME['ShuffledDeck']) == 1 and $GAME['ShuffledDeck'][0] === '') {
                $GAME['ShuffledDeck'] = array();
            }
            shuffle($GAME['Cards'][$GAME['PlayerToMove']]);
            for ($i = 0; $i < $GAME['HandSize'][$GAME['PlayerToMove']]; $i++) {
                $GAME['ShuffledDeck'][] = array_pop($GAME['Cards'][$GAME['PlayerToMove']]);
            }
            $GAME['ShuffledDeck'] = array_reverse($GAME['ShuffledDeck']);
            $GAME['AltGameTicker'] .= 'AAA9J';
            break;
        case 3:
            // At present, it is not permitted for games to be downsized from 3 players to 2 players.
            // This function should not be called when CurrentPlayers is equal to 3; it will stop script execution with an error message.
            die('Programming error: Downsize function called when number of players is 3. Please contact Administrator and give details of how you obtained this error message.');
            break;
        case 2:
            for ($i = 0; $i < MAX_PLAYERS; $i++) {
                if ($GAME['PlayerExists'][$i]) {
                    $TheLastPlayer = $i;
                }
            }
            if ($GAME['RailPhase'] and $GAME['NumRounds'] - $GAME['Round'] < 2) {
                require_once HIDDEN_FILES_PATH . 'scoringresource.php';
                endgamescoring();
            } else {
                $GAME['GameStatus'] = 'Finished';
                require_once HIDDEN_FILES_PATH . 'createpgr.php';
                CreatePGR(0, 0, -1, 0, $TheLastPlayer);
            }
            $GAME['AltGameTicker'] .= 'AAA9J';
            break;
    }
    $GAME['CurrentPlayers']--;
    if ($GAME['CurrentPlayers'] > 1) {
        for ($i = 0; $i < MAX_PLAYERS; $i++) {
            if ($GAME['TurnOrder'][$i] == $GAME['PlayerToMove']) {
                $WhereInTurnOrder = $i;
            }
        }
        for ($i = $WhereInTurnOrder; $i < MAX_PLAYERS - 1; $i++) {
            $GAME['TurnOrder'][$i] = $GAME['TurnOrder'][$i + 1];
        }
        $GAME['TurnOrder'][MAX_PLAYERS - 1] = $GAME['PlayerToMove'];
        if ($GAME['DebtMode']) {
            $SomeoneInDebt = 9;
            for ($i = 0; $i < MAX_PLAYERS; $i++) {
                if ($GAME['PlayerExists'][$GAME['TurnOrder'][$i]] and $GAME['Money'][$GAME['TurnOrder'][$i]] < 0) {
                    for ($j = 0; $j < $GAME['NumIndustrySpaces']; $j++) {
                        if ($GAME['SpaceStatus'][$j] == $GAME['TurnOrder'][$i]) {
                            $SomeoneInDebt = $GAME['TurnOrder'][$i];
                            break 2;
                        }
                    }
                }
            }
            if ($SomeoneInDebt == 9) {
                $GAME['DebtMode'] = 0;
                $GAME['PlayerToMove'] = $GAME['TurnOrder'][0];
            } else {
                $GAME['PlayerToMove'] = $SomeoneInDebt;
            }
        } else {
            $EndRound = true;
            for ($i = MAX_PLAYERS - 2; $i >= $WhereInTurnOrder; $i--) {
                if ($GAME['PlayerExists'][$GAME['TurnOrder'][$i]]) {
                    $GAME['PlayerToMove'] = $GAME['TurnOrder'][$i];
                    $EndRound = false;
                }
            }
            if ($EndRound) {
                if ($GAME['Round'] == $GAME['NumRounds']) {
                    if ($GAME['RailPhase']) {
                        require_once HIDDEN_FILES_PATH . 'scoringresource.php';
                        endgamescoring();
                    } else {
                        require_once HIDDEN_FILES_PATH . 'scoringresource.php';
                        require_once HIDDEN_FILES_PATH . 'turnorderresource.php';
                        canalphasescoring();
                        DoTurnOrder(1);
                    }
                } else {
                    require_once HIDDEN_FILES_PATH . 'turnorderresource.php';
                    DoTurnOrder(1);
                }
            }
        }
        if ($GAME['RailPhase'] and $GAME['Round'] == $GAME['NumRounds'] and $GAME['GameStatus'] != 'Finished') {
            require_once HIDDEN_FILES_PATH . 'nomovesresource.php';
            CheckNoMovesShell();
        }
    }
}
Example #2
0
function moveexecute($formdetails)
{
    global $GAME, $SystemActing;
    $errorlist = '';
    $MoveOn = true;
    if ($GAME['DebtMode']) {
        if ($GAME['SpaceStatus'][$formdetails['IndustrySpace']] == 9) {
            $errorlist .= transtext('memNoTileInSpace') . '<br>';
        } else {
            if ($GAME['SpaceStatus'][$formdetails['IndustrySpace']] != $GAME['PlayerToMove']) {
                $errorlist .= transtext('memTileNotYours') . '<br>';
            } else {
                destroytile($formdetails['IndustrySpace'], 1, 1);
                $GAME['MoveMade'] = 1;
                $GAME['MoveMadeByPlayer'][$GAME['PlayerToMove']] = 1;
            }
        }
        if ($GAME['Money'][$GAME['PlayerToMove']] >= 0) {
            for ($i = 0; $i < MAX_PLAYERS; $i++) {
                if ($GAME['TurnOrder'][$i] == $GAME['PlayerToMove']) {
                    $WhereInTurnOrder = $i;
                }
            }
            $GAME['DebtMode'] = 0;
            for ($i = MAX_PLAYERS - 1; $i > $WhereInTurnOrder; $i--) {
                if ($GAME['PlayerExists'][$GAME['TurnOrder'][$i]] and $GAME['Money'][$GAME['TurnOrder'][$i]] < 0) {
                    for ($j = 0; $j < $GAME['NumIndustrySpaces']; $j++) {
                        if ($GAME['SpaceStatus'][$j] == $GAME['TurnOrder'][$i]) {
                            $GAME['PlayerToMove'] = $GAME['TurnOrder'][$i];
                            $GAME['DebtMode'] = 1;
                            break;
                        }
                    }
                }
            }
            if (!$GAME['DebtMode']) {
                $GAME['PlayerToMove'] = $GAME['TurnOrder'][0];
                $MoveOn = false;
            }
        }
    } else {
        if ($GAME['SecondRailMode']) {
            if ($formdetails['LinkToBuild'] == 50) {
                if ($SystemActing) {
                    $AdminTakingMove = 0;
                } else {
                    if ($GAME['PlayerUserID'][$GAME['PlayerToMove']] == $_SESSION['MyUserID']) {
                        $AdminTakingMove = 0;
                    } else {
                        $AdminTakingMove = 1;
                    }
                }
                if ($AdminTakingMove) {
                    $ResultArray = array('', '', '2E' . callmovetimediff() . letter_end_number($_SESSION['MyUserID']) . letter_end_number($_SESSION['MyGenderCode']), '|' . $_SESSION['MyUserName']);
                } else {
                    $ResultArray = array('', '', 'J' . callmovetimediff(), '');
                }
                $GAME['SecondRailMode'] = 0;
            } else {
                require_once HIDDEN_FILES_PATH . 'coalresource.php';
                require_once HIDDEN_FILES_PATH . 'linkresource.php';
                $AssuredCoalSource = ClosestCoal($GAME['RailStarts'][$formdetails['LinkToBuild']], $GAME['RailEnds'][$formdetails['LinkToBuild']], $formdetails['CoalSource']);
                $ResultArray = buildlink($formdetails['LinkToBuild'], $AssuredCoalSource, 2, 50);
            }
            if ($ResultArray[0] == '') {
                $GAME['AltGameTicker'] .= $ResultArray[2];
                $GAME['GameTickerNames'] .= $ResultArray[3];
            } else {
                $errorlist .= $ResultArray[0];
            }
        } else {
            if ($GAME['SecondDevelopMode']) {
                if ($formdetails['TileType'] == 9) {
                    if ($SystemActing) {
                        $AdminTakingMove = 0;
                    } else {
                        if ($GAME['PlayerUserID'][$GAME['PlayerToMove']] == $_SESSION['MyUserID']) {
                            $AdminTakingMove = 0;
                        } else {
                            $AdminTakingMove = 1;
                        }
                    }
                    if ($AdminTakingMove) {
                        $ResultArray = array('', '', '2E' . callmovetimediff() . letter_end_number($_SESSION['MyUserID']) . letter_end_number($_SESSION['MyGenderCode']), '|' . $_SESSION['MyUserName']);
                    } else {
                        $ResultArray = array('', '', 'J' . callmovetimediff(), '');
                    }
                    $GAME['SecondDevelopMode'] = 0;
                } else {
                    require_once HIDDEN_FILES_PATH . 'developresource.php';
                    $AssuredIronSource = GetIron($formdetails['IronSource']);
                    $ResultArray = develop($formdetails['TileType'], $AssuredIronSource, 1, 50);
                }
                if ($ResultArray[0] == '') {
                    $GAME['AltGameTicker'] .= $ResultArray[2];
                    $GAME['GameTickerNames'] .= $ResultArray[3];
                } else {
                    $errorlist .= $ResultArray[0];
                }
            } else {
                if ($GAME['ContinueSellingMode']) {
                    if ($formdetails['IndustrySpace'] == 50) {
                        if ($SystemActing) {
                            $AdminTakingMove = 0;
                        } else {
                            if ($GAME['PlayerUserID'][$GAME['PlayerToMove']] == $_SESSION['MyUserID']) {
                                $AdminTakingMove = 0;
                            } else {
                                $AdminTakingMove = 1;
                            }
                        }
                        if ($AdminTakingMove) {
                            $ResultArray = array('', '', '2E' . callmovetimediff() . letter_end_number($_SESSION['MyUserID']) . letter_end_number($_SESSION['MyGenderCode']), '|' . $_SESSION['MyUserName']);
                        } else {
                            $ResultArray = array('', '', 'J' . callmovetimediff(), '');
                        }
                        $GAME['ContinueSellingMode'] = 0;
                    } else {
                        require_once HIDDEN_FILES_PATH . 'cottonresource.php';
                        $ResultArray = sellcotton($formdetails['IndustrySpace'], $formdetails['PortSpace'], 1, 50);
                    }
                    if ($ResultArray[0] == '') {
                        $GAME['AltGameTicker'] .= $ResultArray[2];
                        $GAME['GameTickerNames'] .= $ResultArray[3];
                    } else {
                        $errorlist .= $ResultArray[0];
                    }
                } else {
                    if ($formdetails['CardA'] == 9) {
                        $errorlist .= 'No card selected.<br>';
                    } else {
                        $CardDetailsA = $GAME['carddetailarrayb'][$GAME['Cards'][$GAME['PlayerToMove']][$formdetails['CardA']]];
                        if ($formdetails['CardB'] == 9) {
                            $CardDetailsB = 50;
                            $passcb = '';
                        } else {
                            $CardDetailsB = $GAME['carddetailarrayb'][$GAME['Cards'][$GAME['PlayerToMove']][$formdetails['CardB']]];
                            if ($GAME['Round'] == 1 and !$GAME['RailPhase'] or $GAME['HandSize'][$GAME['PlayerToMove']] % 2) {
                                $passcb = '';
                            } else {
                                $passcb = letter_end_number($CardDetailsB);
                            }
                        }
                        switch ($formdetails['MoveType']) {
                            case 0:
                            case 1:
                                if ($formdetails['MoveType'] and $formdetails['CardB'] == 9) {
                                    $ResultArray = array(transtext('memNo2ndCard') . '<br>', '', '');
                                } else {
                                    if ($formdetails['MoveType'] and $formdetails['CardB'] == $formdetails['CardA']) {
                                        $ResultArray = array(transtext('memDuplicCard') . '<br>', '', '');
                                        // "You have selected the same card twice. Please select two different cards."
                                    } else {
                                        if ($formdetails['IndustrySpace'] == 50 or $formdetails['TileType'] == 9) {
                                            $ResultArray = array(transtext('memBadMoveData') . '<br>', '', '');
                                        } else {
                                            require_once HIDDEN_FILES_PATH . 'coalresource.php';
                                            require_once HIDDEN_FILES_PATH . 'tileresource.php';
                                            $AssuredCoalSource = ClosestCoal($formdetails['IndustrySpace'], 50, $formdetails['CoalSource']);
                                            $AssuredIronSource = GetIron($formdetails['IronSource']);
                                            $ResultArray = buildtile($formdetails['IndustrySpace'], $formdetails['TileType'], $AssuredCoalSource, $AssuredIronSource, $formdetails['CardA'], $formdetails['MoveType'], $CardDetailsA, $CardDetailsB);
                                        }
                                    }
                                }
                                $TwoCards = $formdetails['MoveType'];
                                break;
                            case 2:
                                require_once HIDDEN_FILES_PATH . 'linkresource.php';
                                if ($formdetails['LinkToBuild'] == 50) {
                                    $ResultArray = array(transtext('memBadMoveData') . '<br>', '', '');
                                } else {
                                    if ($GAME['RailPhase']) {
                                        require_once HIDDEN_FILES_PATH . 'coalresource.php';
                                        $AssuredCoalSource = ClosestCoal($GAME['RailStarts'][$formdetails['LinkToBuild']], $GAME['RailEnds'][$formdetails['LinkToBuild']], $formdetails['CoalSource']);
                                        $ResultArray = buildlink($formdetails['LinkToBuild'], $AssuredCoalSource, 1, $CardDetailsA);
                                    } else {
                                        $ResultArray = buildlink($formdetails['LinkToBuild'], 50, 1, $CardDetailsA);
                                    }
                                }
                                $TwoCards = 0;
                                break;
                            case 3:
                                if ($formdetails['TileType'] == 9) {
                                    $ResultArray = array(transtext('memBadMoveData') . '<br>', '', '');
                                } else {
                                    require_once HIDDEN_FILES_PATH . 'developresource.php';
                                    $AssuredIronSource = GetIron($formdetails['IronSource']);
                                    $ResultArray = develop($formdetails['TileType'], $AssuredIronSource, 0, $CardDetailsA);
                                }
                                $TwoCards = 0;
                                break;
                            case 4:
                                $ResultArray = array('', '', '');
                                if ($formdetails['LoanAmount'] > 3 or $GAME['IncomeSpace'][$GAME['PlayerToMove']] - $formdetails['LoanAmount'] < 0) {
                                    $ResultArray[0] .= transtext('memLoanTooBig') . '<br>';
                                }
                                if ($GAME['RailPhase'] and $GAME['NumRounds'] - $GAME['Round'] < 4) {
                                    $ResultArray[0] .= transtext('memLoanTooLate') . '<br>';
                                }
                                if ($ResultArray[0] == '') {
                                    $amount = 10 * $formdetails['LoanAmount'];
                                    $GAME['Money'][$GAME['PlayerToMove']] += $amount;
                                    $reducearray = array(0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 12, 12, 14, 14, 16, 16, 18, 18, 20, 20, 22, 22, 24, 24, 26, 26, 28, 28, 30, 30, 30, 33, 33, 33, 36, 36, 36, 39, 39, 39, 42, 42, 42, 45, 45, 45, 48, 48, 48, 51, 51, 51, 54, 54, 54, 57, 57, 57, 60, 60, 60, 60, 64, 64, 64, 64, 68, 68, 68, 68, 72, 72, 72, 72, 76, 76, 76, 76, 80, 80, 80, 80, 84, 84, 84, 84, 88, 88, 88, 88, 92, 92, 92, 92, 96, 96, 96);
                                    for ($i = 0; $i < $formdetails['LoanAmount']; $i++) {
                                        $GAME['IncomeSpace'][$GAME['PlayerToMove']] = $reducearray[$GAME['IncomeSpace'][$GAME['PlayerToMove']]];
                                    }
                                    if ($SystemActing) {
                                        $AdminTakingMove = 0;
                                    } else {
                                        if ($GAME['PlayerUserID'][$GAME['PlayerToMove']] == $_SESSION['MyUserID']) {
                                            $AdminTakingMove = 0;
                                        } else {
                                            $AdminTakingMove = 1;
                                        }
                                    }
                                    if ($AdminTakingMove) {
                                        $ResultArray[2] = '2A' . callmovetimediff() . letter_end_number($_SESSION['MyUserID']) . letter_end_number($_SESSION['MyGenderCode']) . letter_end_number($CardDetailsA) . letter_end_number($formdetails['LoanAmount']);
                                        $ResultArray[3] = '|' . $_SESSION['MyUserName'];
                                    } else {
                                        $ResultArray[2] = 'F' . callmovetimediff() . letter_end_number($CardDetailsA) . letter_end_number($formdetails['LoanAmount']);
                                        $ResultArray[3] = '';
                                    }
                                }
                                $TwoCards = 0;
                                break;
                            case 5:
                                if ($formdetails['IndustrySpace'] == 50) {
                                    $ResultArray = array(transtext('memBadMoveData') . '<br>', '', '');
                                } else {
                                    require_once HIDDEN_FILES_PATH . 'cottonresource.php';
                                    $ResultArray = sellcotton($formdetails['IndustrySpace'], $formdetails['PortSpace'], 0, $CardDetailsA);
                                }
                                $TwoCards = 0;
                                break;
                            case 6:
                                $ResultArray[0] = '';
                                if ($GAME['HandSize'][$GAME['PlayerToMove']] % 2) {
                                    $TwoCards = 0;
                                } else {
                                    if (!$GAME['RailPhase'] and $GAME['Round'] == 1) {
                                        $TwoCards = 0;
                                    } else {
                                        $TwoCards = 1;
                                        if ($CardDetailsB == 50) {
                                            $ResultArray[0] = transtext('memNo2ndCard') . '<br>';
                                            // No second card selected.
                                        }
                                        if ($formdetails[CardB] == $formdetails[CardA]) {
                                            $ResultArray[0] = transtext('memDuplicCard') . '<br>';
                                            // "You have selected the same card twice. Please select two different cards."
                                        }
                                    }
                                }
                                if ($SystemActing) {
                                    $AdminTakingMove = 0;
                                } else {
                                    if ($GAME['PlayerUserID'][$GAME['PlayerToMove']] == $_SESSION['MyUserID']) {
                                        $AdminTakingMove = 0;
                                    } else {
                                        $AdminTakingMove = 1;
                                    }
                                }
                                if ($AdminTakingMove) {
                                    $ResultArray[2] = '2C' . callmovetimediff() . letter_end_number($_SESSION['MyUserID']) . letter_end_number($_SESSION['MyGenderCode']) . letter_end_number($CardDetailsA) . $passcb;
                                    $ResultArray[3] = '|' . $_SESSION['MyUserName'];
                                } else {
                                    $ResultArray[2] = 'H' . callmovetimediff() . letter_end_number($CardDetailsA) . $passcb;
                                    $ResultArray[3] = '';
                                }
                        }
                        if ($ResultArray[0] == '') {
                            $GAME['AltGameTicker'] .= $ResultArray[2];
                            $GAME['GameTickerNames'] .= $ResultArray[3];
                            if ($TwoCards) {
                                if ($formdetails['CardA'] < $formdetails['CardB']) {
                                    $formdetails['CardB']--;
                                }
                            }
                            $y = $GAME['Cards'][$GAME['PlayerToMove']][$formdetails['CardA']];
                            for ($i = $formdetails['CardA']; $i < $GAME['HandSize'][$GAME['PlayerToMove']] - 1; $i++) {
                                $GAME['Cards'][$GAME['PlayerToMove']][$i] = $GAME['Cards'][$GAME['PlayerToMove']][$i + 1];
                            }
                            $GAME['Cards'][$GAME['PlayerToMove']][$GAME['HandSize'][$GAME['PlayerToMove']] - 1] = $y;
                            $GAME['DiscardPile'][] = array_pop($GAME['Cards'][$GAME['PlayerToMove']]);
                            $GAME['HandSize'][$GAME['PlayerToMove']]--;
                            if ($TwoCards) {
                                $y = $GAME['Cards'][$GAME['PlayerToMove']][$formdetails['CardB']];
                                for ($i = $formdetails['CardB']; $i < $GAME['HandSize'][$GAME['PlayerToMove']] - 1; $i++) {
                                    $GAME['Cards'][$GAME['PlayerToMove']][$i] = $GAME['Cards'][$GAME['PlayerToMove']][$i + 1];
                                }
                                $GAME['Cards'][$GAME['PlayerToMove']][$GAME['HandSize'][$GAME['PlayerToMove']] - 1] = $y;
                                $GAME['DiscardPile'][] = array_pop($GAME['Cards'][$GAME['PlayerToMove']]);
                                $GAME['HandSize'][$GAME['PlayerToMove']]--;
                            }
                        } else {
                            $errorlist .= $ResultArray[0];
                        }
                    }
                }
            }
        }
    }
    if ($errorlist == '') {
        $GAME['MoveMade'] = 1;
        if (!$SystemActing) {
            if ($GAME['PlayerUserID'][$GAME['PlayerToMove']] == $_SESSION['MyUserID']) {
                $GAME['MoveMadeByPlayer'][$GAME['PlayerToMove']] = 1;
            }
        } else {
            $GAME['MoveMadeByPlayer'][$GAME['PlayerToMove']] = 1;
        }
    }
    if ($MoveOn and !$GAME['DebtMode'] and !$GAME['SecondRailMode'] and !$GAME['SecondDevelopMode'] and !$GAME['ContinueSellingMode'] and $errorlist == '') {
        if ($GAME['RailPhase'] and $GAME['HandSize'][$GAME['PlayerToMove']] == 1) {
            require_once HIDDEN_FILES_PATH . 'nomovesresource.php';
            if (CheckNoMoves($GAME['Cards'][$GAME['PlayerToMove']][0])) {
                $GAME['AltGameTicker'] .= '9H' . letter_end_number($GAME['carddetailarrayb'][$GAME['Cards'][$GAME['PlayerToMove']][0]]);
                $GAME['DiscardPile'][] = array_pop($GAME['Cards'][$GAME['PlayerToMove']]);
                $GAME['HandSize'][$GAME['PlayerToMove']] = 0;
            }
        }
        $EvenTest = $GAME['HandSize'][$GAME['PlayerToMove']] % 2;
        if (!$EvenTest or !$GAME['RailPhase'] and $GAME['Round'] == 1) {
            if ($GAME['NumRounds'] - $GAME['Round'] > 3) {
                if ($GAME['RailPhase'] or $GAME['Round'] != 1) {
                    $GAME['Cards'][$GAME['PlayerToMove']][6] = array_pop($GAME['ShuffledDeck']);
                    $GAME['HandSize'][$GAME['PlayerToMove']]++;
                }
                $GAME['Cards'][$GAME['PlayerToMove']][7] = array_pop($GAME['ShuffledDeck']);
                $GAME['HandSize'][$GAME['PlayerToMove']]++;
                if ($GAME['AutoSort'][$GAME['PlayerToMove']]) {
                    sort($GAME['Cards'][$GAME['PlayerToMove']]);
                }
            }
            for ($i = 0; $i < MAX_PLAYERS; $i++) {
                if ($GAME['TurnOrder'][$i] == $GAME['PlayerToMove']) {
                    $WhereInTurnOrder = $i;
                }
            }
            $EndRound = true;
            for ($i = MAX_PLAYERS - 1; $i > $WhereInTurnOrder; $i--) {
                if ($GAME['PlayerExists'][$GAME['TurnOrder'][$i]]) {
                    $GAME['PlayerToMove'] = $GAME['TurnOrder'][$i];
                    $EndRound = false;
                }
            }
            if ($EndRound) {
                if ($GAME['Round'] == $GAME['NumRounds']) {
                    if ($GAME['RailPhase']) {
                        require_once HIDDEN_FILES_PATH . 'scoringresource.php';
                        endgamescoring();
                    } else {
                        require_once HIDDEN_FILES_PATH . 'scoringresource.php';
                        require_once HIDDEN_FILES_PATH . 'turnorderresource.php';
                        canalphasescoring();
                        DoTurnOrder(1);
                    }
                } else {
                    require_once HIDDEN_FILES_PATH . 'turnorderresource.php';
                    DoTurnOrder(1);
                }
            }
            if ($GAME['RailPhase'] and $GAME['Round'] == $GAME['NumRounds'] and $GAME['GameStatus'] != 'Finished') {
                require_once HIDDEN_FILES_PATH . 'nomovesresource.php';
                CheckNoMovesShell();
            }
        }
    }
    return $errorlist;
}