Advertisement
MonsterScripter

CodinGame_2023_08_26__18_21_49__thor.php

Aug 27th, 2023
1,182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.75 KB | None | 0 0
  1. <?php
  2.  
  3. $width = 40;
  4. $height = 18;
  5.  
  6. // $lightX: the X position of the light of power
  7. // $lightY: the Y position of the light of power
  8. // $initialTx: Thor's starting X position
  9. // $initialTy: Thor's starting Y position
  10. fscanf(STDIN, "%d %d %d %d", $lightX, $lightY, $initialTx, $initialTy);
  11.  
  12. // game loop
  13. while (TRUE)
  14. {
  15.     // $remainingTurns: The remaining amount of turns Thor can move. Do not remove this line.
  16.     fscanf(STDIN, "%d", $remainingTurns);
  17.     if ($lightY < $initialTy && $initialTy > 0) {
  18.         echo("N");
  19.         $initialTy--;
  20.     }
  21.     if ($lightY > $initialTy && $initialTy < $height) {
  22.         echo("S");
  23.         $initialTy++;
  24.     }
  25.     if ($lightX > $initialTx && $initialTx < $width) {
  26.         echo("E");
  27.         $initialTx++;
  28.     }
  29.     if ($lightX < $initialTx && $initialTx > 0) {
  30.         echo("W");
  31.         $initialTx--;  
  32.     }
  33.     echo("\n");
  34. }
  35.  
  36.  
  37. /*
  38.     Objectif
  39. Votre programme doit permettre à Thor de rejoindre l'éclair de puissance.
  40.     Règles
  41. Thor évolue sur une carte de 40 cases de large et 18 cases de hauteur. Notez que les coordonnées (X et Y) commencent en partant du haut ! Ainsi la case la plus en haut à gauche a pour coordonnées "X=0,Y=0" et celle située le plus en bas à droite a pour coordonnées "X=39,Y=17".
  42.  
  43. Au début du programme vous recevez :
  44. la variable lightX : la position X de l'éclair que Thor doit rejoindre.
  45. la variable lightY : la position Y de l'éclair que Thor doit rejoindre.
  46. la variable initialTX : la position X initiale de Thor.
  47. la variable initialTY : la position Y initiale de Thor.
  48. À la fin du tour de jeu, vous devez afficher la direction que Thor doit prendre parmi :
  49.  
  50. N (Nord)
  51. NE (Nord-Est)
  52. E (Est)
  53. SE (Sud-Est)
  54. S (Sud)
  55. SW (Sud-Ouest)
  56. W (Ouest)
  57. NW (Nord-Ouest)
  58.  
  59. Chaque déplacement fait bouger Thor de 1 case dans la direction choisie.
  60.  
  61. Conditions de victoire
  62. Vous gagnez lorsque Thor arrive sur l'éclair de puissance
  63.  
  64. Conditions de défaite
  65. Thor sort de la carte
  66.  
  67. Note
  68. N'oubliez pas d'exécuter les tests depuis la fenêtre "Jeu de tests".
  69. Attention : les tests fournis et les validateurs utilisés pour le calcul du score sont légèrement différents pour éviter les solutions codées en dur
  70.     Entrées du jeu
  71. Le programme doit d'abord lire les données d'initialisation depuis l'entrée standard, puis, dans une boucle infinie fournir sur la sortie standard les instructions de mouvement de Thor.
  72. Entrées d'initialisation
  73. Ligne 1 : 4 entiers lightX lightY initialTX initialTY. (lightX, lightY) indique la position de l'éclair. (initialTX, initialTY) indique la position initiale de Thor.
  74. Entrée pour un tour de jeu
  75. Ligne 1 : le nombre de déplacements restant pour permettre à Thor de rejoindre l'éclair de puissance remainingTurns. Vous pouvez ignorer cette valeur mais vous devez la lire.
  76. Sortie pour un tour de jeu
  77. Une ligne unique indiquant le mouvement à effectuer : N NE E SE S SW W ou NW
  78. Contraintes
  79. 0 ≤ lightX < 40
  80. 0 ≤ lightY < 18
  81. 0 ≤ initialTX < 40
  82. 0 ≤ initialTY < 18
  83. Temps de réponse pour un tour ≤ 100ms
  84.  
  85. */
  86.  
  87. /*
  88.  
  89. Sortie console
  90.  
  91. Informations de jeuAction (Sortie standard)Debug (Sortie d'erreurs)
  92. Informations :
  93. Thor's ready to go.
  94. Thor position = (0,0). Light position = (36,17). Energy = 36
  95. 00
  96. 36
  97. Sortie standard :
  98. SE
  99. Informations :
  100. Thor's moving...
  101. Thor position = (1,1). Light position = (36,17). Energy = 35
  102. 01
  103. 36
  104. Sortie standard :
  105. SE
  106. Informations :
  107. Thor's moving...
  108. Thor position = (2,2). Light position = (36,17). Energy = 34
  109. 02
  110. 36
  111. Sortie standard :
  112. SE
  113. Informations :
  114. Thor's moving...
  115. Thor position = (3,3). Light position = (36,17). Energy = 33
  116. 03
  117. 36
  118. Sortie standard :
  119. SE
  120. Informations :
  121. Thor's moving...
  122. Thor position = (4,4). Light position = (36,17). Energy = 32
  123. 04
  124. 36
  125. Sortie standard :
  126. SE
  127. Informations :
  128. Thor's moving...
  129. Thor position = (5,5). Light position = (36,17). Energy = 31
  130. 05
  131. 36
  132. Sortie standard :
  133. SE
  134. Informations :
  135. Thor's moving...
  136. Thor position = (6,6). Light position = (36,17). Energy = 30
  137. 06
  138. 36
  139. Sortie standard :
  140. SE
  141. Informations :
  142. Thor's moving...
  143. Thor position = (7,7). Light position = (36,17). Energy = 29
  144. 07
  145. 36
  146. Sortie standard :
  147. SE
  148. Informations :
  149. Thor's moving...
  150. Thor position = (8,8). Light position = (36,17). Energy = 28
  151. 08
  152. 36
  153. Sortie standard :
  154. SE
  155. Informations :
  156. Thor's moving...
  157. Thor position = (9,9). Light position = (36,17). Energy = 27
  158. 09
  159. 36
  160. Sortie standard :
  161. SE
  162. Informations :
  163. Thor's moving...
  164. Thor position = (10,10). Light position = (36,17). Energy = 26
  165. 10
  166. 36
  167. Sortie standard :
  168. SE
  169. Informations :
  170. Thor's moving...
  171. Thor position = (11,11). Light position = (36,17). Energy = 25
  172. 11
  173. 36
  174. Sortie standard :
  175. SE
  176. Informations :
  177. Thor's moving...
  178. Thor position = (12,12). Light position = (36,17). Energy = 24
  179. 12
  180. 36
  181. Sortie standard :
  182. SE
  183. Informations :
  184. Thor's moving...
  185. Thor position = (13,13). Light position = (36,17). Energy = 23
  186. 13
  187. 36
  188. Sortie standard :
  189. SE
  190. Informations :
  191. Thor's moving...
  192. Thor position = (14,14). Light position = (36,17). Energy = 22
  193. 14
  194. 36
  195. Sortie standard :
  196. SE
  197. Informations :
  198. Thor's moving...
  199. Thor position = (15,15). Light position = (36,17). Energy = 21
  200. 15
  201. 36
  202. Sortie standard :
  203. SE
  204. Informations :
  205. Thor's moving...
  206. Thor position = (16,16). Light position = (36,17). Energy = 20
  207. 16
  208. 36
  209. Sortie standard :
  210. SE
  211. Informations :
  212. Thor's moving...
  213. Thor position = (17,17). Light position = (36,17). Energy = 19
  214. 17
  215. 36
  216. Sortie standard :
  217. E
  218. Informations :
  219. Thor's moving...
  220. Thor position = (18,17). Light position = (36,17). Energy = 18
  221. 18
  222. 36
  223. Sortie standard :
  224. E
  225. Informations :
  226. Thor's moving...
  227. Thor position = (19,17). Light position = (36,17). Energy = 17
  228. 19
  229. 36
  230. Sortie standard :
  231. E
  232. Informations :
  233. Thor's moving...
  234. Thor position = (20,17). Light position = (36,17). Energy = 16
  235. 20
  236. 36
  237. Sortie standard :
  238. E
  239. Informations :
  240. Thor's moving...
  241. Thor position = (21,17). Light position = (36,17). Energy = 15
  242. 21
  243. 36
  244. Sortie standard :
  245. E
  246. Informations :
  247. Thor's moving...
  248. Thor position = (22,17). Light position = (36,17). Energy = 14
  249. 22
  250. 36
  251. Sortie standard :
  252. E
  253. Informations :
  254. Thor's moving...
  255. Thor position = (23,17). Light position = (36,17). Energy = 13
  256. 23
  257. 36
  258. Sortie standard :
  259. E
  260. Informations :
  261. Thor's moving...
  262. Thor position = (24,17). Light position = (36,17). Energy = 12
  263. 24
  264. 36
  265. Sortie standard :
  266. E
  267. Informations :
  268. Thor's moving...
  269. Thor position = (25,17). Light position = (36,17). Energy = 11
  270. 25
  271. 36
  272. Sortie standard :
  273. E
  274. Informations :
  275. Thor's moving...
  276. Thor position = (26,17). Light position = (36,17). Energy = 10
  277. 26
  278. 36
  279. Sortie standard :
  280. E
  281. Informations :
  282. Thor's moving...
  283. Thor position = (27,17). Light position = (36,17). Energy = 9
  284. 27
  285. 36
  286. Sortie standard :
  287. E
  288. Informations :
  289. Thor's moving...
  290. Thor position = (28,17). Light position = (36,17). Energy = 8
  291. 28
  292. 36
  293. Sortie standard :
  294. E
  295. Informations :
  296. Thor's moving...
  297. Thor position = (29,17). Light position = (36,17). Energy = 7
  298. 29
  299. 36
  300. Sortie standard :
  301. E
  302. Informations :
  303. Thor's moving...
  304. Thor position = (30,17). Light position = (36,17). Energy = 6
  305. 30
  306. 36
  307. Sortie standard :
  308. E
  309. Informations :
  310. Thor's moving...
  311. Thor position = (31,17). Light position = (36,17). Energy = 5
  312. 31
  313. 36
  314. Sortie standard :
  315. E
  316. Informations :
  317. Thor's moving...
  318. Thor position = (32,17). Light position = (36,17). Energy = 4
  319. 32
  320. 36
  321. Sortie standard :
  322. E
  323. Informations :
  324. Thor's moving...
  325. Thor position = (33,17). Light position = (36,17). Energy = 3
  326. 33
  327. 36
  328. Sortie standard :
  329. E
  330. Informations :
  331. Thor's moving...
  332. Thor position = (34,17). Light position = (36,17). Energy = 2
  333. 34
  334. 36
  335. Sortie standard :
  336. E
  337. Informations :
  338. Thor's moving...
  339. Thor position = (35,17). Light position = (36,17). Energy = 1
  340. 35
  341. 36
  342. Sortie standard :
  343. E
  344. Informations :
  345. Success: Thor reached the flash of power in time!
  346. Thor position = (36,17). Light position = (36,17). Energy = 0
  347.  
  348. **/
  349. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement