Esempio n. 1
0
function develop($tiletype, $ironsource, $continuing, $thecard)
{
    global $GAME, $SystemActing;
    $errorlist = '';
    if (!$GAME['RemainingTiles'][$tiletype][$GAME['PlayerToMove']]) {
        $errorlist = transtext('memOutOfTiles') . '<br>';
        // "You have run out of industry tiles of the chosen type."
    }
    if ($ironsource == 50 and $GAME['Money'][$GAME['PlayerToMove']] < $GAME['cubeprice'][$GAME['IronDemand']]) {
        $errorlist = transtext('memDevPoor') . '<br>';
        // "You cannot develop, as you cannot afford the iron cube."
    }
    switch ($ironsource) {
        case 90:
            $errorlist .= transtext('memIronNotValid') . '<br>';
            break;
            // "The selected source of iron is not valid."
        // "The selected source of iron is not valid."
        case 91:
            $errorlist .= transtext('memIronOnBoard') . '<br>';
            break;
            // "You cannot buy iron from the Demand Track,
            // as there is iron available on the board for you to use."
    }
    if ($ironsource == 50) {
        $altironsource = 99;
    } else {
        $altironsource = $ironsource;
    }
    if ($errorlist == '') {
        $GAME['RemainingTiles'][$tiletype][$GAME['PlayerToMove']]--;
        if ($ironsource == 50) {
            $GAME['Money'][$GAME['PlayerToMove']] -= $GAME['cubeprice'][$GAME['IronDemand']];
            $GAME['AmountSpent'][$GAME['PlayerToMove']] += $GAME['cubeprice'][$GAME['IronDemand']];
            if ($GAME['CurrentPlayers'] == 2 and $GAME['IronDemand'] < 6 or $GAME['CurrentPlayers'] > 2 and $GAME['IronDemand'] < 8) {
                $GAME['IronDemand']++;
            }
        } else {
            $GAME['IronInLancs']--;
            $GAME['SpaceCubes'][$ironsource] = $GAME['SpaceCubes'][$ironsource] - 1;
            // This is written in this way because SpaceCubes is a string consisting of digits
            // (it is not legal to use increment/decrement operators on string offsets).
            if (!$GAME['SpaceCubes'][$ironsource]) {
                fliptile($ironsource);
            }
        }
        if ($SystemActing) {
            $AdminTakingMove = 0;
        } else {
            if ($GAME['PlayerUserID'][$GAME['PlayerToMove']] == $_SESSION['MyUserID']) {
                $AdminTakingMove = 0;
            } else {
                $AdminTakingMove = 1;
            }
        }
        if ($continuing) {
            if ($AdminTakingMove) {
                $altgoodoutput = '2D' . callmovetimediff() . letter_end_number($_SESSION['MyUserID']) . letter_end_number($_SESSION['MyGenderCode']) . letter_end_number($tiletype) . letter_end_number($altironsource);
                $altgoodoutputName = '|' . $_SESSION['MyUserName'];
            } else {
                $altgoodoutput = 'I' . callmovetimediff() . letter_end_number($tiletype) . letter_end_number($altironsource);
                $altgoodoutputName = '';
            }
            $GAME['SecondDevelopMode'] = 0;
        } else {
            if ($AdminTakingMove) {
                $altgoodoutput = '1J' . callmovetimediff() . letter_end_number($_SESSION['MyUserID']) . letter_end_number($_SESSION['MyGenderCode']) . letter_end_number($thecard) . letter_end_number($tiletype) . letter_end_number($altironsource);
                $altgoodoutputName = '|' . $_SESSION['MyUserName'];
            } else {
                $altgoodoutput = 'E' . callmovetimediff() . letter_end_number($thecard) . letter_end_number($tiletype) . letter_end_number($altironsource);
                $altgoodoutputName = '';
            }
            if ($GAME['RemainingTiles'][0][$GAME['PlayerToMove']] or $GAME['RemainingTiles'][1][$GAME['PlayerToMove']] or $GAME['RemainingTiles'][2][$GAME['PlayerToMove']] or $GAME['RemainingTiles'][3][$GAME['PlayerToMove']] or $GAME['RemainingTiles'][4][$GAME['PlayerToMove']]) {
                $CanGetIronFree = false;
                for ($i = 0; $i < $GAME['NumIndustrySpaces']; $i++) {
                    if ($GAME['SpaceStatus'] != 9 and $GAME['SpaceTile'][$i] == 2 and $GAME['SpaceCubes'][$i]) {
                        $CanGetIronFree = true;
                    }
                }
                if (!$CanGetIronFree and $GAME['Money'][$GAME['PlayerToMove']] < $GAME['cubeprice'][$GAME['IronDemand']]) {
                    $altgoodoutput .= '9IA';
                } else {
                    $GAME['SecondDevelopMode'] = 1;
                }
            } else {
                $altgoodoutput .= '9IB';
            }
        }
    } else {
        $altgoodoutput = '';
        $altgoodoutputName = '';
    }
    return array($errorlist, '', $altgoodoutput, $altgoodoutputName);
}
Esempio n. 2
0
function buildtile($wheretobuild, $whattobuild, $coalsource, $ironsource, $card, $doublebuild, $thecardA, $thecardB)
{
    global $GAME, $SystemActing;
    $errorlist = '';
    $TheTechLevel = $GAME['TechLevelArray'][$whattobuild][$GAME['RemainingTiles'][$whattobuild][$GAME['PlayerToMove']]];
    $carddetail = $GAME['carddetailarray'][$GAME['Cards'][$GAME['PlayerToMove']][$card]];
    if ($coalsource == 50) {
        $altcoalsource = 99;
    } else {
        $altcoalsource = $coalsource;
    }
    if ($ironsource == 50) {
        $altironsource = 99;
    } else {
        $altironsource = $ironsource;
    }
    if ($TheTechLevel == 9) {
        $errorlist = transtext('memOutOfTiles') . '<br>';
        // "You have run out of industry tiles of the chosen type."
    } else {
        if ($GAME['HasBuilt'][$GAME['PlayerToMove']] and !$doublebuild and $GAME['Cards'][$GAME['PlayerToMove']][$card] > $GAME['TopLocationCard'] and !$GAME['HasBuiltInTown'][$GAME['PlayerToMove']][$GAME['spacetowns'][$wheretobuild]] and !$GAME['HasLinkedToTown'][$GAME['PlayerToMove']][$GAME['spacetowns'][$wheretobuild]]) {
            $CannotBuildHere = true;
            for ($i = 0; $i < count($GAME['GeneralisedVCs']); $i++) {
                if ($GAME['spacetowns'][$wheretobuild] == $GAME['GeneralisedVCs'][$i][0] and ($GAME['HasBuiltInTown'][$GAME['PlayerToMove']][$GAME['GeneralisedVCs'][$i][1]] or $GAME['HasLinkedToTown'][$GAME['PlayerToMove']][$GAME['GeneralisedVCs'][$i][1]]) or ($GAME['SpecialRules'] & 1 and $GAME['GeneralisedVCs'][$i][2] or $GAME['GeneralisedVCs'][$i][2] == 2) and $GAME['spacetowns'][$wheretobuild] == $GAME['GeneralisedVCs'][$i][1] and ($GAME['HasBuiltInTown'][$GAME['PlayerToMove']][$GAME['GeneralisedVCs'][$i][0]] or $GAME['HasLinkedToTown'][$GAME['PlayerToMove']][$GAME['GeneralisedVCs'][$i][0]])) {
                    $CannotBuildHere = false;
                }
            }
            if ($CannotBuildHere) {
                if ($GAME['RailPhase']) {
                    $errorlist .= transtext('memIndyCardBadR') . '<br>';
                    // "You cannot use an industry card to build in that location,
                    // as you have neither connected to the location nor built a tile there."
                } else {
                    $errorlist .= transtext('memIndyCardBadC') . '<br>';
                    // "You cannot use an industry card to build in that location,
                    // as you have not connected to the location."
                }
            }
        }
        if (!$GAME['SpaceAlwaysExists'][$wheretobuild] and ($GAME['ModularBoardParts'] & $GAME['SpaceExistenceArray'][$wheretobuild]) != $GAME['SpaceExistenceArray'][$wheretobuild]) {
            $errorlist .= transtext('memSpaceNotThere') . '<br>';
            // "That industry space does not exist (or it no longer exists) in this game."
        }
        if ($GAME['tileindustries'][$wheretobuild] != $whattobuild and ($whattobuild > 1 or $GAME['tileindustries'][$wheretobuild] != 5) and ($whattobuild and $whattobuild != 3 or $GAME['tileindustries'][$wheretobuild] != 6) and ($whattobuild != 2 and $whattobuild != 3 or $GAME['tileindustries'][$wheretobuild] != 7)) {
            $errorlist .= transtext('memWrongTileType') . '<br>';
            // "The tile that you attempted to build cannot be built in the chosen industry space."
        }
        if (!$GAME['RailPhase'] and $GAME['HasBuiltInTown'][$GAME['PlayerToMove']][$GAME['spacetowns'][$wheretobuild]] and $GAME['SpaceStatus'][$wheretobuild] != $GAME['PlayerToMove']) {
            $errorlist .= transtext('memAlreadyInTown') . '<br>';
            // "You have already built an industry tile in that location."
        }
        $StrategicBlockAttempt = false;
        for ($i = 0; $i < count($GAME['GeneralisedNoStratBlock']); $i++) {
            if ($whattobuild == $GAME['GeneralisedNoStratBlock'][$i][0] and $GAME['SpaceStatus'][$GAME['GeneralisedNoStratBlock'][$i][1]] == 9 and $wheretobuild == $GAME['GeneralisedNoStratBlock'][$i][2]) {
                $StrategicBlockAttempt = true;
            }
        }
        if ($StrategicBlockAttempt) {
            $errorlist .= transtext('memTacticalBlock') . '<br>';
        }
        if ($GAME['SpaceStatus'][$wheretobuild] != 9 and $GAME['SpaceTile'][$wheretobuild] != $whattobuild) {
            $errorlist .= transtext('memOvrSameType') . '<br>';
        }
        if ($GAME['SpaceStatus'][$wheretobuild] != 9 and $GAME['TechLevels'][$wheretobuild] >= $TheTechLevel) {
            $errorlist .= transtext('memOvrTechLevel') . '<br>';
        }
        if ($GAME['SpaceStatus'][$wheretobuild] == 8 and !$GAME['SpaceTile'][$wheretobuild]) {
            $errorlist .= transtext('memOvrCM') . '<br>';
            // "You can never build over an opponent's Cotton Mill."
            // (Prevents building over an orphan Cotton Mill.)
        }
        if ($GAME['SpaceStatus'][$wheretobuild] != 9 and $GAME['SpaceStatus'][$wheretobuild] != 8 and $GAME['SpaceStatus'][$wheretobuild] != $GAME['PlayerToMove']) {
            switch ($GAME['SpaceTile'][$wheretobuild]) {
                case 0:
                    $errorlist .= transtext('memOvrCM') . '<br>';
                    // "You can never build over an opponent's Cotton Mill."
                    break;
                case 1:
                    if ($GAME['CurrentPlayers'] > 2 and $GAME['CoalDemand'] < 8 or $GAME['CurrentPlayers'] == 2 and $GAME['CoalDemand'] < 6 or $GAME['CoalInLancs']) {
                        $errorlist .= transtext('memOvrCoalCubes') . '<br>';
                        // "You cannot currently build over an opponent's Coal Mine:
                        // the cube scarcity condition is not satisfied."
                    }
                    if ($GAME['SpecialRules'] & 4) {
                        for ($i = 0; $i < $GAME['NumIndustrySpaces']; $i++) {
                            if ($GAME['spacetowns'][$i] == $GAME['spacetowns'][$wheretobuild] and ($GAME['tileindustries'][$i] == 1 or $GAME['tileindustries'][$i] == 5) and $GAME['SpaceStatus'][$i] == 9) {
                                $errorlist .= transtext('memOvrCoalMCOR') . '<br>';
                                // There is a free space in the same location for a Coal Mine.
                                // You cannot build over your opponent's Coal Mine here.
                                break;
                            }
                        }
                    }
                    break;
                case 2:
                    if ($GAME['CurrentPlayers'] > 2 and $GAME['IronDemand'] < 8 or $GAME['CurrentPlayers'] == 2 and $GAME['IronDemand'] < 6 or $GAME['IronInLancs']) {
                        $errorlist .= transtext('memOvrIronCubes') . '<br>';
                        // "You cannot currently build over an opponent's Iron Works:
                        // the cube scarcity condition is not satisfied."
                    }
                    break;
                case 3:
                    $errorlist .= transtext('memOvrPort') . '<br>';
                    // "You can never build over an opponent's Port."
                    break;
                default:
                    $errorlist .= transtext('memOvrShipyard') . '<br>';
                    // "You can never build over an opponent's Shipyard."
            }
        }
        if (!$doublebuild and $GAME['Cards'][$GAME['PlayerToMove']][$card] <= $GAME['TopLocationCard'] and $carddetail != $GAME['spacetowns'][$wheretobuild]) {
            $errorlist .= transtext('memLocnCardBad') . '<br>';
            // "The space where you attempted to build is not in
            // the location named on the card that you tried to use."
        }
        if ($doublebuild and !$GAME['RailPhase'] and $GAME['Round'] == 1) {
            $errorlist .= transtext('memFirstTurnDbl') . '<br>';
            // "You cannot use two cards to build on the first turn of the game."
        }
        if ($doublebuild and $GAME['HandSize'][$GAME['PlayerToMove']] % 2 == 1) {
            $errorlist .= transtext('mem2ndActionDbl') . '<br>';
            // "You cannot use two cards to build for your second action of the turn."
        }
        if (!$doublebuild and $GAME['Cards'][$GAME['PlayerToMove']][$card] > $GAME['TopLocationCard'] and $carddetail != $whattobuild) {
            $errorlist .= transtext('memIndyCardType') . '<br>';
            // "The tile that you attempted to build does not match
            // the industry type of the card that you tried to use."
        }
        if (!$GAME['RailPhase'] and $whattobuild == 4 and $TheTechLevel == 2) {
            $errorlist .= transtext('memTech2Shipyard') . '<br>';
            // "You cannot build a Tech Level 2 Shipyard during the Canal Phase."
        }
        if ($whattobuild == 4 and $TheTechLevel == 0) {
            $errorlist .= transtext('memTech0Shipyard') . '<br>';
            // "You cannot build a Tech Level 0 Shipyard at any time.
            // These tiles must be developed away before you can build Shipyards."
        }
        if ($GAME['RailPhase'] and $TheTechLevel == 1) {
            $errorlist .= transtext('memTech1Rails') . '<br>';
            // You cannot build a Tech Level 1 industry tile during the Rail Phase.
        }
        if ($GAME['Money'][$GAME['PlayerToMove']] < $GAME['TileCosts'][$whattobuild][$TheTechLevel - 1]) {
            $errorlist .= 'You cannot afford to build that industry tile.<br>';
        } else {
            if ($GAME['TileRequireCoal'][$whattobuild][$TheTechLevel - 1] and $coalsource == 50 and $GAME['Money'][$GAME['PlayerToMove']] < $GAME['TileCosts'][$whattobuild][$TheTechLevel - 1] + $GAME['cubeprice'][$GAME['CoalDemand']] or $GAME['TileRequireIron'][$whattobuild][$TheTechLevel - 1] and $ironsource == 50 and $GAME['Money'][$GAME['PlayerToMove']] < $GAME['TileCosts'][$whattobuild][$TheTechLevel - 1] + $GAME['cubeprice'][$GAME['IronDemand']] or $GAME['TileRequireCoal'][$whattobuild][$TheTechLevel - 1] and $GAME['TileRequireIron'][$whattobuild][$TheTechLevel - 1] and $coalsource == 50 and $ironsource == 50 and $GAME['Money'][$GAME['PlayerToMove']] < $GAME['TileCosts'][$whattobuild][$TheTechLevel - 1] + $GAME['cubeprice'][$GAME['CoalDemand']] + $GAME['cubeprice'][$GAME['IronDemand']]) {
                $errorlist .= transtext('memTilePoorCubes') . '<br>';
                // Although you can afford to build the chosen industry tile,
                // you cannot afford to buy from the Demand Track(s) the cube(s) needed to build it.
            }
        }
        if ($GAME['TileRequireCoal'][$whattobuild][$TheTechLevel - 1]) {
            switch ($coalsource) {
                case 90:
                    $errorlist .= transtext('memCoalNotValid') . '<br>';
                    break;
                    // "The selected source of coal is not valid."
                // "The selected source of coal is not valid."
                case 91:
                    $errorlist .= transtext('memCoalOnBoard') . '<br>';
                    break;
                    // "You cannot buy coal from the Demand Track,
                    // as there is coal available on the board for you to use."
                // "You cannot buy coal from the Demand Track,
                // as there is coal available on the board for you to use."
                case 92:
                    $errorlist .= transtext('memCoalNearer') . '<br>';
                    break;
                case 93:
                    $errorlist .= 'The selected source of coal is not connected to the location where you are trying to build.<br>';
                    break;
                case 95:
                    $errorlist .= transtext('memCoalNoPorts') . '<br>';
                    break;
                    // "You cannot buy coal from the Demand Track,
                    // as the location where you want to build is not connected to a Port."
            }
        }
        if ($GAME['TileRequireIron'][$whattobuild][$TheTechLevel - 1]) {
            switch ($ironsource) {
                case 90:
                    $errorlist .= transtext('memIronNotValid') . '<br>';
                    break;
                    // "The selected source of iron is not valid."
                // "The selected source of iron is not valid."
                case 91:
                    $errorlist .= transtext('memIronOnBoard') . '<br>';
                    break;
                    // "You cannot buy iron from the Demand Track,
                    // as there is iron available on the board for you to use."
            }
        }
    }
    if ($errorlist == '') {
        if ($GAME['SpaceStatus'][$wheretobuild] != 9) {
            destroytile($wheretobuild, 0, 1);
        }
        $GAME['HasBuilt'][$GAME['PlayerToMove']] = 1;
        $GAME['HasBuiltInTown'][$GAME['PlayerToMove']][$GAME['spacetowns'][$wheretobuild]] = 1;
        $GAME['SpaceStatus'][$wheretobuild] = $GAME['PlayerToMove'];
        $GAME['SpaceTile'][$wheretobuild] = $whattobuild;
        $GAME['TechLevels'][$wheretobuild] = $TheTechLevel;
        $GAME['Money'][$GAME['PlayerToMove']] -= $GAME['TileCosts'][$whattobuild][$TheTechLevel - 1];
        $GAME['AmountSpent'][$GAME['PlayerToMove']] += $GAME['TileCosts'][$whattobuild][$TheTechLevel - 1];
        $GAME['RemainingTiles'][$whattobuild][$GAME['PlayerToMove']]--;
        if ($GAME['TileRequireCoal'][$whattobuild][$TheTechLevel - 1]) {
            if ($coalsource == 50) {
                $GAME['Money'][$GAME['PlayerToMove']] -= $GAME['cubeprice'][$GAME['CoalDemand']];
                $GAME['AmountSpent'][$GAME['PlayerToMove']] += $GAME['cubeprice'][$GAME['CoalDemand']];
                if ($GAME['CurrentPlayers'] == 2 and $GAME['CoalDemand'] < 6 or $GAME['CurrentPlayers'] > 2 and $GAME['CoalDemand'] < 8) {
                    $GAME['CoalDemand']++;
                }
            } else {
                $GAME['CoalInLancs']--;
                $GAME['SpaceCubes'][$coalsource] = $GAME['SpaceCubes'][$coalsource] - 1;
                // This is written in this way because SpaceCubes is a string consisting of digits
                // (it is not legal to use increment/decrement operators on string offsets).
                if (!$GAME['SpaceCubes'][$coalsource]) {
                    fliptile($coalsource);
                }
            }
        } else {
            $altcoalsource = 98;
        }
        if ($GAME['TileRequireIron'][$whattobuild][$TheTechLevel - 1]) {
            if ($ironsource == 50) {
                $GAME['Money'][$GAME['PlayerToMove']] -= $GAME['cubeprice'][$GAME['IronDemand']];
                $GAME['AmountSpent'][$GAME['PlayerToMove']] += $GAME['cubeprice'][$GAME['IronDemand']];
                if ($GAME['CurrentPlayers'] == 2 and $GAME['IronDemand'] < 6 or $GAME['CurrentPlayers'] > 2 and $GAME['IronDemand'] < 8) {
                    $GAME['IronDemand']++;
                }
            } else {
                $GAME['IronInLancs']--;
                $GAME['SpaceCubes'][$ironsource] = $GAME['SpaceCubes'][$ironsource] - 1;
                // This is written in this way because SpaceCubes is a string consisting of digits
                // (it is not legal to use increment/decrement operators on string offsets).
                if (!$GAME['SpaceCubes'][$ironsource]) {
                    fliptile($ironsource);
                }
            }
        } else {
            $altironsource = 98;
        }
        switch ($whattobuild) {
            case 0:
                $GAME['SpaceCubes'][$wheretobuild] = 1;
                break;
            case 1:
                $GAME['SpaceCubes'][$wheretobuild] = $GAME['TileInitialCubes'][0][$TheTechLevel - 1];
                $GAME['CoalInLancs'] += $GAME['SpaceCubes'][$wheretobuild];
                if ($GAME['HasPort'][$GAME['spacetowns'][$wheretobuild]]) {
                    if ($GAME['CoalDemand'] >= $GAME['SpaceCubes'][$wheretobuild]) {
                        $GAME['CoalInLancs'] -= $GAME['SpaceCubes'][$wheretobuild];
                        $CoalIncome = 0;
                        for ($i = 0; $i < $GAME['SpaceCubes'][$wheretobuild]; $i++) {
                            $GAME['CoalDemand']--;
                            $CoalIncome += $GAME['cubeprice'][$GAME['CoalDemand']];
                        }
                        $GAME['SpaceCubes'][$wheretobuild] = 0;
                        fliptile($wheretobuild);
                    } else {
                        $GAME['CoalInLancs'] -= $GAME['CoalDemand'];
                        $GAME['SpaceCubes'][$wheretobuild] = $GAME['TileInitialCubes'][0][$TheTechLevel - 1] - $GAME['CoalDemand'];
                        $oldcoaldemand = $GAME['CoalDemand'];
                        $CoalIncome = 0;
                        for ($i = 0; $i < $oldcoaldemand; $i++) {
                            $GAME['CoalDemand']--;
                            $CoalIncome += $GAME['cubeprice'][$GAME['CoalDemand']];
                        }
                    }
                    if ($CoalIncome) {
                        $GAME['Money'][$GAME['PlayerToMove']] += $CoalIncome;
                        $altcoalsource = 97;
                    }
                }
                break;
            case 2:
                $GAME['SpaceCubes'][$wheretobuild] = $GAME['TileInitialCubes'][1][$TheTechLevel - 1];
                $GAME['IronInLancs'] += $GAME['SpaceCubes'][$wheretobuild];
                if ($GAME['IronDemand'] >= $GAME['SpaceCubes'][$wheretobuild]) {
                    $GAME['IronInLancs'] -= $GAME['SpaceCubes'][$wheretobuild];
                    $IronIncome = 0;
                    for ($i = 0; $i < $GAME['SpaceCubes'][$wheretobuild]; $i++) {
                        $GAME['IronDemand']--;
                        $IronIncome += $GAME['cubeprice'][$GAME['IronDemand']];
                    }
                    $GAME['SpaceCubes'][$wheretobuild] = 0;
                    fliptile($wheretobuild);
                } else {
                    $GAME['IronInLancs'] -= $GAME['IronDemand'];
                    $GAME['SpaceCubes'][$wheretobuild] = $GAME['TileInitialCubes'][1][$TheTechLevel - 1] - $GAME['IronDemand'];
                    $oldirondemand = $GAME['IronDemand'];
                    $IronIncome = 0;
                    for ($i = 0; $i < $oldirondemand; $i++) {
                        $GAME['IronDemand']--;
                        $IronIncome += $GAME['cubeprice'][$GAME['IronDemand']];
                    }
                }
                if ($IronIncome) {
                    $GAME['Money'][$GAME['PlayerToMove']] += $IronIncome;
                    $altironsource = 97;
                }
                break;
            case 3:
                for ($i = 0; $i < $GAME['NumTowns']; $i++) {
                    if ($GAME['CoalNet'][$i] == $GAME['CoalNet'][$GAME['spacetowns'][$wheretobuild]]) {
                        $GAME['HasPort'][$i] = 1;
                    }
                }
                $GAME['SpaceCubes'][$wheretobuild] = 1;
                break;
            case 4:
                fliptile($wheretobuild);
        }
        if ($SystemActing) {
            $AdminTakingMove = 0;
        } else {
            if ($GAME['PlayerUserID'][$GAME['PlayerToMove']] == $_SESSION['MyUserID']) {
                $AdminTakingMove = 0;
            } else {
                $AdminTakingMove = 1;
            }
        }
        if ($doublebuild) {
            $dbcard = letter_end_number($thecardB);
            $actionnuma = '1H';
            $actionnumb = 'C';
        } else {
            $dbcard = '';
            $actionnuma = '1G';
            $actionnumb = 'B';
        }
        if ($AdminTakingMove) {
            $altgoodoutput = $actionnuma . callmovetimediff() . letter_end_number($_SESSION['MyUserID']) . letter_end_number($_SESSION['MyGenderCode']) . letter_end_number($thecardA) . $dbcard . letter_end_number($whattobuild) . letter_end_number($wheretobuild) . letter_end_number($altcoalsource) . letter_end_number($altironsource);
            $altgoodoutputName = '|' . $_SESSION['MyUserName'];
        } else {
            $altgoodoutput = $actionnumb . callmovetimediff() . letter_end_number($thecardA) . $dbcard . letter_end_number($whattobuild) . letter_end_number($wheretobuild) . letter_end_number($altcoalsource) . letter_end_number($altironsource);
            $altgoodoutputName = '';
        }
    } else {
        $altgoodoutput = '';
        $altgoodoutputName = '';
    }
    return array($errorlist, '', $altgoodoutput, $altgoodoutputName);
}
Esempio n. 3
0
function sellcotton($milllocation, $portlocation, $continuing, $thecard)
{
    global $GAME, $SystemActing;
    $errorlistA = '';
    $errorlistB = '';
    $ExclamationMark = 0;
    if ($GAME['SpaceTile'][$milllocation] or $GAME['SpaceStatus'][$milllocation] == 9) {
        $errorlistA .= transtext('memIsNotCM') . '<br>';
        // "The industry space that you specified as the location
        // of the Cotton Mill is not occupied by a Cotton Mill."
    } else {
        if ($GAME['SpaceStatus'][$milllocation] != $GAME['PlayerToMove']) {
            $errorlistA .= transtext('memCMNotYours') . '<br>';
        } else {
            if (!$GAME['SpaceCubes'][$milllocation]) {
                $errorlistA .= transtext('memCMFlipped') . '<br>';
                // "The Cotton Mill that you specified is already flipped."
            }
        }
    }
    if ($errorlistA == '') {
        if ($portlocation < $GAME['NumIndustrySpaces']) {
            if ($GAME['SpaceTile'][$portlocation] != 3) {
                $errorlistB .= transtext('memIsNotPort') . '<br>';
                // "The industry space that you specified as the location
                // of the Port is not occupied by a Port."
            } else {
                if ($GAME['CoalNet'][$GAME['spacetowns'][$milllocation]] != $GAME['CoalNet'][$GAME['spacetowns'][$portlocation]]) {
                    $errorlistB .= transtext('memPortNotConn') . '<br>';
                    // "The Port location that you specified is not connected to the Cotton Mill that you specified."
                } else {
                    if (!$GAME['SpaceCubes'][$portlocation]) {
                        $errorlistB .= transtext('memPortFlipped') . '<br>';
                        // "The Port in the location that you specified is already flipped."
                    }
                }
            }
        } else {
            if (!$GAME['HasPort'][$GAME['spacetowns'][$milllocation]]) {
                $errorlistB .= transtext('memCMNoPorts') . '<br>';
                // "The specified Cotton Mill cannot sell to the Distant Market, as it is not connected to any Ports."
            } else {
                if ($GAME['CottonDemand'] == 8) {
                    $errorlistB .= transtext('memNoMoreDemand') . '<br>';
                }
            }
        }
    }
    $errorlist = $errorlistA . $errorlistB;
    if ($errorlist == '') {
        if ($SystemActing) {
            $AdminTakingMove = 0;
        } else {
            if ($GAME['PlayerUserID'][$GAME['PlayerToMove']] == $_SESSION['MyUserID']) {
                $AdminTakingMove = 0;
            } else {
                $AdminTakingMove = 1;
            }
        }
        $append_action_end_note = true;
        if ($portlocation < $GAME['NumIndustrySpaces']) {
            fliptile($portlocation);
            fliptile($milllocation);
            if ($continuing) {
                if ($AdminTakingMove) {
                    $altgoodoutput = '2D' . callmovetimediff() . letter_end_number($_SESSION['MyUserID']) . letter_end_number($_SESSION['MyGenderCode']) . letter_end_number($milllocation) . letter_end_number($portlocation);
                    $altgoodoutputName = '|' . $_SESSION['MyUserName'];
                } else {
                    $altgoodoutput = 'I' . callmovetimediff() . letter_end_number($milllocation) . letter_end_number($portlocation);
                    $altgoodoutputName = '';
                }
            } else {
                if ($AdminTakingMove) {
                    $altgoodoutput = '2B' . callmovetimediff() . letter_end_number($_SESSION['MyUserID']) . letter_end_number($_SESSION['MyGenderCode']) . letter_end_number($thecard) . letter_end_number($milllocation) . letter_end_number($portlocation);
                    $altgoodoutputName = '|' . $_SESSION['MyUserName'];
                } else {
                    $altgoodoutput = 'G' . callmovetimediff() . letter_end_number($thecard) . letter_end_number($milllocation) . letter_end_number($portlocation);
                    $altgoodoutputName = '';
                }
            }
            $CheckCtu = true;
        } else {
            drawDMtile();
            if ($continuing) {
                if ($AdminTakingMove) {
                    $altgoodoutput = '2D' . callmovetimediff() . letter_end_number($_SESSION['MyUserID']) . letter_end_number($_SESSION['MyGenderCode']) . letter_end_number($milllocation) . '9J';
                    $altgoodoutputName = '|' . $_SESSION['MyUserName'];
                } else {
                    $altgoodoutput = 'I' . callmovetimediff() . letter_end_number($milllocation) . '9J';
                    $altgoodoutputName = '';
                }
            } else {
                if ($AdminTakingMove) {
                    $altgoodoutput = '2B' . callmovetimediff() . letter_end_number($_SESSION['MyUserID']) . letter_end_number($_SESSION['MyGenderCode']) . letter_end_number($thecard) . letter_end_number($milllocation) . '9J';
                    $altgoodoutputName = '|' . $_SESSION['MyUserName'];
                } else {
                    $altgoodoutput = 'G' . callmovetimediff() . letter_end_number($thecard) . letter_end_number($milllocation) . '9J';
                    $altgoodoutputName = '';
                }
            }
            if ($GAME['CottonDemand'] < 8) {
                $CheckCtu = true;
                $Boost = array(3, 3, 2, 2, 1, 1, 0, 0);
                $Boost = $Boost[$GAME['CottonDemand']];
                $GAME['IncomeSpace'][$GAME['PlayerToMove']] += $Boost;
                // If IncomeSpace[...] ends up above 99,
                // it's taken care of by the call to fliptile()
                fliptile($milllocation);
                if (!DMSaleSuccessProbability()) {
                    $GAME['CottonDemand'] = 8;
                    $altgoodoutput .= '9J';
                }
            } else {
                $CheckCtu = false;
                $append_action_end_note = false;
            }
        }
        $GAME['ContinueSellingMode'] = 0;
        if ($CheckCtu) {
            $MillsArray = array();
            $PortsArray = array();
            for ($i = 0; $i < $GAME['NumIndustrySpaces']; $i++) {
                if ($GAME['SpaceStatus'][$i] == $GAME['PlayerToMove'] and !$GAME['SpaceTile'][$i] and $GAME['SpaceCubes'][$i]) {
                    $MillsArray[] = $i;
                }
                if ($GAME['SpaceStatus'][$i] != 9 and $GAME['SpaceTile'][$i] == 3 and $GAME['SpaceCubes'][$i]) {
                    $PortsArray[] = $i;
                }
            }
            for ($i = 0; $i < count($MillsArray); $i++) {
                if ($GAME['HasPort'][$GAME['spacetowns'][$MillsArray[$i]]] and $GAME['CottonDemand'] < 8) {
                    $GAME['ContinueSellingMode'] = 1;
                    break;
                }
                for ($j = 0; $j < count($PortsArray); $j++) {
                    if ($GAME['CoalNet'][$GAME['spacetowns'][$MillsArray[$i]]] == $GAME['CoalNet'][$GAME['spacetowns'][$PortsArray[$j]]]) {
                        $GAME['ContinueSellingMode'] = 1;
                        break 2;
                    }
                }
            }
        }
        if (!$GAME['ContinueSellingMode'] and $append_action_end_note) {
            $altgoodoutput .= '9I';
        }
    } else {
        $altgoodoutput = '';
        $altgoodoutputName = '';
    }
    return array($errorlist, '', $altgoodoutput, $altgoodoutputName);
}
Esempio n. 4
0
function buildlink($linktobuild, $coalsource, $buildnum, $thecard)
{
    global $GAME, $SystemActing;
    $errorlist = '';
    if ($GAME['LinkStatus'][$linktobuild] != 9) {
        if ($GAME['RailPhase']) {
            $errorlist .= transtext('memRailBuilt') . '<br>';
        } else {
            $errorlist .= transtext('memCanalBuilt') . '<br>';
        }
        // "The chosen rail/canal link has already been built."
    }
    if ($GAME['RailPhase']) {
        if (!$GAME['RailAlwaysExists'][$linktobuild] and ($GAME['ModularBoardParts'] & $GAME['RailExistenceArray'][$linktobuild]) != $GAME['RailExistenceArray'][$linktobuild]) {
            $errorlist .= transtext('memRailNotThere') . '<br>';
            // "That rail link does not exist (or it no longer exists) in this game."
        }
        if (!$GAME['HasBuiltInTown'][$GAME['PlayerToMove']][$GAME['RailStarts'][$linktobuild]] and !$GAME['HasBuiltInTown'][$GAME['PlayerToMove']][$GAME['RailEnds'][$linktobuild]] and !$GAME['HasLinkedToTown'][$GAME['PlayerToMove']][$GAME['RailStarts'][$linktobuild]] and !$GAME['HasLinkedToTown'][$GAME['PlayerToMove']][$GAME['RailEnds'][$linktobuild]]) {
            $errorlist .= transtext('memRailNotConn') . '<br>';
            // "You cannot build that rail link, as you have neither connected to nor built in either location."
        }
        switch ($coalsource) {
            case 90:
                $errorlist .= transtext('memCoalNotValid') . '<br>';
                break;
                // "The selected source of coal is not valid."
            // "The selected source of coal is not valid."
            case 91:
                $errorlist .= transtext('memCoalOnBoard') . '<br>';
                break;
                // "You cannot buy coal from the Demand Track,
                // as there is coal available on the board for you to use."
            // "You cannot buy coal from the Demand Track,
            // as there is coal available on the board for you to use."
            case 92:
                $errorlist .= transtext('memCoalNearer') . '<br>';
                break;
            case 93:
                $errorlist .= 'The selected source of coal is not connected to the location where you are trying to build.<br>';
                break;
            case 95:
                $errorlist .= transtext('memCoalNoPorts') . '<br>';
                break;
                // "You cannot buy coal from the Demand Track,
                // as the location where you want to build is not connected to a Port."
        }
    } else {
        if (!$GAME['CanalAlwaysExists'][$linktobuild] and ($GAME['ModularBoardParts'] & $GAME['CanalExistenceArray'][$linktobuild]) != $GAME['CanalExistenceArray'][$linktobuild]) {
            $errorlist .= transtext('memCanalNotThere') . '<br>';
            // That canal link does not exist (or it no longer exists) in this game.
        }
        if (!$GAME['HasBuiltInTown'][$GAME['PlayerToMove']][$GAME['CanalStarts'][$linktobuild]] and !$GAME['HasBuiltInTown'][$GAME['PlayerToMove']][$GAME['CanalEnds'][$linktobuild]] and !$GAME['HasLinkedToTown'][$GAME['PlayerToMove']][$GAME['CanalStarts'][$linktobuild]] and !$GAME['HasLinkedToTown'][$GAME['PlayerToMove']][$GAME['CanalEnds'][$linktobuild]]) {
            $errorlist .= transtext('memCanalNotConn') . '<br>';
            // "You cannot build that canal link, as you have neither connected to nor built in either location."
        }
    }
    $MoneyWarning = true;
    if (!$GAME['RailPhase'] and $GAME['Money'][$GAME['PlayerToMove']] < 3) {
        $errorlist .= transtext('memCanalPoor') . '<br>';
        // "You cannot afford to build a canal link."
    }
    if ($GAME['RailPhase'] and $GAME['Money'][$GAME['PlayerToMove']] < 5) {
        $MoneyWarning = false;
        $errorlist .= transtext('memRailPoor') . '<br>';
        // "You cannot afford to build a rail link."
    }
    if ($GAME['RailPhase'] and $MoneyWarning and $coalsource == 50 and $GAME['Money'][$GAME['PlayerToMove']] < 5 * $buildnum + $GAME['cubeprice'][$GAME['CoalDemand']]) {
        $errorlist .= transtext('memRailPoorCoal') . '<br>';
        // "Although you can afford to build a rail link, you cannot afford
        // to buy from the Demand Track the coal cube needed to build it."
    }
    if (!$GAME['RemainingTiles'][5][$GAME['PlayerToMove']]) {
        if ($GAME['RailPhase']) {
            $errorlist .= transtext('memOutOfRails') . '<br>';
        } else {
            $errorlist .= transtext('memOutOfCanals') . '<br>';
        }
        // "You do not have any rail/canal markers left."
    }
    if ($coalsource == 50) {
        $altcoalsource = 99;
    } else {
        $altcoalsource = $coalsource;
    }
    if ($errorlist == '') {
        if ($SystemActing) {
            $AdminTakingMove = 0;
        } else {
            if ($GAME['PlayerUserID'][$GAME['PlayerToMove']] == $_SESSION['MyUserID']) {
                $AdminTakingMove = 0;
            } else {
                $AdminTakingMove = 1;
            }
        }
        $GAME['RemainingTiles'][5][$GAME['PlayerToMove']]--;
        $GAME['LinkStatus'][$linktobuild] = $GAME['PlayerToMove'];
        $GAME['Money'][$GAME['PlayerToMove']] -= (3 + 2 * $GAME['RailPhase']) * $buildnum;
        $GAME['AmountSpent'][$GAME['PlayerToMove']] += (3 + 2 * $GAME['RailPhase']) * $buildnum;
        if ($GAME['RailPhase']) {
            if ($GAME['CoalNet'][$GAME['RailStarts'][$linktobuild]] < $GAME['CoalNet'][$GAME['RailEnds'][$linktobuild]]) {
                $LowCoalNet = $GAME['CoalNet'][$GAME['RailStarts'][$linktobuild]];
                $HighCoalNet = $GAME['CoalNet'][$GAME['RailEnds'][$linktobuild]];
            } else {
                $LowCoalNet = $GAME['CoalNet'][$GAME['RailEnds'][$linktobuild]];
                $HighCoalNet = $GAME['CoalNet'][$GAME['RailStarts'][$linktobuild]];
            }
            if ($GAME['HasPort'][$GAME['RailStarts'][$linktobuild]] or $GAME['HasPort'][$GAME['RailEnds'][$linktobuild]]) {
                $AssignHasPort = 1;
            } else {
                $AssignHasPort = 0;
            }
            for ($i = 0; $i < $GAME['NumTowns']; $i++) {
                if ($GAME['CoalNet'][$i] == $HighCoalNet) {
                    $GAME['CoalNet'][$i] = $LowCoalNet;
                }
                if ($GAME['CoalNet'][$i] == $LowCoalNet) {
                    $GAME['HasPort'][$i] = $AssignHasPort;
                }
            }
            if ($coalsource == 50) {
                $GAME['Money'][$GAME['PlayerToMove']] -= $GAME['cubeprice'][$GAME['CoalDemand']];
                $GAME['AmountSpent'][$GAME['PlayerToMove']] += $GAME['cubeprice'][$GAME['CoalDemand']];
                if ($GAME['CurrentPlayers'] == 2 and $GAME['CoalDemand'] < 6 or $GAME['CurrentPlayers'] > 2 and $GAME['CoalDemand'] < 8) {
                    $GAME['CoalDemand']++;
                }
            } else {
                $GAME['CoalInLancs']--;
                $GAME['SpaceCubes'][$coalsource] = $GAME['SpaceCubes'][$coalsource] - 1;
                // This is written in this way because SpaceCubes is a string consisting of digits
                // (it is not legal to use increment/decrement operators on string offsets).
                if (!$GAME['SpaceCubes'][$coalsource]) {
                    fliptile($coalsource);
                }
            }
            $GAME['HasLinkedToTown'][$GAME['PlayerToMove']][$GAME['RailStarts'][$linktobuild]] = 1;
            $GAME['HasLinkedToTown'][$GAME['PlayerToMove']][$GAME['RailEnds'][$linktobuild]] = 1;
            if ($buildnum == 2) {
                if ($AdminTakingMove) {
                    $altgoodoutput = '2D' . callmovetimediff() . letter_end_number($_SESSION['MyUserID']) . letter_end_number($_SESSION['MyGenderCode']) . letter_end_number($linktobuild) . letter_end_number($altcoalsource);
                    $altgoodoutputName = '|' . $_SESSION['MyUserName'];
                } else {
                    $altgoodoutput = 'I' . callmovetimediff() . letter_end_number($linktobuild) . letter_end_number($altcoalsource);
                    $altgoodoutputName = '';
                }
                $GAME['SecondRailMode'] = 0;
            } else {
                if ($AdminTakingMove) {
                    $altgoodoutput = '1I' . callmovetimediff() . letter_end_number($_SESSION['MyUserID']) . letter_end_number($_SESSION['MyGenderCode']) . letter_end_number($thecard) . letter_end_number($linktobuild) . letter_end_number($altcoalsource);
                    $altgoodoutputName = '|' . $_SESSION['MyUserName'];
                } else {
                    $altgoodoutput = 'D' . callmovetimediff() . letter_end_number($thecard) . letter_end_number($linktobuild) . letter_end_number($altcoalsource);
                    $altgoodoutputName = '';
                }
                if (!$GAME['RemainingTiles'][5][$GAME['PlayerToMove']]) {
                    $altgoodoutput .= '9IB';
                } else {
                    if ($GAME['Money'][$GAME['PlayerToMove']] < 10) {
                        $altgoodoutput .= '9IC';
                    } else {
                        if ($GAME['CoalInLancs'] or $GAME['Money'][$GAME['PlayerToMove']] > 9 + $GAME['cubeprice'][$GAME['CoalDemand']]) {
                            for ($i = 0; $i < $GAME['NumRailLinks']; $i++) {
                                if (($GAME['HasPort'][$GAME['RailEnds'][$i]] or $GAME['HasPort'][$GAME['RailStarts'][$i]]) and $GAME['Money'][$GAME['PlayerToMove']] > 9 + $GAME['cubeprice'][$GAME['CoalDemand']] and $GAME['LinkStatus'][$i] == 9 and ($GAME['HasBuiltInTown'][$GAME['PlayerToMove']][$GAME['RailStarts'][$i]] or $GAME['HasBuiltInTown'][$GAME['PlayerToMove']][$GAME['RailEnds'][$i]] or $GAME['HasLinkedToTown'][$GAME['PlayerToMove']][$GAME['RailStarts'][$i]] or $GAME['HasLinkedToTown'][$GAME['PlayerToMove']][$GAME['RailEnds'][$i]])) {
                                    $GAME['SecondRailMode'] = 1;
                                    break;
                                }
                                for ($j = 0; $j < $GAME['NumIndustrySpaces']; $j++) {
                                    if ($GAME['SpaceStatus'][$j] != 9 and $GAME['SpaceTile'][$j] == 1 and $GAME['SpaceCubes'][$j] and ($GAME['CoalNet'][$GAME['spacetowns'][$j]] == $GAME['CoalNet'][$GAME['RailStarts'][$i]] or $GAME['CoalNet'][$GAME['spacetowns'][$j]] == $GAME['CoalNet'][$GAME['RailEnds'][$i]]) and ($GAME['HasBuiltInTown'][$GAME['PlayerToMove']][$GAME['RailStarts'][$i]] or $GAME['HasBuiltInTown'][$GAME['PlayerToMove']][$GAME['RailEnds'][$i]] or $GAME['HasLinkedToTown'][$GAME['PlayerToMove']][$GAME['RailStarts'][$i]] or $GAME['HasLinkedToTown'][$GAME['PlayerToMove']][$GAME['RailEnds'][$i]]) and $GAME['LinkStatus'][$i] == 9 and ($GAME['RailAlwaysExists'][$i] or $GAME['ModularBoardParts'] & $GAME['RailExistenceArray'][$i])) {
                                        $GAME['SecondRailMode'] = 1;
                                        break 2;
                                    }
                                }
                            }
                        }
                        if (!$GAME['SecondRailMode']) {
                            $altgoodoutput .= '9IA';
                        }
                    }
                }
            }
        } else {
            if ($GAME['CoalNet'][$GAME['CanalStarts'][$linktobuild]] < $GAME['CoalNet'][$GAME['CanalEnds'][$linktobuild]]) {
                $LowCoalNet = $GAME['CoalNet'][$GAME['CanalStarts'][$linktobuild]];
                $HighCoalNet = $GAME['CoalNet'][$GAME['CanalEnds'][$linktobuild]];
            } else {
                $LowCoalNet = $GAME['CoalNet'][$GAME['CanalEnds'][$linktobuild]];
                $HighCoalNet = $GAME['CoalNet'][$GAME['CanalStarts'][$linktobuild]];
            }
            if ($GAME['HasPort'][$GAME['CanalStarts'][$linktobuild]] or $GAME['HasPort'][$GAME['CanalEnds'][$linktobuild]]) {
                $AssignHasPort = 1;
            } else {
                $AssignHasPort = 0;
            }
            for ($i = 0; $i < $GAME['NumTowns']; $i++) {
                if ($GAME['CoalNet'][$i] == $HighCoalNet) {
                    $GAME['CoalNet'][$i] = $LowCoalNet;
                }
                if ($GAME['CoalNet'][$i] == $LowCoalNet) {
                    $GAME['HasPort'][$i] = $AssignHasPort;
                }
            }
            $GAME['HasLinkedToTown'][$GAME['PlayerToMove']][$GAME['CanalStarts'][$linktobuild]] = 1;
            $GAME['HasLinkedToTown'][$GAME['PlayerToMove']][$GAME['CanalEnds'][$linktobuild]] = 1;
            if ($AdminTakingMove) {
                $altgoodoutput = '1I' . callmovetimediff() . letter_end_number($_SESSION['MyUserID']) . letter_end_number($_SESSION['MyGenderCode']) . letter_end_number($thecard) . letter_end_number($linktobuild);
                $altgoodoutputName = '|' . $_SESSION['MyUserName'];
            } else {
                $altgoodoutput = 'D' . callmovetimediff() . letter_end_number($thecard) . letter_end_number($linktobuild);
                $altgoodoutputName = '';
            }
        }
    } else {
        $altgoodoutput = '';
        $altgoodoutputName = '';
    }
    return array($errorlist, '', $altgoodoutput, $altgoodoutputName);
}
Esempio n. 5
0
function flip_UOCMs()
{
    // This function runs at the end of each phase if the game has been downsized. It simulates
    // attempting to flip orphan Cotton Mills, in order to avoid unfairness to players who have
    // attempted a Port strategy. It first makes a list of unflipped orphan Cotton Mills,
    // then it makes lists of "good" Ports (those that generate points for the "orphan player")
    // and of "bad" Ports (those that generate points only for the "real" players). Then
    // it goes through four steps to try and flip these Cotton Mills and good Ports.
    // "Desirability" of flipping a tile is evaluated first on how many points it would earn for
    // the "orphan player" (more points is good), then on how many points it would earn for the
    // the "real players" collectively (more points is bad). If two tiles of the same type are
    // tied for desirability, then their relative order is randomised.
    global $GAME;
    $UOCMs_numbers = array();
    $UOCMs_desirability = array();
    $UOCMs_networkcomponent = array();
    $UOCMs_random = array();
    $good_UPs_numbers = array();
    $good_UPs_desirability = array();
    $good_UPs_networkcomponent = array();
    $good_UPs_random = array();
    $bad_UPs_numbers = array();
    $bad_UPs_desirability = array();
    $bad_UPs_networkcomponent = array();
    $bad_UPs_random = array();
    for ($i = 0; $i < $GAME['NumIndustrySpaces']; $i++) {
        if ($GAME['SpaceStatus'][$i] == 8 and $GAME['SpaceCubes'][$i] and !$GAME['SpaceTile'][$i]) {
            $desirability = flip_UOCMs_evaltile($i);
            if ($desirability > 0) {
                $UOCMs_numbers[] = $i;
                $UOCMs_desirability[] = $desirability;
                $UOCMs_networkcomponent[] = $GAME['CoalNet'][$GAME['spacetowns'][$i]];
                $UOCMs_random[] = $i;
            }
        }
        if ($GAME['SpaceStatus'][$i] != 9 and $GAME['SpaceCubes'][$i] and $GAME['SpaceTile'][$i] == 3) {
            $desirability = flip_UOCMs_evaltile($i);
            if ($desirability > 0) {
                $good_UPs_numbers[] = $i;
                $good_UPs_desirability[] = flip_UOCMs_evaltile($i);
                $good_UPs_networkcomponent[] = $GAME['CoalNet'][$GAME['spacetowns'][$i]];
                $good_UPs_random[] = $i;
            } else {
                $bad_UPs_numbers[] = $i;
                $bad_UPs_desirability[] = flip_UOCMs_evaltile($i);
                $bad_UPs_networkcomponent[] = $GAME['CoalNet'][$GAME['spacetowns'][$i]];
                $bad_UPs_random[] = $i;
            }
        }
    }
    if (!count($UOCMs_numbers)) {
        return;
    }
    shuffle($UOCMs_random);
    shuffle($good_UPs_random);
    shuffle($bad_UPs_random);
    array_multisort($UOCMs_desirability, SORT_DESC, $UOCMs_random, $UOCMs_numbers, $UOCMs_networkcomponent);
    array_multisort($good_UPs_desirability, SORT_DESC, $good_UPs_random, $good_UPs_numbers, $good_UPs_networkcomponent);
    array_multisort($bad_UPs_desirability, SORT_DESC, $bad_UPs_random, $bad_UPs_numbers, $bad_UPs_networkcomponent);
    for ($i = 0; $i < count($good_UPs_numbers); $i++) {
        // First, for each "good" Port, I try to find the "best"
        // Cotton Mill that's connected to it, and flip them both.
        for ($j = 0; $j < count($UOCMs_numbers); $j++) {
            if ($UOCMs_networkcomponent[$j] == $good_UPs_networkcomponent[$i]) {
                $GAME['AltGameTicker'] .= '7F' . letter_end_number($UOCMs_numbers[$j]) . letter_end_number($good_UPs_numbers[$i]);
                fliptile($UOCMs_numbers[$j]);
                fliptile($good_UPs_numbers[$i]);
                array_splice($UOCMs_numbers, $j, 1);
                array_splice($UOCMs_networkcomponent, $j, 1);
                array_splice($good_UPs_numbers, $i, 1);
                array_splice($good_UPs_networkcomponent, $i, 1);
                $i--;
                break;
            }
        }
    }
    if (!count($UOCMs_numbers)) {
        return;
    }
    $NetworkComponents = array_unique($GAME['CoalNet']);
    $NetworkComponentsRenumbered = array();
    foreach ($NetworkComponents as $key => $value) {
        $NetworkComponentsRenumbered[] = $value;
        // array_unique() preserves keys, which I don't want.
    }
    for ($i = 0; $i < count($NetworkComponentsRenumbered); $i++) {
        $PortCMBalance[$NetworkComponentsRenumbered[$i]] = 0;
    }
    for ($i = 0; $i < count($UOCMs_numbers); $i++) {
        $PortCMBalance[$UOCMs_networkcomponent[$i]]++;
    }
    for ($i = 0; $i < count($bad_UPs_numbers); $i++) {
        $PortCMBalance[$bad_UPs_networkcomponent[$i]]--;
    }
    while (DMSaleSuccessProbability() == 1) {
        // Second, for as long as success in selling to the Distant Market is assured,
        // I look for Cotton Mills that are in a network component with too many Cotton
        // Mills compared to Ports, and I flip them via the Distant Market. I only need
        // to look for "bad" Ports from this point on, since following the previous step,
        // all unflipped "good" Ports are disconnected from the remaining Cotton Mills.
        for ($i = 0; $i < count($UOCMs_numbers); $i++) {
            if ($GAME['HasPort'][$UOCMs_networkcomponent[$i]] and $PortCMBalance[$UOCMs_networkcomponent[$i]] > 0) {
                $GAME['AltGameTicker'] .= '7F' . letter_end_number($UOCMs_numbers[$i]) . '9J';
                drawDMtile();
                fliptile($UOCMs_numbers[$i]);
                array_splice($UOCMs_numbers, $i, 1);
                array_splice($UOCMs_networkcomponent, $i, 1);
                continue 2;
            }
        }
        break;
    }
    while (DMSaleSuccessProbability() == 1) {
        // Third, for as long as success in selling to the Distant Market is assured,
        // I try to find the "worst" Port and flip, via the Distant Market, any Cotton Mill
        // that's connected to it. The Port concerned is deleted from the array of
        // "bad" Ports when I do this - it can no longer be required, so I eliminate it
        // the better to identify the "worst" Port that I can still be compelled to use.
        for ($i = count($bad_UPs_numbers) - 1; $i >= 0; $i--) {
            for ($j = 0; $j < count($UOCMs_numbers); $j++) {
                if ($UOCMs_networkcomponent[$j] == $bad_UPs_networkcomponent[$i]) {
                    $GAME['AltGameTicker'] .= '7F' . letter_end_number($UOCMs_numbers[$j]) . '9J';
                    drawDMtile();
                    fliptile($UOCMs_numbers[$j]);
                    array_splice($UOCMs_numbers, $j, 1);
                    array_splice($UOCMs_networkcomponent, $j, 1);
                    array_splice($bad_UPs_numbers, $i, 1);
                    array_splice($bad_UPs_networkcomponent, $i, 1);
                    continue 3;
                }
            }
        }
        break;
    }
    for ($i = 0; $i < count($UOCMs_numbers); $i++) {
        // Fourth, for each Cotton Mill, I try to find the "best" Port
        // that's connected to it, and flip them both.
        for ($j = 0; $j < count($bad_UPs_numbers); $j++) {
            if ($bad_UPs_networkcomponent[$j] == $UOCMs_networkcomponent[$i]) {
                $GAME['AltGameTicker'] .= '7F' . letter_end_number($UOCMs_numbers[$i]) . letter_end_number($bad_UPs_numbers[$j]);
                fliptile($UOCMs_numbers[$i]);
                fliptile($bad_UPs_numbers[$j]);
                array_splice($UOCMs_numbers, $i, 1);
                array_splice($UOCMs_networkcomponent, $i, 1);
                array_splice($bad_UPs_numbers, $j, 1);
                array_splice($bad_UPs_networkcomponent, $j, 1);
                $i--;
                break;
            }
        }
    }
    while ($GAME['CottonDemand'] < 8) {
        // Finally, I try to flip the remaining Cotton Mills using the Distant Market,
        // until the demand for cotton runs out.
        for ($i = 0; $i < count($UOCMs_numbers); $i++) {
            if ($GAME['HasPort'][$UOCMs_networkcomponent[$i]]) {
                $GAME['AltGameTicker'] .= '7F' . letter_end_number($UOCMs_numbers[$i]) . '9J';
                if (drawDMtile()) {
                    fliptile($UOCMs_numbers[$i]);
                    array_splice($UOCMs_numbers, $i, 1);
                    array_splice($UOCMs_networkcomponent, $i, 1);
                    if (!DMSaleSuccessProbability()) {
                        $GAME['CottonDemand'] = 8;
                        $GAME['AltGameTicker'] .= '9J';
                    }
                    continue 2;
                } else {
                    break 2;
                }
            }
        }
        break;
    }
}