Advertisement
Guest User

Untitled

a guest
Dec 5th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.64 KB | None | 0 0
  1. #include "Player.hh"
  2.  
  3.  
  4. /**
  5. * Write the name of your player and save this file
  6. * with the same name and .cc extension.
  7. */
  8. #define PLAYER_NAME Eomer
  9.  
  10.  
  11.  
  12. struct PLAYER_NAME : public Player {
  13.  
  14. /**
  15. * Factory: returns a new instance of this class.
  16. * Do not modify this function.
  17. */
  18. static Player* factory () {
  19. return new PLAYER_NAME;
  20. }
  21. typedef vector<bool> Row;
  22. typedef vector<Row> Matriu;
  23. typedef vector<int> VE;
  24. struct Pos_info{
  25. Dir direction;
  26. Pos position;
  27. };
  28.  
  29. /**
  30. * Types and attributes for your player can be defined here.
  31. */
  32. bool me_gusta_farmer(Pos pos_actual){
  33. if(cell(pos_actual).owner != 0) return puedo_ir_farmer(pos_actual); //No es mia
  34. else return false;
  35. }
  36.  
  37. bool me_gusta_knight(Pos pos_actual){
  38. if((unit(cell(pos_actual)).type == Knight) or (unit(cell(pos_actual)).type == Farmer)) return puedo_ir_knight(pos_actual);
  39. else return false;
  40. }
  41. bool puedo_ir_farmer(Pos pos_destino){
  42. if((pos_destino.i < 37 and pos_destino.j < 37) and (pos_destino.i > 0 and pos_destino.j > 0)){
  43. if(cell(pos_destino).haunted or cell(pos_destino).type == Wall) return false; //embrujada o muro
  44. else if(cell(pos_destino).id != -1) return false; //alguien dentro
  45. return true;
  46. }
  47. return false;
  48. }
  49.  
  50. bool puedo_ir_knight(Pos pos_destino){
  51. if((pos_destino.i < 37 and pos_destino.j < 37) and (pos_destino.i > 0 and pos_destino.j > 0)){
  52. if(cell(pos_destino).haunted or cell(pos_destino).type == Wall) return false; //embrujada o muro
  53. else if(unit(cell(pos_destino).id).player != 0) return false; //Quizas modificar
  54. return true;
  55. }
  56. return false;
  57.  
  58. }
  59.  
  60.  
  61. void farmer(int id){
  62. bool trobat = false;
  63. Pos_info pos_actual;
  64. pos_actual.position = unit(id).pos;
  65. pos_actual.direction = None;
  66.  
  67. Matriu posicions_visit(37, Row(37,false));
  68. queue<Pos_info> alvaro; //Elementos que quedan por visitar
  69. alvaro.push(pos_actual);
  70.  
  71. while (not trobat and not alvaro.empty()){
  72. Pos aux = alvaro.front().position;
  73. Dir auxd = alvaro.front().direction;
  74. alvaro.pop();
  75. if (not posicions_visit[aux.i][aux.j]){
  76. posicions_visit[aux.i][aux.j] = true;
  77. if (me_gusta_farmer(aux)){
  78. Dir dire = auxd;
  79. trobat = true;
  80. }
  81. else{
  82. if(puedo_ir_farmer(Pos(aux.i, aux.j+1)) ){
  83. pos_actual pushaux;
  84. pushaux.position = Pos(aux.i, aux.j+1);
  85. pushaux.direction = auxd;
  86. if (pushaux.direction == None) pushaux.direction = Right;
  87. alvaro.push(pushaux);
  88. }
  89.  
  90. if(puedo_ir_farmer(Pos(aux.i+1, aux.j))){
  91. pos_actual pushaux;
  92. pushaux.position = Pos(aux.i+1, aux.j);
  93. pushaux.direction = auxd;
  94. if (pushaux.direction == None) pushaux.direction = Right;
  95. alvaro.push(pushaux);
  96. }
  97. if(puedo_ir_farmer(Pos(aux.i, aux.j-1))){
  98. pos_actual pushaux;
  99. pushaux.position = Pos(aux.i, aux.j-1);
  100. pushaux.direction = auxd;
  101. if (pushaux.direction == None) pushaux.direction = Right;
  102. alvaro.push(pushaux);
  103. }
  104. if(puedo_ir_farmer(Pos(aux.i-1, aux.j))){
  105. pos_actual pushaux;
  106. pushaux.position = Pos(aux.i-1, aux.j);
  107. pushaux.direction = auxd;
  108. if (pushaux.direction == None) pushaux.direction = Right;
  109. alvaro.push(pushaux);
  110. }
  111. }
  112. }
  113. } command(id, dire);//OCULTA
  114. }
  115.  
  116. void witch(int id){ //FALTA
  117.  
  118. }
  119. void move_knight(int id, Pos pos_destino){
  120. int rando = random(0,1);
  121. Pos pos_actual = unit(id).pos;
  122. if(pos_actual.i == pos_destino.i){
  123. if(pos_actual.j == pos_destino.j) command(id,None);
  124. if(pos_actual.j < pos_destino.j){
  125. if(puedo_ir_farmer(Pos(pos_actual.i,pos_actual.j+1))) command(id, Right);
  126. else if(puedo_ir_farmer(Pos(pos_actual.i+1,pos_actual.j))) command(id,Bottom);
  127. else if(puedo_ir_farmer(Pos(pos_actual.i-1,pos_actual.j))) command(id,Top);
  128. else if(puedo_ir_farmer(Pos(pos_actual.i,pos_actual.j-1))) command(id,Left);
  129. else command(id,None);
  130. }
  131. else if(pos_actual.j > pos_destino.j){
  132. if(puedo_ir_farmer(Pos(pos_actual.i,pos_actual.j-1))) command(id,Left);
  133. else if(puedo_ir_farmer(Pos(pos_actual.i+1,pos_actual.j))) command(id,Bottom);
  134. else if(puedo_ir_farmer(Pos(pos_actual.i-1,pos_actual.j))) command(id,Top);
  135. else if(puedo_ir_farmer(Pos(pos_actual.i,pos_actual.j+1))) command(id, Right);
  136. else command(id,None);
  137. }
  138. }
  139. else if(pos_actual.i > pos_destino.i){
  140. if(pos_actual.j == pos_destino.j) command(id,Top);
  141. else if(pos_actual.j < pos_destino.j) command(id, Right);
  142. else if(pos_actual.j > pos_destino.j) command(id, Left);
  143. }
  144. else if(pos_actual.i < pos_destino.i){
  145. if(pos_actual.j == pos_destino.j) command(id,Bottom);
  146. else if(pos_actual.j < pos_destino.j) command(id, Right);
  147. else if(pos_actual.j > pos_destino.j) command(id, Left);
  148. }
  149. }
  150. void knight(int id){
  151. bool trobat = false;
  152. Pos pos_actual = unit(id).pos;
  153. Matriu posicions_visit(37, Row(37,false));
  154. queue<Pos> alvaro; //Elementos que quedan por visitar
  155. alvaro.push(pos_actual);
  156. while (not trobat and not alvaro.empty()){
  157. Pos aux = alvaro.front();
  158. alvaro.pop();
  159. if (not posicions_visit[aux.i][aux.j]){
  160. posicions_visit[aux.i][aux.j] = true;
  161. if (me_gusta_knight(aux)){
  162. move_knight(id,aux);
  163. trobat = true;
  164. }
  165. else{
  166. if(puedo_ir_knight(Pos(aux.i+1, aux.j+1))) alvaro.push(Pos(aux.i+1, aux.j+1)); //Abajo derecha
  167. if(puedo_ir_knight(Pos(aux.i, aux.j+1))) alvaro.push(Pos(aux.i, aux.j+1)); //Derecha
  168. if(puedo_ir_knight(Pos(aux.i+1, aux.j))) alvaro.push(Pos(aux.i+1, aux.j)); //Abajo
  169. if(puedo_ir_knight(Pos(aux.i-1, aux.j+1))) alvaro.push(Pos(aux.i-1, aux.j+1)); //Arriba derecha
  170. if(puedo_ir_knight(Pos(aux.i+1, aux.j-1))) alvaro.push(Pos(aux.i+1, aux.j-1)); //Abajo izquierda
  171. if(puedo_ir_knight(Pos(aux.i, aux.j-1))) alvaro.push(Pos(aux.i, aux.j-1)); //Izquierda
  172. if(puedo_ir_knight(Pos(aux.i-1, aux.j))) alvaro.push(Pos(aux.i-1, aux.j)); //Arriba
  173. if(puedo_ir_knight(Pos(aux.i-1, aux.j-1))) alvaro.push(Pos(aux.i-1, aux.j-1)); //Arriba izquierda
  174. }
  175. }
  176. }
  177. }
  178.  
  179. /**
  180. * Play method, invoked once per each round.
  181. */
  182. virtual void play () {
  183. VE f = farmers(0);
  184. VE k = knights(0);
  185. VE w = witches(0);
  186. for (int id : f) {
  187. //cout << "Soy el farmer con id: " << id << endl;
  188. farmer(id); //movimiento farmer
  189. }
  190. for (int id : k) {
  191. //cout << "Soy el farmer con id: " << id << endl;
  192. knight(id); //movimiento knight
  193. }
  194. for (int id : w) {
  195. //cout << "Soy el farmer con id: " << id << endl;
  196. witch(id); //movimiento witches
  197. }
  198. }
  199.  
  200. };
  201.  
  202.  
  203. /**
  204. * Do not modify the following line.
  205. */
  206. RegisterPlayer(PLAYER_NAME);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement