big steppy
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

155 wiersze
3.5 KiB

  1. function random_desc(list, odds=1) {
  2. if (Math.random() < odds)
  3. return list[Math.floor(Math.random() * list.length)];
  4. else
  5. return "";
  6. }
  7. function merge_things(list) {
  8. if (list.length == 0) {
  9. return "";
  10. } else if (list.length == 1) {
  11. return list[0];
  12. } else if (list.length == 2) {
  13. return list[0] + " and " + list[1];
  14. } else {
  15. result = "";
  16. list.slice(0,list.length-1).forEach(function(term) {
  17. result += term + ", ";
  18. })
  19. result += "and " + list[list.length-1]
  20. return result;
  21. }
  22. }
  23. function merge_desc(list) {
  24. result = ""
  25. list.forEach(function(term) {
  26. if (term != "")
  27. result += term + " ";
  28. });
  29. // knock off the last space
  30. if (result.length > 0) {
  31. result = result.substring(0, result.length - 1);
  32. }
  33. return result;
  34. }
  35. // maybe make this something that approximates a
  36. // normal distribution; doing this 15,000,000 times is bad...
  37. function distribution(min, max, samples) {
  38. var result = 0;
  39. for (var i = 0; i < samples; i++) {
  40. result += Math.floor(Math.random() * (max - min + 1) + min);
  41. }
  42. return result;
  43. }
  44. function Person(count = 1) {
  45. this.name = "Person";
  46. this.count = count;
  47. this.contents = [];
  48. this.describeOne = function () {
  49. sex = random_desc(["male", "female"]);
  50. body = random_desc(["skinny","fat","tall","short","stocky","spindly"],0.6);
  51. species = random_desc(["wolf","cat","dog","squirrel","horse","hyena","fox","jackal","crux","sergal"]);
  52. return "a " + merge_desc([sex,body,species]);
  53. }
  54. this.describe = function() {
  55. if (count <= 3) {
  56. list = [];
  57. for (var i = 0; i < count; i++) {
  58. list.push(this.describeOne());
  59. }
  60. return merge_things(list);
  61. } else {
  62. return this.count + " people."
  63. }
  64. }
  65. return this;
  66. }
  67. function EmptyCar(count = 1) {
  68. this.name = "Car";
  69. this.count = count;
  70. this.contents = [];
  71. this.describeOne
  72. }
  73. function Car(count = 1) {
  74. this.name = "Car";
  75. this.count = count;
  76. this.contents = [];
  77. var amount = distribution(2,5,count);
  78. this.contents.push(new Person(amount));
  79. }
  80. function Bus(count = 1) {
  81. this.name = "Bus";
  82. this.count = count;
  83. this.contents = [];
  84. this.resolved = false;
  85. var amount = distribution(10,35,count);
  86. this.contents.push(new Person(amount));
  87. }
  88. function Motorcycle(count = 1) {
  89. this.name = "Motorcycle";
  90. this.count = count;
  91. this.contents = [];
  92. var amount = distribution(1,2,count);
  93. this.contents.push(new Person(amount));
  94. }
  95. function Train(count = 1) {
  96. this.name = "Train";
  97. this.count = count;
  98. this.contents = [];
  99. var amount = distribution(20,60,count);
  100. this.contents.push(new Person(amount));
  101. }
  102. function House(count = 1) {
  103. this.name = "House";
  104. this.count = count;
  105. this.contents = [];
  106. var amount = distribution(0,8,count);
  107. this.contents.push(new Person(amount));
  108. amount = distribution(0,2,count);
  109. this.contents.push(new Car(amount));
  110. }
  111. function ParkingGarage(count = 1) {
  112. this.name = "Parking Garage";
  113. this.count = count;
  114. this.contents = [];
  115. var amount = distribution(10,200,count);
  116. this.contents.push(new Person(amount));
  117. amount = distribution(30,100,count);
  118. this.contents.push(new EmptyCar(amount));
  119. amount = distribution(5,20,count);
  120. this.contents.push(new Car(amount));
  121. }
  122. function Overpass(count = 1) {
  123. this.name = "Overpass";
  124. this.count = count;
  125. this.contents = [];
  126. var amount = distribution(0,20,count);
  127. this.contents.push(new Person(amount));
  128. amount = distribution(25,100,count);
  129. this.contents.push(new Car(amount));
  130. }