GameController.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * Created by IntelliJ IDEA.
  4. * User: solu
  5. * Date: 2019/3/1
  6. * Time: 5:03 PM
  7. */
  8. class GameController extends BaseController {
  9. public function actionData($args) {
  10. $horseNum = 8; // 马数量
  11. $stageNum = 5; // 舞台数量
  12. $stageLength = 120; // 舞台长度
  13. $objGame = new Game();
  14. $horseList = $objGame->initHorse($horseNum);
  15. $eventList = $objGame->initEvent($stageNum);
  16. $winnerIndex = 0;
  17. $minTime = 2000;
  18. foreach ($horseList as $i => $horse) {
  19. // 第一阶段
  20. $total_time = 0;
  21. for ($j = 0; $j < $stageNum; $j++) {
  22. $weatherNum = $eventList[$j][0]; // 第一个数字是天气
  23. $eventNum = $eventList[$j][$i]; // 当前马匹的事件
  24. $bufferSpeed = Game::getBufferSpeed($weatherNum, $eventNum, $horse);
  25. $time = $stageLength / $bufferSpeed;
  26. $total_time += $time;
  27. $horse['time' . $j] = $time;
  28. }
  29. $horse['total_time'] = round($total_time);
  30. if ($minTime > $total_time) {
  31. $minTime = $total_time;
  32. $winnerIndex = $i;
  33. }
  34. $horseList[$i] = $horse;
  35. }
  36. return compact('horseNum', 'stageNum', 'stageLength', 'winnerIndex', 'horseList', 'eventList');
  37. }
  38. }