Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.59 KB | None | 0 0
  1. from API import Game
  2.  
  3.  
  4. class Strategy(Game):
  5. """
  6. FILL THIS METHOD OUT FOR YOUR BOT:
  7. Method to set unit initializations. Run at the beginning of a game, after assigning player numbers.
  8. We have given you a default implementation for this method.
  9. OUTPUT:
  10. An array of 3 dictionaries, where each dictionary details a unit. The dictionaries should have the following fields
  11. "health": An integer indicating the desired health for that unit
  12. "speed": An integer indicating the desired speed for that unit
  13. "unitId": An integer indicating the desired id for that unit. In this provided example, we assign Ids 1,2,3 if you are player1, or 4,5,6 if you are player2
  14. "attackPattern": a 7x7 2d integer list indicating the desired attack pattern for that unit
  15. "terrainPattern": a 7x7 2d boolean list indicating the desired terrain pattern for that unit.
  16. Note: terrainPattern and attackPattern should be indexed x,y. with (0,0) being the bottom left
  17. If player_id is 1, UnitIds for the bots should be 1,2,3. If player_id is 2, UnitIds should be 4,5,6
  18. """
  19. def get_setup(self):
  20. units = []
  21. # if you are player1, unitIds will be 1,2,3. If you are player2, they will be 4,5,6
  22. if self.player_id == 1:
  23. unit1 = {"health": 5, "speed": 5}
  24. unit1["attackPattern"] = [[0] * 7 for j in range(7)]
  25. unit1["unitId"] = 1
  26. unit1["attackPattern"][3][0] = 1
  27. unit1["attackPattern"][3][6] = 1
  28. unit1["terrainPattern"] = [[False]*7 for j in range(7)]
  29.  
  30. unit2 = {"health": 5, "speed": 5}
  31. unit2["attackPattern"] = [[0] * 7 for j in range(7)]
  32. unit2["unitId"] = 2
  33. unit2["attackPattern"][3][0] = 1
  34. unit2["attackPattern"][3][6] = 1
  35. unit2["terrainPattern"] = [[False]*7 for j in range(7)]
  36.  
  37. unit3 = {"health": 5, "speed": 5}
  38. unit3["attackPattern"] = [[0] * 7 for j in range(7)]
  39. unit3["unitId"] = 3
  40. unit3["attackPattern"][3][0] = 1
  41. unit3["attackPattern"][3][6] = 1
  42. unit3["terrainPattern"] = [[False]*7 for j in range(7)]
  43.  
  44. units = [unit1, unit2,unit3]
  45. else:
  46. unit4 = {"health": 5, "speed": 5}
  47. unit4["attackPattern"] = [[0] * 7 for j in range(7)]
  48. unit4["unitId"] = 4
  49. unit4["terrainPattern"] = [[False]*7 for j in range(7)]
  50.  
  51. unit5 = {"health": 5, "speed": 5}
  52. unit5["attackPattern"] = [[0] * 7 for j in range(7)]
  53. unit5["unitId"] = 5
  54. unit5["terrainPattern"] = [[False]*7 for j in range(7)]
  55.  
  56.  
  57. unit6 = {"health": 5, "speed": 5}
  58. unit6["attackPattern"] = [[0] * 7 for j in range(7)]
  59. unit6["terrainPattern"] = [[False]*7 for j in range(7)]
  60. unit6["unitId"] = 6
  61.  
  62. units = [unit4, unit5, unit6]
  63. return units
  64.  
  65. """
  66. FILL THIS METHOD OUT FOR YOUR BOT:
  67. Method to implement the competitors strategy in the next turn of the game.
  68. We have given you a default implementation here.
  69. OUTPUT:
  70. A list of 3 dictionaries, each of which indicates what to do on a given turn with that specific unit. Each dictionary should have the following keys:
  71. "unitId": The Id of the unit this dictionary will detail the action for
  72. "movement": an array of directions ("UP", "DOWN", "LEFT", or "RIGHT") details how you want that unit to move on this turn
  73. "attack": the direction in which to attack ("UP", "DOWN", "LEFT", or "RIGHT")
  74. "priority": The bots move one at a time, so give the priority which you want them to act in (1,2, or 3)
  75. """
  76. turn_count = 0
  77. def do_turn(self):
  78. my_units = self.get_my_units()
  79. if self.turn_count == 0:
  80. if self.player_id == 1:
  81. decision = [{"priority": 3, "movement": ["DOWN"]*my_units[0].speed, "attack":"STAY", "unitId": 1},
  82. {"priority": 2, "movement": ["DOWN"]*my_units[0].speed, "attack":"STAY", "unitId": 2},
  83. {"priority": 1, "movement": ["DOWN"]*my_units[0].speed, "attack":"STAY", "unitId": 3}]
  84. else:
  85. decision = [{"priority": 3, "movement": ["UP"]*my_units[0].speed, "attack":"STAY", "unitId": 4 },
  86. {"priority": 2, "movement": ["UP"]*my_units[0].speed, "attack":"STAY", "unitId": 5 },
  87. {"priority": 1, "movement": ["UP"]*my_units[0].speed, "attack":"STAY", "unitId": 6}]
  88. elif self.turn_count == 1:
  89. if self.player_id == 1:
  90. decision = [{"priority": 3, "movement": ["RIGHT"]*3 + ["STAY"]*2, "attack":"STAY", "unitId": 1},
  91. {"priority": 2, "movement": ["RIGHT"]*3 + ["STAY"]*2, "attack":"STAY", "unitId": 2},
  92. {"priority": 1, "movement": ["RIGHT"]*5, "attack":"STAY", "unitId": 3}]
  93. else:
  94. decision = [{"priority": 3, "movement": ["LEFT"]*3 + ["STAY"]*2, "attack":"STAY", "unitId": 4 },
  95. {"priority": 2, "movement": ["LEFT"]*3 + ["STAY"]*2, "attack":"STAY", "unitId": 5 },
  96. {"priority": 1, "movement": ["LEFT"]*5, "attack":"STAY", "unitId": 6}]
  97. else:
  98. decision = [{
  99. "priority": i+1,
  100. "movement": ["STAY"]*my_units[i].speed,
  101. "attack": "UP",
  102. "unitId": my_units[i].id
  103. } for i in range(len(my_units))]
  104. self.turn_count += 1
  105. return decision
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement