示例#1
0
    $index = rand(0, sizeof($list) - 1);
    if ($isAssociative) {
        $keys = array_keys($list);
        $name = $keys[$index];
        return array($name => $list[$name]);
    }
    return $list[$index];
}
function setColor($color)
{
    global $__COLOR__;
    $__COLOR__ = key($color);
    global $__COLOR_TONE__;
    $__COLOR_TONE__ = $color[$__COLOR__];
}
function setQuestion($question)
{
    global $__QUESTION__;
    $__QUESTION__ = $question;
}
function setAnswer($answer)
{
    global $__ANSWER__;
    $__ANSWER__ = $answer;
}
$pickedColor = pickRandom($colors, true);
$pickedQuestion = pickRandom($questions);
$pickedAnswer = pickRandom($answers);
setColor($pickedColor);
setQuestion($pickedQuestion);
setAnswer($pickedAnswer);
 for ($i = 1; $i <= CITY_COUNT; $i++) {
     for ($j = 1; $j <= CITY_COUNT; $j++) {
         if (isset($_POST[$i . '_' . $j])) {
             $distances[$i][$j] = $_POST[$i . '_' . $j];
         } else {
             if (isset($_POST[$j . '_' . $i])) {
                 $distances[$i][$j] = $_POST[$j . '_' . $i];
             } else {
                 $distances[$i][$j] = 32767;
             }
         }
     }
 }
 # Building our initial population
 for ($i = 0; $i < $population; $i++) {
     $initialPopulation[$i] = pickRandom();
 }
 for ($k = 1; $k <= $generations; $k++) {
     echo "<div><strong>Generation '" . $k . "'</strong></div>\n";
     # Rating population in accordance with fitness value.
     echo "<pre>";
     $i = 0;
     $distanceSum = 0;
     $biggest = 0;
     foreach ($initialPopulation as $entity) {
         $currentPopulation[$i]['dna'] = $entity;
         $currentPopulation[$i]['rate'] = rate($entity, $distances);
         $distanceSum += $currentPopulation[$i]['rate'];
         if ($currentPopulation[$i]['rate'] > $biggest) {
             $biggest = $currentPopulation[$i]['rate'];
         }
示例#3
0
function showLucky()
{
    $result = "";
    global $activities, $iday, $drinks, $directions;
    $result .= "今天是" . date("Y年m月d日 l", time());
    $_activities = filter($activities);
    $numGood = random($iday, 98) % 3 + 2;
    $numBad = random($iday, 87) % 3 + 2;
    $eventArr = pickRandomActivity($_activities, $numGood + $numBad);
    $result .= "\n\n宜:\n";
    for ($i = 0; $i < $numGood; $i++) {
        $result .= $i . ".「" . $eventArr[$i]['name'] . "」" . $eventArr[$i]['good'] . "\n";
    }
    $result .= "\n不宜:\n";
    for ($i = 0; $i < $numBad; $i++) {
        $result .= $i . ".「" . $eventArr[$i + $numGood]['name'] . "」" . $eventArr[$i + $numGood]['bad'] . "\n";
    }
    $result .= "\n座位朝向:\n";
    $result .= "面向「" . $directions[random($iday, 2) % sizeof($directions)] . "」写程序,bug最少\n";
    $result .= "\n今日宜饮:\n";
    $todayDrink = pickRandom($drinks, 2);
    $result .= $todayDrink[0] . "、" . $todayDrink[1];
    $result .= "\n\n女神亲近指数:\n";
    $result .= star(random($iday, 6) % 5 + 1);
    return $result;
}