Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. struct Tile
  9. {
  10. bool up;
  11. bool right;
  12. bool down;
  13. bool left;
  14. int x; // just for save points, the save points cordinate
  15. int y; // just for save points, the save points cordinate
  16. int k; // just for save points, how many steps at that save point
  17. };
  18.  
  19. struct Player
  20. {
  21. int num_player_quests;
  22. int x;
  23. int y;
  24. Tile player_tile;
  25.  
  26. };
  27.  
  28. struct Item
  29. {
  30. string item_name;
  31. int x;
  32. int y;
  33. int player_id;
  34. };
  35.  
  36. struct Quest
  37. {
  38. string quest_name;
  39. int player_id;
  40. };
  41.  
  42. bool can_up(Tile me, vector<vector<Tile> > line) // can it go one step up
  43. {
  44. if(me.y == 0)return false;
  45. else if(line[me.x][me.y].up == true && line[me.x][me.y - 1].down == true)return true;
  46. else return false;
  47. }
  48.  
  49. bool can_right(Tile me, vector<vector<Tile> > line) // can it go one step right
  50. {
  51. if(me.x == 6)return false;
  52. else if(line[me.x][me.y].right == true && line[me.x + 1][me.y].left == true)return true;
  53. else return false;
  54. }
  55.  
  56. bool can_down(Tile me, vector<vector<Tile> > line) // can it go one step down
  57. {
  58. if(me.y == 6)return false;
  59. else if(line[me.x][me.y].down == true && line[me.x][me.y + 1].up == true)return true;
  60. else return false;
  61. }
  62.  
  63. bool can_left(Tile me, vector<vector<Tile> > line) // can it go one step left
  64. {
  65. if(me.x == 0)return false;
  66. else if(line[me.x][me.y].left == true && line[me.x - 1][me.y].right == true)return true;
  67. else return false;
  68. }
  69.  
  70.  
  71. bool check_if_available_path(vector<vector<Tile> > line, Item item, Player me, vector<Tile> &save_points)
  72. {
  73.  
  74.  
  75.  
  76. int k = 0; // number of steps, limit is 20
  77. int save_index = -1; // which save point is which
  78. Tile copy_me; // the one that moves around to look if there is an available path
  79.  
  80. int control_k = 0; // how many steps with all coming to save_points around 40 (for testing)
  81.  
  82. copy_me.x = me.x;
  83. copy_me.y = me.y;
  84.  
  85. item.x = item.x - 1;
  86. item.y = item.y - 1;
  87.  
  88. if(can_up(copy_me, line) == false && can_right(copy_me, line) == false && can_down(copy_me, line) == false && can_left(copy_me, line) == false)return false;
  89.  
  90. while((copy_me.x != item.x || copy_me.y != item.y) && k <= 20 && control_k <= 40)
  91. {
  92. //cerr << "copy_me x " << copy_me.x << " item x " << item.x <<endl << "copy_me y " << copy_me.y << " item y " << item.y <<endl;
  93.  
  94. if(copy_me.x == item.x && copy_me.y == item.y)return true;
  95.  
  96. if(can_up(copy_me, line) == true)
  97. {
  98. if(line[copy_me.x][copy_me.y].up + line[copy_me.x][copy_me.y].right + line[copy_me.x][copy_me.y].down + line[copy_me.x][copy_me.y].left > 1)
  99. {
  100. Tile save;
  101. save.up = line[copy_me.x][copy_me.y].up; save.right = line[copy_me.x][copy_me.y].right; save.down = line[copy_me.x][copy_me.y].down; save.left = line[copy_me.x][copy_me.y].left;
  102. save.x = copy_me.x; save.y = copy_me.y;
  103. save.k = k;
  104. save_points.push_back(save);
  105. save_index++;
  106. }
  107. line[copy_me.x][copy_me.y].up = false;
  108. save_points[save_index].up = false;
  109. copy_me.x = copy_me.x;
  110. copy_me.y = copy_me.y - 1;
  111. k++;
  112. //control_k++;
  113. line[copy_me.x][copy_me.y].down = false;
  114. }
  115. else if(can_right(copy_me, line) == true)
  116. {
  117. if(line[copy_me.x][copy_me.y].up + line[copy_me.x][copy_me.y].right + line[copy_me.x][copy_me.y].down + line[copy_me.x][copy_me.y].left > 1)
  118. {
  119. Tile save;
  120. save.up = line[copy_me.x][copy_me.y].up; save.right = line[copy_me.x][copy_me.y].right; save.down = line[copy_me.x][copy_me.y].down; save.left = line[copy_me.x][copy_me.y].left;
  121. save.x = copy_me.x; save.y = copy_me.y;
  122. save.k = k;
  123. save_points.push_back(save);
  124. save_index++;
  125. }
  126. line[copy_me.x][copy_me.y].right = false;
  127. save_points[save_index].right = false;
  128. copy_me.x = copy_me.x + 1;
  129. copy_me. y = copy_me.y;
  130. k++;
  131. //control_k++;
  132. line[copy_me.x][copy_me.y].left = false;
  133. }
  134. else if(can_down(copy_me, line) == true)
  135. {
  136. if(line[copy_me.x][copy_me.y].up + line[copy_me.x][copy_me.y].right + line[copy_me.x][copy_me.y].down + line[copy_me.x][copy_me.y].left > 1)
  137. {
  138. Tile save;
  139. save.up = line[copy_me.x][copy_me.y].up; save.right = line[copy_me.x][copy_me.y].right; save.down = line[copy_me.x][copy_me.y].down; save.left = line[copy_me.x][copy_me.y].left;
  140. save.x = copy_me.x; save.y = copy_me.y;
  141. save.k = k;
  142. save_points.push_back(save);
  143. save_index++;
  144. }
  145. line[copy_me.x][copy_me.y].down = false;
  146. save_points[save_index].down = false;
  147. copy_me.x = copy_me.x + 1;
  148. copy_me.y = copy_me.y;
  149. k++;
  150. //control_k++;
  151. line[copy_me.x][copy_me.y].up = false;
  152. }
  153. else if(can_left(copy_me, line) == true)
  154. {
  155. if(line[copy_me.x][copy_me.y].up + line[copy_me.x][copy_me.y].right + line[copy_me.x][copy_me.y].down + line[copy_me.x][copy_me.y].left > 1)
  156. {
  157. Tile save;
  158. save.up = line[copy_me.x][copy_me.y].up; save.right = line[copy_me.x][copy_me.y].right; save.down = line[copy_me.x][copy_me.y].down; save.left = line[copy_me.x][copy_me.y].left;
  159. save.x = copy_me.x; save.y = copy_me.y;
  160. save.k = k;
  161. save_points.push_back(save);
  162. save_index++;
  163. }
  164. line[copy_me.x][copy_me.y].left = false;
  165. save_points[save_index].left = false;
  166. copy_me.x = copy_me.x + 1;
  167. copy_me.y = copy_me.y;
  168. k++;
  169. //control_k++;
  170. line[copy_me.x][copy_me.y].right = false;
  171. }
  172. else if(can_up(copy_me, line) == false && can_right(copy_me, line) == false && can_down(copy_me, line) == false && can_left(copy_me, line) == false)
  173. {
  174.  
  175. if(save_points.size() > 0)
  176. {
  177. copy_me = save_points[save_points.size() - 1];
  178. }
  179. k = save_points[save_points.size() - 1].k;
  180. if(save_points[save_points.size()-1].up + save_points[save_points.size()-1].right + save_points[save_points.size()-1].down + save_points[save_points.size()-1].left <= 1)
  181. {
  182. save_points.erase(save_points.end() - 1);
  183. }
  184. }
  185. control_k++;
  186. //cerr << control_k << endl;
  187. }
  188. //cerr << "control_k : " << control_k << " k :" << k << endl;
  189. if(control_k >= 40 || k >= 20)return false;
  190. else return true;
  191.  
  192.  
  193. }
  194.  
  195. int main()
  196. {
  197.  
  198. // game loop
  199. while (1)
  200. {
  201.  
  202. vector<vector<Tile> > line;
  203.  
  204. vector<Tile> save_points;
  205.  
  206. Player me;
  207. Player enemy;
  208.  
  209. vector<Item> items;
  210.  
  211. vector<Quest> quests;
  212.  
  213. line.resize(7);
  214.  
  215. int turn_type;
  216. cin >> turn_type; cin.ignore();
  217. //cerr << turn_type << endl;
  218.  
  219. for (int i = 0; i < line.size(); i++) // ivedu duomenis zaidimo lentos
  220. {
  221. for (int j = 0; j < 7; j++)
  222. {
  223. string tile;
  224. cin >> tile; cin.ignore();
  225. line[i].push_back({tile[j] - '0', tile[1] - '0', tile[2] - '0', tile[3] - '0'});
  226. //cerr << line[i][j].up << line[i][j].right << line[i][j].down << line[i][j].left << " ";
  227. //cerr << tile << " ";
  228. }
  229. //cerr << endl;
  230. }
  231.  
  232. string a;string b;Tile A;Tile B;// cancer tik duomenu uzsaugojimui
  233.  
  234. cin >> me.num_player_quests >> me.x >> me.y >> a; cin.ignore(); // ivedu duomenis apie save
  235. A.up = a[0] - '0'; A.right = a[1] - '0'; A.down = a[2] - '0'; A.left = a[3] - '0';
  236. me.player_tile = A;
  237.  
  238. cin >> enemy.num_player_quests >> enemy.x >> enemy.y >> b; cin.ignore(); // ivedu duomenis apie priesa
  239. B.up = b[0] - '0'; B.right = b[1] - '0'; B.down = b[2] - '0'; B.left = b[3] - '0';
  240. enemy.player_tile = B;
  241. //cerr << me.num_player_quests << " " << me.x << " " << me.y << " " << me.player_tile.up << endl;
  242.  
  243. int num_of_items;
  244. cin >> num_of_items; cin.ignore();// the total number of items available on board and on player tiles
  245.  
  246. for (int i = 0; i < num_of_items; i++)
  247. {
  248. Item A;
  249. cin >> A.item_name >> A.x >> A.y >> A.player_id; cin.ignore();
  250. items.push_back(A);
  251. }
  252. int num_of_quests;
  253. cin >> num_of_quests; cin.ignore(); // the total number of revealed quests for both players
  254. for (int i = 0; i < num_of_quests; i++)
  255. {
  256. Quest A;
  257. cin >> A.quest_name >> A.player_id; cin.ignore();
  258. quests.push_back(A);
  259. }
  260.  
  261. if(items.size() > 0)
  262. {
  263. cerr << check_if_available_path(line, items[0], me , save_points);
  264. }
  265. if(turn_type == 0) // push
  266. {
  267. cout << "PUSH 1 RIGHT" << endl; // PUSH <id> <direction> | MOVE <direction> | PASS
  268. }
  269. if(turn_type == 1) // move
  270. {
  271. cout << "MOVE RIGHT DOWN RIGHT DOWN UP RIGHT LEFT UP RIGHT DOWN LEFT" << endl;
  272.  
  273. //cout << "PASS";
  274. }
  275. //cerr << me.player_tile.up << me.player_tile.right << me.player_tile.down << me.player_tile.left;
  276. }
  277.  
  278.  
  279. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement