示例#1
0
    def check_speed(self):
        """Adds velocity to the ball periodically."""

        if pyxel.frame_count > self.speed_up:
            self.speed_up += SPEED_PERIOD
            self.ball.x_vol += SPEED_AMOUNT * sign(self.ball.x_vol)
            self.ball.y_vol += SPEED_AMOUNT * sign(self.ball.y_vol)
示例#2
0
def are_these_two_locations_visible_to_each_other(first_x, first_y, second_x,
                                                  second_y,
                                                  can_see_past_function):
    """
    Answers the question of whether someone at location (first_x, first_y) could see someone or something at location (second_x, second_y).
    There are different rules for who can see past what, so the caller provides a can_see_past_function to help us decide.
    :param first_x: int, horizontal index in the map
    :param first_y: int, vertical index in the map
    :param second_x: int, horizontal index in the map
    :param second_y: int, vertical index in the map
    :param can_see_past_function: function, returns True/False for whether the viewer can see past the square at location (x, y)
    :return: True if can see from (first_x, first_y) to (second_x, second_y), or False if cannot
    """
    are_visible = True
    if first_x == second_x:
        direction = utilities.sign(second_y - first_y)
        for i in range(first_y + direction, second_y, direction):
            if not can_see_past_function(first_x, i):
                are_visible = False
                break
    elif first_y == second_y:
        direction = utilities.sign(second_x - first_x)
        for i in range(first_x + direction, second_x, direction):
            if not can_see_past_function(i, first_y):
                are_visible = False
                break
    else:
        are_visible = False
    return are_visible
示例#3
0
	def updateTruckLocations(self, truckDirectives):
		#Action should be a list of tuples where action[i] = (ith truck directive x, ith truck directive y)
		for i, (t_row, t_col) in enumerate(self.truckPos):
			(directive_row, directive_col) = truckDirectives[i]
			dy = directive_row - t_row
			dx = directive_col - t_col
			if abs(dy) > abs(dx):
				move_y = utilities.sign(dy)
				self.truckPos[i] = (t_row + move_y, t_col)
			else:
				move_x = utilities.sign(dx)
				self.truckPos[i] = (t_row, t_col + move_x)
示例#4
0
	def simulateAction(self, state, action):
		newState = copy.deepcopy(state)
		for i, (t_row, t_col) in enumerate(newState.truckPos):
			(directive_row, directive_col) = action[i]
			dy = directive_row - t_row
			dx = directive_col - t_col
			if abs(dy) > abs(dx):
				move_y = utilities.sign(dy)
				newState.truckPos[i] = (t_row + move_y, t_col)
			else:
				move_x = utilities.sign(dx)
				newState.truckPos[i] = (t_row, t_col + move_x)
		return newState
示例#5
0
def is_right_triangle(x_1, y_1, x_2, y_2):
    if (x_1 == x_2 and y_1 == y_2) or (x_1 == 0
                                       and y_1 == 0) or (x_2 == 0
                                                         and y_2 == 0):
        return False
    if simplify((x_1, y_1)) == simplify(
        (x_2, y_2)) or utilities.sign(x_1 - x_2) == utilities.sign(y_1 - y_2):
        return False
    if (x_1 == 0 and y_2 == 0) or (x_2 == 0 and y_1 == 0):
        return True
    edge_1 = simplify((x_1, y_1))
    edge_2 = simplify((x_2, y_2))
    edge_3 = simplify((abs(y_1 - y_2), abs(x_1 - x_2)))
    return edge_2 == edge_3 or edge_1 == edge_3
示例#6
0
def do_next_move(player_x, player_y):
    """
    Perform the werewolf's next move.
    :param player_x: int, x coordinate of where the werewolf thinks the player is
    :param player_y: int, y coordinate of where the werewolf thinks the player is
    """
    global x, y, stunned_count, skip_turn
    # TODO: If the werewolf is dead, exit this function.
    # TODO: If we should skip the werewolf's turn, set skip to False and exit this function.
    # TODO: If werewolf is stunned, decrease the stun count by 1 and exit this function.

    delta_x = player_x - x  # distance from werewolf to player in X direction
    delta_y = player_y - y  # distance from werewolf to player in Y direction

    possible_next_x = x + utilities.sign(delta_x)  # one square closer to player in X direction
    possible_next_y = y + utilities.sign(delta_y)  # one square closer to player in Y direction

    is_x_direction_move_possible = delta_x != 0 and is_open_space(possible_next_x, y)
    is_y_direction_move_possible = delta_y != 0 and is_open_space(x, possible_next_y)

    if is_x_direction_move_possible and not is_y_direction_move_possible:
        x = possible_next_x  # If werewolf can only move horizontally, then do so.
    elif not is_x_direction_move_possible and is_y_direction_move_possible:
        y = possible_next_y  # If werewolf can only move vertically, then do so.
    elif is_x_direction_move_possible and is_y_direction_move_possible:
        if abs(delta_x) > abs(delta_y):
            x = possible_next_x  # If werewolf can move in both directions but is closer horizontally, move horizontally.
        elif abs(delta_x) < abs(delta_y):
            y = possible_next_y  # If werewolf can move in both directions but is closer vertically, move vertically.
        else:
            # If werewolf can move in both directions and is equally close to the player horizontally and vertically, randomly pick whether to move horizontally or vertically.
            randomly_pick_x = random.choice([True, False])
            if randomly_pick_x:
                x = possible_next_x
            else:
                y = possible_next_y
示例#7
0
def find_x_intercept(coord_1, coord_2):
    if utilities.sign(coord_1[1]) == utilities.sign(coord_2[1]):
        return None
    x_diff = coord_2[0] - coord_1[0]
    y_diff = coord_2[1] - coord_1[1]
    return coord_1[0] - (coord_1[1] * (x_diff / y_diff))