moniHorse.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. require_once realpath(dirname(__FILE__)) . '/../common.php';
  3. ini_set("display_errors", "On");
  4. error_reporting(E_ALL & ~E_NOTICE);
  5. $horseNum = 8; // 马数量
  6. $stageNum = 5; // 舞台数量
  7. $stageLength = 120; // 舞台长度
  8. $horseList = initHorse($horseNum);
  9. $map = [];
  10. for ($n = 0; $n < 10000; $n++) {
  11. $eventList = initEvent($stageNum);
  12. $winnerIndex = 0;
  13. $minTime = 2000;
  14. foreach ($horseList as $i => $horse) {
  15. // 第一阶段
  16. $total_time = 0;
  17. for ($j = 0; $j < $stageNum; $j++) {
  18. $weatherNum = $eventList[$j][0]; // 第一个数字是天气
  19. $eventNum = $eventList[$j][$i]; // 当前马匹的事件
  20. $bufferSpeed = getBufferSpeed($weatherNum, $eventNum, $horse);
  21. $time = $stageLength / $bufferSpeed;
  22. $total_time += $time;
  23. $horse['time' . $j] = $time;
  24. $weatherStr = getWeatherStr($weatherNum);
  25. $eventStr = getEventStr($eventNum);
  26. // EosBase::log("NO.{$n}, {$i}th horse round {$j}, {$weatherStr} {$eventStr}, bufferSpeed:{$bufferSpeed}, speed total:{$total_time}, time: {$time}");
  27. }
  28. $horse['total_time'] = round($total_time);
  29. if ($minTime > $total_time) {
  30. $minTime = $total_time;
  31. $winnerIndex = $i;
  32. }
  33. $horseList[$i] = $horse;
  34. }
  35. $total_time_list = array_column($horseList, 'total_time');
  36. $map[$winnerIndex]++;
  37. $minTime = round($minTime);
  38. // EosBase::log("++++++++++++++++ NO.{$n} game, winner: {$winnerIndex}, time:{$minTime} ++++++++++++++++++, list:" . join(", ", $total_time_list));
  39. }
  40. ksort($map);
  41. foreach ($map as $i => $times) {
  42. $horse = $horseList[$i];
  43. EosBase::log("第{$i}只马,获胜{$times}次, 总能力:{$horse['ability']}, 速度:{$horse['speed']}, 跳跃:{$horse['jump']}, 敏捷:{$horse['agility']}, 幸运:{$horse['luck']}, 意志:{$horse['volition']}");
  44. }
  45. function getWeatherStr($weatherNum) {
  46. if ($weatherNum == 0) {
  47. return 'weather:wind, ';
  48. } else if ($weatherNum == 1) {
  49. return 'weather:snow, ';
  50. } else {
  51. return '';
  52. }
  53. }
  54. function getEventStr($eventNum) {
  55. switch ($eventNum) {
  56. case 0:
  57. case 1:
  58. case 2:
  59. return "event:石头, ";
  60. case 4:
  61. case 5:
  62. case 6:
  63. return "event:泥坑, ";
  64. case 7:
  65. case 8:
  66. return "event:加速, ";
  67. }
  68. return 'event:正常';
  69. }
  70. function getBufferSpeed($weatherNum, $eventNum, $horse) {
  71. $speed = $horse['speed'];
  72. // 0 属于正常跑
  73. // 1 ~ 3 属于 石头,靠跳跃 0.3
  74. // 4 ~ 6 属于 泥坑,靠敏捷 0.3
  75. // 7 ~ 9 属于 Buffer,靠幸运 0.3
  76. switch ($eventNum) {
  77. case 0:
  78. case 1:
  79. case 2:
  80. $speed *= $horse['jump'] / 100;
  81. break;
  82. case 4:
  83. case 5:
  84. case 6:
  85. $speed *= $horse['agility'] / 100;
  86. break;
  87. case 7:
  88. case 8:
  89. $speed += $horse['luck'] + 10;
  90. break;
  91. }
  92. // 0、1 属于 逆风、下雪,靠意志 0.2
  93. if ($weatherNum == 0 || $weatherNum == 1) {
  94. $speed *= $horse['volition'] / 100;
  95. }
  96. $speed = max($speed, 10);
  97. return $speed;
  98. }
  99. function initHorse($horseNum) {
  100. $horseList = [];
  101. for ($i = 0; $i < $horseNum; $i++) {
  102. $horse = [
  103. "speed" => rand(20, 90), // 速度
  104. "jump" => rand(1, 90), // 跳跃
  105. "agility" => rand(1, 90), // 敏捷
  106. "luck" => rand(20, 90), // 幸运
  107. "volition" => rand(10, 90), // 意志
  108. ];
  109. foreach ($horse as $value) {
  110. $horse['ability'] += $value;
  111. }
  112. $horseList[] = $horse;
  113. EosBase::log("第{$i}只马: 速度:{$horse['speed']}, 跳跃:{$horse['jump']}, 敏捷:{$horse['agility']}, 幸运:{$horse['luck']}, 意志:{$horse['volition']}");
  114. }
  115. return $horseList;
  116. }
  117. function initEvent($stageNum) {
  118. $list = [];
  119. for ($num = $stageNum; $num >= 1; $num--) {
  120. $numList = [];
  121. for ($i = 0; $i < 9; $i++) {
  122. // $numList[] = rand(0, 9);
  123. $numList[] = rand(0, 9);
  124. }
  125. $list[] = $numList;
  126. }
  127. return $list;
  128. }