Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from API import Game
- class Strategy(Game):
- """
- FILL THIS METHOD OUT FOR YOUR BOT:
- Method to set unit initializations. Run at the beginning of a game, after assigning player numbers.
- We have given you a default implementation for this method.
- OUTPUT:
- An array of 3 dictionaries, where each dictionary details a unit. The dictionaries should have the following fields
- "health": An integer indicating the desired health for that unit
- "speed": An integer indicating the desired speed for that unit
- "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
- "attackPattern": a 7x7 2d integer list indicating the desired attack pattern for that unit
- "terrainPattern": a 7x7 2d boolean list indicating the desired terrain pattern for that unit.
- Note: terrainPattern and attackPattern should be indexed x,y. with (0,0) being the bottom left
- 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
- """
- def get_setup(self):
- units = []
- # if you are player1, unitIds will be 1,2,3. If you are player2, they will be 4,5,6
- if self.player_id == 1:
- unit1 = {"health": 5, "speed": 5}
- unit1["attackPattern"] = [[0] * 7 for j in range(7)]
- unit1["unitId"] = 1
- unit1["attackPattern"][3][0] = 1
- unit1["attackPattern"][3][6] = 1
- unit1["terrainPattern"] = [[False]*7 for j in range(7)]
- unit2 = {"health": 5, "speed": 5}
- unit2["attackPattern"] = [[0] * 7 for j in range(7)]
- unit2["unitId"] = 2
- unit2["attackPattern"][3][0] = 1
- unit2["attackPattern"][3][6] = 1
- unit2["terrainPattern"] = [[False]*7 for j in range(7)]
- unit3 = {"health": 5, "speed": 5}
- unit3["attackPattern"] = [[0] * 7 for j in range(7)]
- unit3["unitId"] = 3
- unit3["attackPattern"][3][0] = 1
- unit3["attackPattern"][3][6] = 1
- unit3["terrainPattern"] = [[False]*7 for j in range(7)]
- units = [unit1, unit2,unit3]
- else:
- unit4 = {"health": 5, "speed": 5}
- unit4["attackPattern"] = [[0] * 7 for j in range(7)]
- unit4["unitId"] = 4
- unit4["terrainPattern"] = [[False]*7 for j in range(7)]
- unit5 = {"health": 5, "speed": 5}
- unit5["attackPattern"] = [[0] * 7 for j in range(7)]
- unit5["unitId"] = 5
- unit5["terrainPattern"] = [[False]*7 for j in range(7)]
- unit6 = {"health": 5, "speed": 5}
- unit6["attackPattern"] = [[0] * 7 for j in range(7)]
- unit6["terrainPattern"] = [[False]*7 for j in range(7)]
- unit6["unitId"] = 6
- units = [unit4, unit5, unit6]
- return units
- """
- FILL THIS METHOD OUT FOR YOUR BOT:
- Method to implement the competitors strategy in the next turn of the game.
- We have given you a default implementation here.
- OUTPUT:
- 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:
- "unitId": The Id of the unit this dictionary will detail the action for
- "movement": an array of directions ("UP", "DOWN", "LEFT", or "RIGHT") details how you want that unit to move on this turn
- "attack": the direction in which to attack ("UP", "DOWN", "LEFT", or "RIGHT")
- "priority": The bots move one at a time, so give the priority which you want them to act in (1,2, or 3)
- """
- turn_count = 0
- def do_turn(self):
- my_units = self.get_my_units()
- if self.turn_count == 0:
- if self.player_id == 1:
- decision = [{"priority": 3, "movement": ["DOWN"]*my_units[0].speed, "attack":"STAY", "unitId": 1},
- {"priority": 2, "movement": ["DOWN"]*my_units[0].speed, "attack":"STAY", "unitId": 2},
- {"priority": 1, "movement": ["DOWN"]*my_units[0].speed, "attack":"STAY", "unitId": 3}]
- else:
- decision = [{"priority": 3, "movement": ["UP"]*my_units[0].speed, "attack":"STAY", "unitId": 4 },
- {"priority": 2, "movement": ["UP"]*my_units[0].speed, "attack":"STAY", "unitId": 5 },
- {"priority": 1, "movement": ["UP"]*my_units[0].speed, "attack":"STAY", "unitId": 6}]
- elif self.turn_count == 1:
- if self.player_id == 1:
- decision = [{"priority": 3, "movement": ["RIGHT"]*3 + ["STAY"]*2, "attack":"STAY", "unitId": 1},
- {"priority": 2, "movement": ["RIGHT"]*3 + ["STAY"]*2, "attack":"STAY", "unitId": 2},
- {"priority": 1, "movement": ["RIGHT"]*5, "attack":"STAY", "unitId": 3}]
- else:
- decision = [{"priority": 3, "movement": ["LEFT"]*3 + ["STAY"]*2, "attack":"STAY", "unitId": 4 },
- {"priority": 2, "movement": ["LEFT"]*3 + ["STAY"]*2, "attack":"STAY", "unitId": 5 },
- {"priority": 1, "movement": ["LEFT"]*5, "attack":"STAY", "unitId": 6}]
- else:
- decision = [{
- "priority": i+1,
- "movement": ["STAY"]*my_units[i].speed,
- "attack": "UP",
- "unitId": my_units[i].id
- } for i in range(len(my_units))]
- self.turn_count += 1
- return decision
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement