No Description

battle_test.c 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. /****************************************************************************
  2. * Copyright (C) 2015-2016 by the SotS Team *
  3. * *
  4. * This file is part of Sovereign of the Skies. *
  5. * *
  6. * Sovereign of the Skies is free software: you can redistribute it *
  7. * and/or modify it *
  8. * under the terms of the GNU Lesser General Public License as published *
  9. * by the Free Software Foundation, either version 3 of the License, or *
  10. * (at your option) any later version provided you include a copy of the *
  11. * licence and this header. *
  12. * *
  13. * Sovereign of the Skies is distributed in the hope that it will be *
  14. * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of *
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  16. * GNU Lesser General Public License for more details. *
  17. * *
  18. * You should have received a copy of the GNU Lesser General Public *
  19. * License along with Sovereign of the Skies. *
  20. * If not, see <http://www.gnu.org/licenses/>. *
  21. ****************************************************************************/
  22. /**
  23. * @file battle_test.c
  24. * @author Sturmvogel
  25. * @date 15 dec 2016
  26. * @brief Unit tests for battles, very temporary and undocumented
  27. */
  28. #include <types.h>
  29. #include <battle_test.h>
  30. #include <debug.h>
  31. #include <battle_initiative.h>
  32. #include <pkmn_abilities.h>
  33. #include <battle_structs.h>
  34. #include <battle_common.h>
  35. #include <battle_custom_structs.h>
  36. #define TEST_AMOUNT 10000
  37. void test_speed() {
  38. debug_print("Initiating Initiative Unit\nTest...\n");
  39. u8 pass = true;
  40. battle_participants[0].spd = 10;
  41. battle_participants[1].spd = 11;
  42. debug_printf("bank_one.spd: %d\n", battle_participants[0].spd);
  43. debug_printf("bank_two.spd: %d\n", battle_participants[1].spd);
  44. debug_print("testing (await TWO):");
  45. enum init_enum result = get_first_to_strike(0, 1, 0);
  46. if (result == TWO)
  47. debug_print("\xFE\x1 pass\n\xFE\x0");
  48. else {
  49. pass = false;
  50. debug_print("\xFE\x2 fail\n\xFE\x0");
  51. }
  52. battle_participants[0].spd = 12;
  53. debug_printf("bank_one.spd: %d\n", battle_participants[0].spd);
  54. debug_printf("bank_two.spd: %d\n", battle_participants[1].spd);
  55. debug_print("testing (await ONE):");
  56. result = get_first_to_strike(0, 1, 0);
  57. if (result == ONE)
  58. debug_print("\xFE\x1 pass\n\xFE\x0");
  59. else {
  60. pass = false;
  61. debug_print("\xFE\x2 fail\n\xFE\x0");
  62. }
  63. battle_participants[0].spd = 10;
  64. battle_participants[1].spd = 11;
  65. debug_printf("bank_one.spd: %d\n", battle_participants[0].spd);
  66. debug_printf("bank_two.spd: %d\n", battle_participants[1].spd);
  67. //trick room
  68. custom_battle_elements.ptr->field_affecting.trick_room = 1;
  69. debug_print("activating trick room...\n");
  70. debug_print("testing (await ONE):");
  71. result = get_first_to_strike(0, 1, 0);
  72. if (result == ONE)
  73. debug_print("\xFE\x1 pass\n\xFE\x0");
  74. else {
  75. pass = false;
  76. debug_print("\xFE\x2 fail\n\xFE\x0");
  77. }
  78. battle_participants[0].spd = 12;
  79. debug_printf("bank_one.spd: %d\n", battle_participants[0].spd);
  80. debug_printf("bank_two.spd: %d\n", battle_participants[1].spd);
  81. debug_print("testing (await TWO):");
  82. result = get_first_to_strike(0, 1, 0);
  83. if (result == TWO)
  84. debug_print("\xFE\x1 pass\n\xFE\x0");
  85. else {
  86. pass = false;
  87. debug_print("\xFE\x2 fail\n\xFE\x0");
  88. }
  89. battle_participants[1].ability_id = ABILITY_STALL;
  90. debug_print("stall test (+tr): ");
  91. result = get_first_to_strike(0, 1, 0);
  92. if (result == ONE)
  93. debug_print("\xFE\x1 pass\n\xFE\x0");
  94. else {
  95. pass = false;
  96. debug_print("\xFE\x2 fail\n\xFE\x0");
  97. }
  98. custom_battle_elements.ptr->field_affecting.trick_room = 0;
  99. debug_print("stall test (-tr): ");
  100. result = get_first_to_strike(0, 1, 0);
  101. if (result == ONE)
  102. debug_print("\xFE\x1 pass\n\xFE\x0");
  103. else {
  104. pass = false;
  105. debug_print("\xFE\x2 fail\n\xFE\x0");
  106. }
  107. battle_participants[1].ability_id = 0;
  108. debug_print("\nPRESS A TO CONTINUE...");
  109. debug_wait_for_btn(1);
  110. debug_clean();
  111. debug_print("speed value tests...\n");
  112. battle_participants[0].spd = 75;
  113. battle_participants[1].spd = 60;
  114. debug_printf("bank_one.spd: %d\n", battle_participants[0].spd);
  115. debug_printf("bank_two.spd: %d\n", battle_participants[1].spd);
  116. u16 speed_one = get_speed(0);
  117. u16 speed_two = get_speed(1);
  118. debug_printf("unaffected speed: %d", speed_one);
  119. debug_printf(": %d", speed_two);
  120. if (speed_one == 75 && speed_two == 60) {
  121. debug_print(" \xFE\x1pass\xFE\x0\n");
  122. } else {
  123. debug_print("\xFE\x02 fail\xFE\x0\n");
  124. pass = false;
  125. }
  126. battle_participants[0].status.flags.paralysis = 1;
  127. battle_participants[1].status.flags.paralysis = 1;
  128. speed_one = get_speed(0);
  129. speed_two = get_speed(1);
  130. debug_printf("para speed: %d", speed_one);
  131. debug_printf(": %d", speed_two);
  132. if (speed_one == 18 && speed_two == 15) {
  133. debug_print(" \xFE\x1pass\xFE\x0\n");
  134. } else {
  135. debug_print("\xFE\x02 fail\xFE\x0\n");
  136. pass = false;
  137. }
  138. battle_participants[0].spd_buff = 12;
  139. battle_participants[1].spd_buff = 12;
  140. speed_one = get_speed(0);
  141. speed_two = get_speed(1);
  142. debug_printf("para/speed+6: %d", speed_one);
  143. debug_printf(": %d", speed_two);
  144. if (speed_one == 75 && speed_two == 60) {
  145. debug_print(" \xFE\x1pass\xFE\x0\n");
  146. } else {
  147. debug_print("\xFE\x02 fail\xFE\x0\n");
  148. pass = false;
  149. }
  150. battle_participants[0].status.flags.paralysis = 0;
  151. battle_participants[1].status.flags.paralysis = 0;
  152. speed_one = get_speed(0);
  153. speed_two = get_speed(1);
  154. debug_printf("speed+6: %d", speed_one);
  155. debug_printf(": %d", speed_two);
  156. if (speed_one == 300 && speed_two == 240) {
  157. debug_print(" \xFE\x1pass\xFE\x0\n");
  158. } else {
  159. debug_print("\xFE\x02 fail\xFE\x0\n");
  160. pass = false;
  161. }
  162. battle_participants[0].spd_buff = 3;
  163. battle_participants[1].spd_buff = 3;
  164. speed_one = get_speed(0);
  165. speed_two = get_speed(1);
  166. debug_printf("speed-3: %d", speed_one);
  167. debug_printf(": %d", speed_two);
  168. if (speed_one == 30 && speed_two == 24) {
  169. debug_print(" \xFE\x1pass\xFE\x0\n");
  170. } else {
  171. debug_print("\xFE\x02 fail\xFE\x0\n");
  172. pass = false;
  173. }
  174. battle_participants[0].spd_buff = 6;
  175. battle_participants[1].spd_buff = 6;
  176. debug_print("activating chemtrails...\n");
  177. battle_weather.flags.rain = 1;
  178. battle_weather.flags.sun = 1;
  179. battle_weather.flags.sandstorm = 1;
  180. u8 weather_pass = true;
  181. battle_participants[0].ability_id = ABILITY_CHLOROPHYLL;
  182. speed_one = get_speed(0);
  183. if (speed_one != 150)
  184. weather_pass = false;
  185. battle_participants[0].ability_id = ABILITY_SWIFT_SWIM;
  186. speed_one = get_speed(0);
  187. if (speed_one != 150)
  188. weather_pass = false;
  189. battle_participants[0].ability_id = ABILITY_SAND_RUSH;
  190. battle_participants[1].ability_id = ABILITY_SAND_RUSH;
  191. speed_one = get_speed(0);
  192. if (speed_one != 150)
  193. weather_pass = false;
  194. debug_print("weather test:");
  195. debug_print(weather_pass ? "\xFE\x1 pass\xFE\x0\n" : "\xFE\x2 fail\xFE\x0\n");
  196. if (!weather_pass)
  197. pass = false;
  198. debug_print("tailwind + weather: ");
  199. custom_battle_elements.ptr->side_affecting[0].tailwind = 1;
  200. custom_battle_elements.ptr->side_affecting[0].tailwind_bank = 0;
  201. custom_battle_elements.ptr->side_affecting[1].tailwind = 1;
  202. custom_battle_elements.ptr->side_affecting[1].tailwind_bank = 1;
  203. speed_one = get_speed(0);
  204. speed_two = get_speed(1);
  205. if (speed_one == 300 && speed_two == 240) {
  206. debug_print(" \xFE\x1pass\xFE\x0\n");
  207. } else {
  208. debug_print("\xFE\x02 fail\xFE\x0\n");
  209. pass = false;
  210. }
  211. custom_battle_elements.ptr->side_affecting[0].tailwind = 0;
  212. custom_battle_elements.ptr->side_affecting[0].tailwind_bank = 0;
  213. custom_battle_elements.ptr->side_affecting[1].tailwind = 0;
  214. custom_battle_elements.ptr->side_affecting[1].tailwind_bank = 0;
  215. battle_weather.flags.rain = 0;
  216. battle_weather.flags.sun = 0;
  217. battle_weather.flags.sandstorm = 0;
  218. debug_print("quick feet: ");
  219. battle_participants[0].ability_id = ABILITY_QUICK_FEET;
  220. battle_participants[1].ability_id = ABILITY_QUICK_FEET;
  221. battle_participants[0].status.flags.paralysis = 1;
  222. battle_participants[1].status.flags.poison = 1;
  223. speed_one = get_speed(0);
  224. speed_two = get_speed(1);
  225. u8 quick_feet_pass = true;
  226. if (speed_one == 112 && speed_two == 90) {
  227. battle_participants[0].status.flags.sleep = 1;
  228. battle_participants[1].status.flags.poison = 0;
  229. battle_participants[0].status.flags.paralysis = 0;
  230. speed_one = get_speed(0);
  231. speed_two = get_speed(1);
  232. if (!(speed_one == 75 && speed_two == 60)) {
  233. quick_feet_pass = false;
  234. }
  235. } else
  236. quick_feet_pass = false;
  237. if (quick_feet_pass) {
  238. debug_print(" \xFE\x1pass\xFE\x0\n");
  239. } else {
  240. debug_print("\xFE\x02 fail\xFE\x0\n");
  241. pass = false;
  242. }
  243. battle_participants[0].status.flags.sleep = 0;
  244. battle_participants[0].ability_id = 0;
  245. battle_participants[1].ability_id = 0;
  246. debug_wait_for_btn(8);
  247. debug_clean();
  248. //stress
  249. battle_participants[0].spd = 20;
  250. battle_participants[1].spd = 20;
  251. debug_printf("bank_one.spd: %d\n", battle_participants[0].spd);
  252. debug_printf("bank_two.spd: %d\n", battle_participants[1].spd);
  253. int count_one = 0;
  254. int count_two = 0;
  255. for (int i = 0; i < TEST_AMOUNT; ++i) {
  256. result = get_first_to_strike(0, 1, 0);
  257. if (result == ONE)
  258. count_one++;
  259. else
  260. count_two++;
  261. }
  262. debug_printf("tie stress test...\ncount \xFE\x1%d\xFE\x0 / ", count_one);
  263. debug_printf(" \xFE\x2%d\xFE\x0\n", count_two);
  264. int ratio_one = (count_one * 100) / TEST_AMOUNT;
  265. int ratio_two = (count_two * 100) / TEST_AMOUNT;
  266. debug_printf("%d%% / ", ratio_one);
  267. debug_printf("%d%%\n", ratio_two);
  268. debug_print("\nPRESS A TO CONTINUE...");
  269. debug_wait_for_btn(1);
  270. debug_clean();
  271. if (pass)
  272. debug_set_bg(0x3E0);
  273. else
  274. debug_set_bg(0x1F);
  275. debug_print("test complete\n(entering deadlock)");
  276. while (true) {
  277. }
  278. return;
  279. }