本文整理汇总了Python中Map.set_symbol方法的典型用法代码示例。如果您正苦于以下问题:Python Map.set_symbol方法的具体用法?Python Map.set_symbol怎么用?Python Map.set_symbol使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Map
的用法示例。
在下文中一共展示了Map.set_symbol方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import Map [as 别名]
# 或者: from Map import set_symbol [as 别名]
class Arena:
""" Handles the game simulation. """
def __init__(self, map_file_name, bot_files):
""" Initializes the map and bikes. """
self.map = Map(map_file_name)
init_posns = self._generate_init_posns(self.map)
self.bikes = [
Bike(BIKE_1_SYMBOL, init_posns[0], bot_files[0]),
Bike(BIKE_2_SYMBOL, init_posns[1], bot_files[1]),
]
self.map.set_symbol(self.bikes[0].curr_posn, self.bikes[0].symbol)
self.map.set_symbol(self.bikes[1].curr_posn, self.bikes[1].symbol)
self.game_over = False
self.turn_count = 0
# Send the initialization info to the bots.
for bike in self.bikes:
bike.bot.add_to_info_to_send(bike.symbol)
if bike.symbol == BIKE_1_SYMBOL:
enemy_symbol = BIKE_2_SYMBOL
bot_num = 0
else:
enemy_symbol = BIKE_1_SYMBOL
bot_num = 1
bike.bot.add_to_info_to_send(enemy_symbol)
bike.bot.add_to_info_to_send(str(init_posns[bot_num].x) + " " + str(init_posns[bot_num].y))
bike.bot.add_to_info_to_send(str(init_posns[1 - bot_num].x) + " " + str(init_posns[1 - bot_num].y))
bike.bot.add_to_info_to_send(map_file_name)
def _generate_random_posns(self, map):
""" Generates a random pair of symmetric positions
such that the positions do not conflict with any
object in the map and returns the pair.
"""
max_ = map.size - 1
while True:
x = randint(0, max_ / 3)
y = randint(0, max_ / 3)
posn1 = Position(x, y, max_, max_)
posn2 = Position(max_ - x, max_ - y, max_, max_)
if map.get_symbol(posn1) == EMPTY and map.get_symbol(posn2) == EMPTY:
break
return [posn1, posn2]
def _map_has_bikes(self, map):
""" Return true if the map has both the bikes (symbols) in it.
"""
return map.get_count(BIKE_1_SYMBOL) == 1 and map.get_count(BIKE_2_SYMBOL) == 1
def _generate_init_posns(self, map):
""" Depending on map, generates initial positions
for the bikes.
-> Return the positions if the map has the bikes in it.
-> Else randomly generate symmetric positions and return.
"""
if self._map_has_bikes(map):
return [map.get_position(BIKE_1_SYMBOL), map.get_position(BIKE_2_SYMBOL)]
else:
return self._generate_random_posns(map)
def get_moves(self, first_move=False):
""" Gets moves from each bot driving the bikes. """
for i in range(2):
bike = self.bikes[i]
updates = self.map.updates[i]
# When should we pass?
# only when
# 1) it is an odd move.
# 2) you don't have nitro
# 3) your opponent has nitro
condition = (
self.turn_count % 2 == 1 and self.bikes[i].bot.nitro_left == 0 and self.bikes[1 - i].bot.nitro_left > 0
)
if condition:
pass
else:
bike.get_move(updates, self.map, first_move)
def update_powers(self):
""" Updates the power up counts of bikes. """
for bike in self.bikes:
bot = bike.bot
bot.nitro_left = max(0, bot.nitro_left - 1)
bot.traverser_left = max(0, bot.traverser_left - 1)
def _check_for_collisions(self):
""" Checks for collisions, and if any,
sets the appropriate flags. """
# Bikes colliding with some thing there on the map
# since previous move
for i in range(2):
bike = self.bikes[i]
symbol_at_new_posn = self.map.get_symbol(bike.curr_posn)
# check for collision only if traverser power is not there
if bike.bot.traverser_left == 0:
bike.is_dead = symbol_at_new_posn != EMPTY and symbol_at_new_posn not in POWER_UP_SYMBOLS
# bring the bike back to life if it is dead becaule ...
# the opponent had nitro and this bike did not move this turn
# and hence were declared dead
if (
#.........这里部分代码省略.........