<?php
/**
 * Created by IntelliJ IDEA.
 * User: solu
 * Date: 2019/3/1
 * Time: 5:03 PM
 */

class GameController extends BaseController {

    public function actionData($args) {

        $horseNum = 8;       // 马数量
        $stageNum = 5;       // 舞台数量
        $stageLength = 120;    // 舞台长度

        $objGame = new Game();
        $horseList = $objGame->initHorse($horseNum);
        $eventList = $objGame->initEvent($stageNum);

        $winnerIndex = 0;
        $minTime = 2000;
        foreach ($horseList as $i => $horse) {
            // 第一阶段
            $total_time = 0;
            for ($j = 0; $j < $stageNum; $j++) {
                $weatherNum = $eventList[$j][0]; // 第一个数字是天气
                $eventNum = $eventList[$j][$i];    // 当前马匹的事件

                $bufferSpeed = Game::getBufferSpeed($weatherNum, $eventNum, $horse);
                $time = $stageLength / $bufferSpeed;
                $total_time += $time;
                $horse['time' . $j] = $time;
            }

            $horse['total_time'] = round($total_time);
            if ($minTime > $total_time) {
                $minTime = $total_time;
                $winnerIndex = $i;
            }

            $horseList[$i] = $horse;
        }

        return compact('horseNum', 'stageNum', 'stageLength', 'winnerIndex', 'horseList', 'eventList');
    }

}