本文整理汇总了Python中position.Position.new方法的典型用法代码示例。如果您正苦于以下问题:Python Position.new方法的具体用法?Python Position.new怎么用?Python Position.new使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类position.Position
的用法示例。
在下文中一共展示了Position.new方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: move
# 需要导入模块: from position import Position [as 别名]
# 或者: from position.Position import new [as 别名]
def move(self, steps: int) -> 'MegaCar':
"""
Move car "step" amount of places.
"""
if self.horizontal:
return Car.new(self.start + Position.new(steps, 0), self.horizontal,
self.length)
else:
return Car.new(self.start + Position.new(0, steps), self.horizontal,
self.length)
示例2: interactive_search
# 需要导入模块: from position import Position [as 别名]
# 或者: from position.Position import new [as 别名]
def interactive_search(game_index):
game = games[game_index - 1]
print("Trying to solve game with breadth first algortihm... ")
print("If I can't solve it in a second, I'll ask for your help.")
breath_search(game, 1)
print("We can simplify this problem by \"freezing\" some cars.")
while True:
for car in game.cars:
car.immobile = False
change_goal = bool(input("Do you want to change the goal? True/False "))
if change_goal:
index = int(input("Give the index of the goal car: (e.g.: 2) "))
position = list(map(int, input("Give the position of the goal: (e.g.: 2,3) ").split(",")))
position = Position.new(position[0], position[1])
game.goal = (index, position)
freeze_cars = list(map(int, input("Tell me which cars to freeze: (e.g.: 10, 14, 16) ").split(", ")))
freeze_cars = [game.cars[i] for i in freeze_cars]
for car in freeze_cars:
car.immobile = True
total_time = int(input("How long do want to run? "))
try:
breath_search(game, total_time)
except Win as win:
save = bool(input("You won! Do you want to save this game and proceed? True/False "))
if save:
game = win.board
示例3: __init__
# 需要导入模块: from position import Position [as 别名]
# 或者: from position.Position import new [as 别名]
def __init__(self, start, end):
self.start = start
self.end = end
if start.y == end.y:
self.horizontal = True
self.length = abs(end.x - start.x)
else:
self.horizontal = False
self.length = abs(end.y - start.y)
self.positions = [start]
for i in range(1, self.length):
if self.horizontal:
self.positions.append(start + Position.new(i, 0))
else:
self.positions.append(start + Position.new(0, i))
self.positions.append(end)
示例4: from_goal
# 需要导入模块: from position import Position [as 别名]
# 或者: from position.Position import new [as 别名]
def from_goal(goal: (int, Position), cars: List[Car]):
(index, goal_pos) = goal
car_to_move = cars[index]
if car_to_move.horizontal:
if goal_pos.x < car_to_move.start.x:
mega_car_start = Position.new(car_to_move.start.x - 1, car_to_move.start.y)
else:
mega_car_start = Position.new(car_to_move.end.x + 1, car_to_move.end.y)
else:
if goal_pos.y < car_to_move.start.y:
mega_car_start = Position.new(car_to_move.start.x, car_to_move.start.y - 1)
else:
mega_car_start = Position.new(car_to_move.end.x, car_to_move.end.y + 1)
mega_car = MegaCar(
min(mega_car_start, goal_pos),
max(mega_car_start, goal_pos)
)
return mega_car
示例5: from_board
# 需要导入模块: from position import Position [as 别名]
# 或者: from position.Position import new [as 别名]
def from_board(board: 'Board'):
(index, goal_pos) = board.goal
car_to_move = board.cars[index]
if car_to_move.horizontal:
if goal_pos.x < car_to_move.start.x:
mega_car_start = Position.new(car_to_move.start.x - 1, car_to_move.start.y)
else:
mega_car_start = Position.new(car_to_move.end.x + 1, car_to_move.end.y)
else:
if goal_pos.y < car_to_move.start.y:
mega_car_start = Position.new(car_to_move.start.x, car_to_move.start.y - 1)
else:
mega_car_start = Position.new(car_to_move.end.x, car_to_move.end.y + 1)
mega_car = MegaCar(
min(mega_car_start, goal_pos),
max(mega_car_start, goal_pos)
)
return mega_car
示例6: __str__
# 需要导入模块: from position import Position [as 别名]
# 或者: from position.Position import new [as 别名]
def __str__(self, *args, **kwargs):
"""
Give color and number to cars in visualization.
"""
board = '\n'
for y in range(0, self.board_height):
for x in range(0, self.board_width):
if self.car_that_contains_position(Position.new(x, y)) is not None:
i = self.cars.index(
self.car_that_contains_position(Position.new(x, y)))
if i == 0:
board += colored(str(i).zfill(2), 'red') + ' '
else:
board += color(str(i).zfill(2), i) + ' '
else:
board += 'XX '
board += '\n'
return board
示例7: blocking_cars
# 需要导入模块: from position import Position [as 别名]
# 或者: from position.Position import new [as 别名]
def blocking_cars(self, goal: (int, Position)) -> List[Car]:
(index, goal_pos) = goal
car_to_move = self.cars[index]
if car_to_move.horizontal:
if goal_pos.x < car_to_move.start.x:
mega_car_start = Position.new(car_to_move.start.x - 1, car_to_move.start.y)
else:
mega_car_start = Position.new(car_to_move.end.x + 1, car_to_move.end.y)
else:
if goal_pos.y < car_to_move.start.y:
mega_car_start = Position.new(car_to_move.start.x, car_to_move.start.y - 1)
else:
mega_car_start = Position.new(car_to_move.end.x, car_to_move.end.y + 1)
mega_car = MegaCar(
min(mega_car_start, goal_pos),
max(mega_car_start, goal_pos)
)
return mega_car.no_clash_all_cars(self.cars)
示例8: Board
# 需要导入模块: from position import Position [as 别名]
# 或者: from position.Position import new [as 别名]
from board import Board
from car import Car
from position import Position
level1 = Board(cars=[
Car.new(Position.new(2, 2), True, 2),
Car.new(Position.new(3, 3), False, 2),
Car.new(Position.new(4, 0), False, 3),
Car.new(Position.new(4, 4), True, 2)
], goal=(0, Position.new(5, 2)),
board_height=6,
board_width=6
)
game1 = Board(goal=(0, Position.new(5, 2)),
board_height=6,
board_width=6,
cars=[
Car.new(length=2, horizontal=True, start=Position.new(3, 2)),
Car.new(length=3, horizontal=False, start=Position.new(2, 0)),
Car.new(length=2, horizontal=True, start=Position.new(3, 0)),
Car.new(length=3, horizontal=False, start=Position.new(5, 0)),
Car.new(length=2, horizontal=True, start=Position.new(4, 3)),
Car.new(length=2, horizontal=False, start=Position.new(0, 4)),
Car.new(length=2, horizontal=True, start=Position.new(1, 4)),
Car.new(length=2, horizontal=False, start=Position.new(3, 3)),
Car.new(length=2, horizontal=True, start=Position.new(4, 5)),
]
)
game2 = Board(goal=(0, Position.new(5, 2)),