Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.12 KB | None | 0 0
  1. // dracula.c
  2. // Implementation of your "Fury of Dracula" Dracula AI
  3.  
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. #include <time.h>
  7. #include "Game.h"
  8. #include "DracView.h"
  9. #include "Map.h"
  10.  
  11. static void dracViewPrint (DracView gameView);
  12. LocationID bruteForce(DracView currentView, Map g);
  13. void proximity(int *distance, DracView currentView, LocationID dracula);
  14.  
  15.  
  16. void decideDraculaMove(DracView gameState)
  17. {
  18. int location = 0;
  19.  
  20. Map g = newMap ();
  21.  
  22. int nodes = 0;
  23.  
  24. nodes = numV (g);
  25.  
  26. printf ("The value of nodes is %d\n", nodes);
  27.  
  28. location = bruteForce (gameState, g);
  29.  
  30. registerBestPlay (idToAbbrev(location),"");
  31.  
  32. printf ("The value of location is %d\n", location);
  33. }
  34. /*This assumes the following
  35.  
  36. the following insert files are included
  37.  
  38. #include <dracView.h>
  39. #include <gameView.h>
  40. #include <map.h>
  41. */
  42.  
  43. LocationID bruteForce(DracView currentView, Map g){
  44. LocationID nextMove = 0;
  45. int trail[6];
  46.  
  47. int i =0 ;
  48.  
  49. int *array;
  50. int *numLocations;
  51. int k = 50;
  52.  
  53.  
  54. numLocations = &k;
  55.  
  56.  
  57. dracViewPrint (currentView);
  58.  
  59. giveMeTheTrail(currentView, PLAYER_DRACULA, trail);
  60.  
  61. int connections[NUM_MAP_LOCATIONS];
  62.  
  63. //Sets all of the values in connections to -1
  64. for (i = 0; i < NUM_MAP_LOCATIONS; i++) connections[i] = -1;
  65.  
  66. //Where can Dracula travel by road
  67. array = whereCanIgo(currentView, numLocations, 1, 0);
  68. int l = 0;
  69. for (l = 0; l < NUM_MAP_LOCATIONS; l++) {
  70. connections [l] = array[l];
  71. printf ("%d ", connections [l]);
  72. }
  73.  
  74. printf ("\n");
  75.  
  76. int tempDistance = 0;
  77. int compareDistance = 50;
  78.  
  79. int isLegalMove = 1;
  80.  
  81.  
  82.  
  83. //Finds where Dracula is
  84. LocationID hunter1 = whereIs(currentView, PLAYER_LORD_GODALMING);
  85.  
  86. int path[20];
  87. int trans[20];
  88.  
  89. int j;
  90.  
  91. i = 0;
  92. if(connections[0] != -1){
  93. while(connections[i] != -1){
  94. //Finds the shortest distance and then puts it on.
  95. tempDistance = shortestPath(g, connections[i], hunter1, path, trans);
  96. if(compareDistance > tempDistance){
  97. for(j = 0; j <= 5; j++){
  98. if (trail[j] == connections[i]) {
  99. isLegalMove = 0;
  100. }
  101. }
  102. if(isLegalMove == 1){//If its a legal move change the following.
  103. compareDistance = tempDistance;
  104. nextMove = connections[i];
  105. } else {
  106. isLegalMove = 1; // Resets the isLegalMove flag
  107. }
  108. }
  109. i++;
  110. }
  111. }
  112.  
  113. printf ("The value of next move is %d\n", nextMove);
  114.  
  115. return nextMove;
  116.  
  117. }
  118.  
  119. void proximity(int *distance, DracView currentView, LocationID dracula){
  120. Map g = newMap();
  121.  
  122. LocationID hunter1 = whereIs(currentView, PLAYER_LORD_GODALMING);
  123. LocationID hunter2 = whereIs(currentView, PLAYER_DR_SEWARD);
  124. LocationID hunter3 = whereIs(currentView, PLAYER_VAN_HELSING);
  125. LocationID hunter4 = whereIs(currentView, PLAYER_MINA_HARKER);
  126.  
  127. int path[20];
  128. int trans[20];
  129.  
  130. //Determines how many moves a hunter is from dracula.
  131. distance[0] = shortestPath(g, dracula, hunter1, path, trans);
  132. distance[1] = shortestPath(g, dracula, hunter2, path, trans);
  133. distance[2] = shortestPath(g, dracula, hunter3, path, trans);
  134. distance[3] = shortestPath(g, dracula, hunter4, path, trans);
  135. }
  136.  
  137.  
  138. static void dracViewPrint (DracView gameView) {
  139. printf ("\n================= GAME VIEW VALUES ====================\n");
  140. printf ("The current round is %d\n", giveMeTheRound (gameView));
  141. printf ("The current score is %d\n", giveMeTheScore(gameView));
  142. printf ("Lord Godalming HP is %d\n", howHealthyIs (gameView, PLAYER_LORD_GODALMING));
  143. printf ("Dr Seward HP is %d\n", howHealthyIs (gameView, PLAYER_DR_SEWARD));
  144. printf ("Van Helsing HP is %d\n", howHealthyIs (gameView, PLAYER_VAN_HELSING));
  145. printf ("Mina Harker HP is %d\n", howHealthyIs (gameView, PLAYER_MINA_HARKER));
  146. printf ("Dracula HP is %d\n\n", howHealthyIs (gameView, PLAYER_DRACULA));
  147.  
  148. int trail [6];
  149.  
  150. int i = 0;
  151. printf ("Lord Godalming's trail is: \n");
  152.  
  153. giveMeTheTrail (gameView, PLAYER_LORD_GODALMING, trail);
  154.  
  155. for (i = 0; i < TRAIL_SIZE; i++) {
  156. printf ("%d ", trail[i]);
  157. }
  158. printf ("\n\n");
  159.  
  160. printf ("Dr Seward's trail is: \n");
  161.  
  162. giveMeTheTrail (gameView, PLAYER_DR_SEWARD, trail);
  163.  
  164. for (i = 0; i < TRAIL_SIZE; i++) {
  165. printf ("%d ", trail[i]);
  166. }
  167. printf ("\n\n");
  168.  
  169. printf ("Van Helsing's trail is: \n");
  170.  
  171. giveMeTheTrail (gameView, PLAYER_VAN_HELSING, trail);
  172.  
  173. for (i = 0; i < TRAIL_SIZE; i++) {
  174. printf ("%d ", trail[i]);
  175. }
  176. printf ("\n\n"); printf ("Mina Harker's trail is: \n");
  177.  
  178. giveMeTheTrail (gameView, PLAYER_MINA_HARKER, trail);
  179.  
  180. for (i = 0; i < TRAIL_SIZE; i++) {
  181. printf ("%d ", trail[i]);
  182. }
  183. printf ("\n\n"); printf ("Dracula's trail is: \n");
  184.  
  185. giveMeTheTrail (gameView, PLAYER_DRACULA, trail);
  186.  
  187. for (i = 0; i < TRAIL_SIZE; i++) {
  188. printf ("%d ", trail[i]);
  189. }
  190. printf ("\n\n");
  191.  
  192.  
  193.  
  194. printf ("=======================================================\n\n");
  195.  
  196. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement