コード例 #1
0
def test_adj_default():

    board_adj_default_cross = Board(10, 10)

    p1 = Pos(5, 5)
    p2 = Pos(6, 5)
    p3 = Pos(4, 4)

    # cross:
    assert board_adj_default_cross.is_adjacent(p1, p2) == True
    # diag :
    assert board_adj_default_cross.is_adjacent(p1, p3) == False

    set_default_adjacency(AdjacencyEvaluatorCross)
    board_adj_default_cross_2 = Board(10, 10)
    # cross:
    assert board_adj_default_cross_2.is_adjacent(p1, p2) == True
    # diag :
    assert board_adj_default_cross_2.is_adjacent(p1, p3) == False

    set_default_adjacency(AdjacencyEvaluatorCrossDiag)
    board_adj_default_cross_diag = Board(10, 10)
    # cross:
    assert board_adj_default_cross_diag.is_adjacent(p1, p2) == True
    # diag :
    assert board_adj_default_cross_diag.is_adjacent(p1, p3) == True
コード例 #2
0
def test_getitem_fail():

    board = Board(5, 14)
    failed_at_failing = False

    try:
        a = board[0, 14]
        failed_at_failing = True
    except BoardIndexError as e:
        print(e)
    try:
        p = Pos(5, 0)
        a = board[p]
        failed_at_failing = True
    except BoardIndexError as e:
        print(e)
    try:
        a = board[0, -15]
        failed_at_failing = True
    except BoardIndexError as e:
        print(e)
    try:
        p = Pos(-6, 0)
        a = board[p]
        failed_at_failing = True
    except BoardIndexError as e:
        print(e)

    assert failed_at_failing == False
コード例 #3
0
def test_permute_simple():

    board = Board(5, 3)
    setting_data = ("ABCDE", "FGHIJ", "KLMNO")
    board.set_data_from_string(setting_data)

    tile_with_c = board[2, 0]
    tile_with_n = board[3, 2]

    board.circular_permute_tiles([Pos(2, 0), Pos(3, 2)])
    print(board.render())

    assert tile_with_c.x == 3
    assert tile_with_c.y == 2
    assert tile_with_c.data == "C"
    assert board[3, 2].data == "C"

    assert tile_with_n.x == 2
    assert tile_with_n.y == 0
    assert tile_with_n.data == "N"
    assert board[2, 0].data == "N"

    render_result = """

		ABNDE
		FGHIJ
		KLMCO

	"""
    assert strip_multiline(board.render()) == strip_multiline(render_result)
コード例 #4
0
ファイル: aboard.py プロジェクト: darkrecher/aboard
    def circular_permute_tiles(self, positions):
        """
		positions est un itérable.
		"""

        made_first_iteration = False

        for pos in positions:
            if made_first_iteration:
                cur_pos = pos
                cur_tile = self._tiles[cur_pos.y][cur_pos.x]
                cur_tile.pos = Pos(prev_pos)
                cur_tile.x = prev_pos.x
                cur_tile.y = prev_pos.y
                self._tiles[prev_pos.y][prev_pos.x] = cur_tile
                prev_pos = cur_pos
            else:
                first_pos = pos
                first_tile = self._tiles[first_pos.y][first_pos.x]
                prev_pos = first_pos
                made_first_iteration = True

        first_tile.pos = Pos(pos)
        first_tile.x = pos.x
        first_tile.y = pos.y
        self._tiles[pos.y][pos.x] = first_tile
コード例 #5
0
def generate_training_stats(years_in_majors, position):
    exp_term = 0
    if years_in_majors == 0: pass
    else: exp_term = 16.0 / (1 + 60.0 / (years_in_majors * years_in_majors))

    params1 = parameters()
    params2 = parameters()
    stat1 = redistribute(int(rand_skill_seed(params1[0], params1[1])))
    stat2 = redistribute(int(rand_skill_seed(params2[0], params2[1])))

    total = stat1 + stat2
    hitting, fielding, pitching = 0, 0, 0
    if Pos.is_infield(position):
        hitting = int(round(total * 1.0 / 2.0))
        fielding = int(round(total * 1.0 / 2.0))
        pitching = MIN_VALUE
    elif Pos.is_outfield(position):
        hitting = int(round(total * 3.0 / 5.0))
        fielding = int(round(total * 2.0 / 5.0))
        pitching = MIN_VALUE
    elif Pos.is_pitcher(position):
        index = int(total * 0.02999)
        params = distro_set[index]
        pitching = redistribute(int(rand_skill_seed(params[0], params[1])))
        fielding = redistribute(
            int(rand_skill_seed(distro_set[3][0], distro_set[3][1])))
        hitting = redistribute(
            int(rand_skill_seed(distro_set[1][0], distro_set[1][1])))
    else:
        hitting = int(round(total * 4.0 / 5.0))
        fielding = int(round(total * 1.0 / 5.0))
        pitching = MIN_VALUE

    return redistribute(hitting), redistribute(fielding), redistribute(
        pitching)
コード例 #6
0
def generate_player():
	r = random(); name = ''
	if r < 0.5: name = rand_male_name() + ' ' + rand_surname()
	else: name = rand_female_name() + ' ' + rand_surname()

	pos = Pos.rand_position()

	weight, height = 0, 0
	if pos == Pos.CATCHER: weight, height = catcher_height_weight()
	elif Pos.is_infield(pos): weight, height = infield_height_weight()
	elif Pos.is_outfield(pos): weight, height = outfield_height_weight()
	else: weight, height = pitcher_height_weight()

	birthdate = generate_birthdate(start_date.year)

	bats, throws = generate_bats_throws()

	years_in_majors = int( gauss(years_old(birthdate, start_date) - 23, 2) )
	if years_in_majors < 0: years_in_majors = 0
	caps = Capabilities.generate_all_caps(height, weight, birthdate, start_date, years_in_majors, pos)

	pos_caps = PositionCapabilities.generate_pos_caps(pos)

	contract = Contract(get_FA(), 0, 0)

	personality = Personality.rand_personality()
 
	return Player(name, pos, height, weight, birthdate, bats, throws, caps, pos_caps, contract, personality)
コード例 #7
0
ファイル: test_position.py プロジェクト: darkrecher/aboard
def test_eq():

    p_1 = Pos(34, 78)
    p_2 = Pos(35, 78)
    p_3 = Pos(34, 77)
    p_4 = Pos(34, 78)
    p_5 = Pos(0, 0)

    assert p_1 == p_1
    assert p_1 != p_2
    assert p_1 != p_3
    assert p_1 == p_4
    assert p_1 != p_5
コード例 #8
0
    def __init__(self,
                 board,
                 pos_start,
                 pos_end,
                 pass_through_condition=propag_cond_default):
        # FUTURE : pathfinding avec tous les shortest paths possibles.
        # pathfinding avec tous les paths possibles

        super().__init__(board)
        self.pass_through_condition = pass_through_condition
        pos_start = Pos(pos_start)
        pos_end = Pos(pos_end)
        self.pos_start = pos_start
        self.pos_end = pos_end

        iter_propag = BoardIteratorPropagation(self.board, self.pos_start,
                                               pass_through_condition)

        try:
            while pos_end not in iter_propag.propagated_poss:
                next(iter_propag)
        except StopIteration:
            self.path = None
            return

        propagated_poss = iter_propag.propagated_poss

        # Et maintenant, on parcourt la propagation à l'envers,
        # pour retrouver le chemin.
        pos_cur = pos_end
        dist_cur = propagated_poss[pos_cur]
        self.path = [pos_cur]

        while pos_cur != pos_start:

            advanced = False
            for adj_pos in self.board.adjacency.adjacent_positions(pos_cur):
                if (propagated_poss.get(adj_pos, -2)
                        == dist_cur - 1) and pass_through_condition(
                            self.board[adj_pos], self.board[pos_cur]):
                    pos_cur = adj_pos
                    dist_cur -= 1
                    self.path.append(pos_cur)
                    advanced = True
                    break

            if not advanced:
                raise Exception(
                    "No adj pos with dist-1. Not supposed to happen")
コード例 #9
0
    def __next__(self):

        while self.nb_sub_coord_to_skip:
            self._apply_skip_sub_coord()
            self.nb_sub_coord_to_skip -= 1
            self._update_col_line_modification(True)

        try:
            val_coord_main = next(self.iter_main)
            must_change_sub = False
        except StopIteration:
            # Faut repartir à la "ligne" suivante.
            must_change_sub = True

        self._update_col_line_modification(must_change_sub)

        if must_change_sub:
            self._apply_skip_sub_coord()
            val_coord_main = next(self.iter_main)
            self._update_col_line_modification(True)

        if self.id_coord_main == Coord.X:
            x = val_coord_main
            y = self.val_coord_sub
        else:
            x = self.val_coord_sub
            y = val_coord_main

        new_pos = Pos(x, y)
        self._update_indicators(new_pos)
        return self.board.get_tile(self.current_pos)
コード例 #10
0
def test_adj_diag():

    simple_board = Board(10, 10, class_adjacency=AdjacencyEvaluatorCrossDiag)

    p1 = Pos(5, 5)
    p2 = Pos(6, 5)
    p3 = Pos(4, 4)

    # same :
    assert simple_board.is_adjacent(p1, p1) == False
    # cross :
    assert simple_board.is_adjacent(p1, p2) == True
    # diag :
    assert simple_board.is_adjacent(p1, p3) == True
    # none :
    assert simple_board.is_adjacent(p2, p3) == False
コード例 #11
0
def test_permute_column():

    board = Board(5, 7)
    setting_data = ("ABCDE", "FGHIJ", "KLMNO", "PQRST", "UVWXY", "01234",
                    "56789")
    board.set_data_from_string(setting_data)

    pos_to_permute = [Pos(tile.x, tile.y) for tile in board[2, :]]
    assert len(pos_to_permute) == 7

    board.circular_permute_tiles(pos_to_permute)
    print(board.render())

    render_result = """

		ABHDE
		FGMIJ
		KLRNO
		PQWST
		UV2XY
		01734
		56C89


	"""
    assert strip_multiline(board.render()) == strip_multiline(render_result)
    # Pour vérifier que la fonction de permutation ne vide pas la liste.
    # Ça le faisait avant, et c'était mal.
    assert len(pos_to_permute) == 7
コード例 #12
0
def test_replace_simple():

    board = Board(5, 3)
    setting_data = ("ABCDE", "FGHIJ", "KLMNO")
    board.set_data_from_string(setting_data)
    new_tile = Tile()
    new_tile.data = "Z"

    board.replace_tile(new_tile, Pos(3, 1))

    print(board.render())

    assert new_tile.x == 3
    assert new_tile.y == 1
    assert board[3, 1].data == "Z"

    render_result = """

		ABCDE
		FGHZJ
		KLMNO

	"""
    assert strip_multiline(board.render()) == strip_multiline(render_result)
    print(board.render())
コード例 #13
0
ファイル: arena.py プロジェクト: fuwizeye/battling-knights
    def __init__(self):

        board = []
        for x in range(0, 8):
            row = [Pos(x, y) for y in range(0, 8)]
            board.append(tuple(row))
        self.board = tuple(board)
コード例 #14
0
ファイル: test_position.py プロジェクト: darkrecher/aboard
def test_from_obj():
    class Whatever:
        def __init__(self):
            self.x = 23.9
            self.y = 45.8

    p = Pos(Whatever())
    assert p.x == 23 and p.y == 45
コード例 #15
0
    def getPlayerPositions(self):
        poss = []
        for r in range(1, 6):
            for c in range(1, 6):
                pos = Pos(r, c)
                if self.board.hasPiece(pos, self.playerPiece):
                    poss.append(pos)

        return poss
コード例 #16
0
 def __init__(self, board, pos_start, propag_condition=propag_cond_default):
     # TODO : avec plusieurs pos_start.
     super().__init__(board)
     self.propag_condition = propag_condition
     # Dict
     #  - clé : la pos propagée.
     #  - valeur : la distance depuis la pos de départ jusqu'à la pos propagée.
     self.propagated_poss = {}
     # liste de tuple de 2 éléments : la distance et la pos propagée.
     self.to_propagate_poss = [(0, Pos(pos_start))]
コード例 #17
0
def test_getitem_pos():

    board = Board(3, 3)
    p = Pos(1, 0)
    board[p].data = "|"
    board[Pos(0, -2)].data = "-"
    board[Pos(-2, 1)].data = "*"
    board[Pos(-1, -2)].data = "~"
    board[{"x": 1, "y": 2}].data = "I"

    render_result = """

		.|.
		-*~
		.I.

	"""
    print(board.render())
    assert strip_multiline(board.render()) == strip_multiline(render_result)
コード例 #18
0
    def __next__(self):

        self.current_posis_index += 1

        if self.current_posis_index >= len(self.posis):
            raise StopIteration

        new_pos = Pos(self.posis[self.current_posis_index])
        self._update_indicators(new_pos)
        return self.board.get_tile(self.current_pos)
コード例 #19
0
ファイル: aboard.py プロジェクト: darkrecher/aboard
    def __getitem__(self, args):
        # FUTURE : on a le droit de faire du *args, **kwargs avec getitem ?
        # Et ça donne quoi si on le fait ? À tester.

        if not args:
            return BoardIteratorRect(self)

        try:
            pos = Pos(args)
        except ValueError:
            pos = None

        if pos is not None:
            # Mode un seul élément
            return self._get_tile(pos.x, pos.y)

        slice_x = None
        slice_y = None
        id_coord_main = Coord.X

        try:
            iter_on_args = iter(args)
            slice_x = next(iter_on_args)
            slice_y = next(iter_on_args)
            id_coord_main = next(iter_on_args)
        except TypeError:
            slice_x = args
        except StopIteration:
            pass

        if (slice_x is None or slice_y is None or isinstance(slice_x, slice)
                or isinstance(slice_y, slice)):

            # Mode itération
            if slice_x is None:
                slice_x = slice(None, None, None)
            if isinstance(slice_x, int):
                slice_x = slice(slice_x, slice_x + 1, None)

            if slice_y is None:
                slice_y = slice(None, None, None)
            if isinstance(slice_y, int):
                slice_y = slice(slice_y, slice_y + 1, None)

            dict_coord_from_str = {"X": Coord.X, "Y": Coord.Y}
            if isinstance(id_coord_main, str):
                id_coord_main = id_coord_main.upper()
                if id_coord_main in dict_coord_from_str:
                    id_coord_main = dict_coord_from_str[id_coord_main]

            return BoardIteratorRect(self, slice_x, slice_y, id_coord_main)

            # Mode fail
        raise Exception("TODO fail get item" + "".join(args))
コード例 #20
0
 def __init__(self, x=None, y=None, board_owner=None):
     # TODO : il faut accepter le même bazar de param que pour l'objet Pos. Ou pas.
     self.x = x
     self.y = y
     # TODO : est-ce qu'on autorise des tiles sans coord, qui "flotte un peu dans les airs", ou pas ?
     try:
         self.pos = Pos(x, y)
     except:
         self.pos = None
     self.board_owner = board_owner
     self.data = "."
     self.mobile_items = []
コード例 #21
0
 def generate_pos_caps(cls, player_pos):
     skills = {}
     skills[Pos.CATCHER] = cls.redistribute(
         int(
             gauss(
                 cls.skill_levels[Pos.compare_pos(player_pos, Pos.CATCHER)],
                 cls.sigma)))
     skills[Pos.FIRST_BASE] = cls.redistribute(
         int(
             gauss(
                 cls.skill_levels[Pos.compare_pos(player_pos,
                                                  Pos.FIRST_BASE)],
                 cls.sigma)))
     skills[Pos.SECOND_BASE] = cls.redistribute(
         int(
             gauss(
                 cls.skill_levels[Pos.compare_pos(player_pos,
                                                  Pos.SECOND_BASE)],
                 cls.sigma)))
     skills[Pos.THIRD_BASE] = cls.redistribute(
         int(
             gauss(
                 cls.skill_levels[Pos.compare_pos(player_pos,
                                                  Pos.THIRD_BASE)],
                 cls.sigma)))
     skills[Pos.SHORTSTOP] = cls.redistribute(
         int(
             gauss(
                 cls.skill_levels[Pos.compare_pos(player_pos,
                                                  Pos.SHORTSTOP)],
                 cls.sigma)))
     skills[Pos.LEFT_FIELD] = cls.redistribute(
         int(
             gauss(
                 cls.skill_levels[Pos.compare_pos(player_pos,
                                                  Pos.LEFT_FIELD)],
                 cls.sigma)))
     skills[Pos.CENTER_FIELD] = cls.redistribute(
         int(
             gauss(
                 cls.skill_levels[Pos.compare_pos(player_pos,
                                                  Pos.CENTER_FIELD)],
                 cls.sigma)))
     skills[Pos.RIGHT_FIELD] = cls.redistribute(
         int(
             gauss(
                 cls.skill_levels[Pos.compare_pos(player_pos,
                                                  Pos.RIGHT_FIELD)],
                 cls.sigma)))
     return PositionCapabilities(skills)
コード例 #22
0
    def adjacent_positions(self, pos):
        # TODO : faudrait renvoyer des tiles ou des positions ?

        # Il est conseillé de mettre dans le même ordre que l'ordre des Direction.
        # C'est à dire dans le sens des aiguilles d'une montre.
        # (Mais ce n'est pas tout le temps possible avec des fonctions d'adjacences tordues)
        offsets = [(0, -1), (+1, 0), (0, +1), (-1, 0)]
        for offset in offsets:
            x = pos.x + offset[0]
            y = pos.y + offset[1]
            # TODO : le check de inbounds devrait être dans la classe board, tellement c'est un truc basique.
            if (0 <= x < self.board.w) and (0 <= y < self.board.h):
                yield Pos(x, y)
コード例 #23
0
    def movePlayerPiece(self):
        inp = input("Player " + self.playerPiece +
                    " move piece (position + direction, e.g. 'A1 NE'): ")

        try:
            pos = Pos.parse(inp[0:2])
            dir = inp[3:].rstrip()
            self.board.move(pos, self.playerPiece, dir)
        except TypeError as e1:
            print(str(e1))
            self.movePlayerPiece()
        except MoveError as e2:
            print(str(e2))
            self.movePlayerPiece()
コード例 #24
0
    def move(self, board_owner=None, tile_owner=None, z_index=None, *args, **kwargs):
        """
		Param prioritaire : tile_owner.
		Sinon : les autres params.
		"""
        # FUTURE : j'ai plein de fonctions qui crée une pos à partir de args et kwargs.
        # Y'aurait peut-être moyen de le factoriser avec un décorateur.

        if self.tile_owner is not None:
            # --- suppression du mobitem de la tile où il était avant ---
            # Si self n'est pas mobile_items, ça va raiser une exception.
            # C'est ce qu'on veut, parce que not supposed to happen.
            index_myself = self.tile_owner.mobile_items.index(self)
            del self.tile_owner.mobile_items[index_myself]
            # --- définition éventuelle de board_owner, à partir de l'actuel board_owner ---
            if board_owner is None:
                board_owner = self.tile_owner.board_owner

                # --- définition éventuelle de board_owner, à partir du nouveau tile_owner ---
        if tile_owner is not None:
            board_owner = tile_owner.board_owner

            # --- définition éventuelle de tile_owner, à partir de board_owner et des param de pos ---
        if tile_owner is None and board_owner is not None:
            try:
                pos = Pos(*args, **kwargs)
                tile_owner = board_owner[pos]
            except:
                tile_owner = None

                # --- Enregistrement dans le nouveau tile_owner, si défini ---
        if tile_owner is not None:
            self.tile_owner = tile_owner
            if z_index is None:
                tile_owner.mobile_items.append(self)
            else:
                tile_owner.mobile_items.insert(z_index, self)
コード例 #25
0
def test_directions_computing():
    center = Pos(4, 7)
    assert compute_direction(center, Pos(4, 5)) == Dir.UP
    assert compute_direction(center, Pos(5, 5)) == Dir.UP_RIGHT
    assert compute_direction(center, Pos(6, 5)) == Dir.UP_RIGHT
    assert compute_direction(center, Pos(6, 6)) == Dir.UP_RIGHT
    assert compute_direction(center, Pos(6, 7)) == Dir.RIGHT
    assert compute_direction(center, Pos(6, 8)) == Dir.DOWN_RIGHT
    assert compute_direction(center, Pos(6, 9)) == Dir.DOWN_RIGHT
    assert compute_direction(center, Pos(5, 9)) == Dir.DOWN_RIGHT
    assert compute_direction(center, Pos(4, 9)) == Dir.DOWN
    assert compute_direction(center, Pos(3, 9)) == Dir.DOWN_LEFT
    assert compute_direction(center, Pos(2, 9)) == Dir.DOWN_LEFT
    assert compute_direction(center, Pos(2, 8)) == Dir.DOWN_LEFT
    assert compute_direction(center, Pos(2, 7)) == Dir.LEFT
    assert compute_direction(center, Pos(2, 6)) == Dir.UP_LEFT
    assert compute_direction(center, Pos(2, 5)) == Dir.UP_LEFT
    assert compute_direction(center, Pos(3, 5)) == Dir.UP_LEFT
コード例 #26
0
ファイル: test_position.py プロジェクト: darkrecher/aboard
def test_coord_outing():
    p = Pos(23.9, 45.8)
    t = p.as_tuple()
    assert t[0] == 23 and t[1] == 45
    d = p.as_dict()
    assert d["x"] == 23 and d["y"] == 45
コード例 #27
0
    def find_drugs(code, batchno, num, index):
        print(code, num, index)
        global ishave_num

        # 添加明细
        win32api.SetCursorPos([Pos.TJMX_X(), Pos.TJMX_Y()])  # 设置鼠标位置
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)  # 左键点击
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)  # 左键点击
        time.sleep(1)
        pass

        # 药品编码搜索框
        win32api.SetCursorPos([Pos.YPBMSS_X(), Pos.YPBMSS_Y()])  # 设置鼠标位置
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)  # 左键点击
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)  # 左键点击
        time.sleep(0.1)
        pass

        # 清空输入框原有参数
        win32api.keybd_event(win32con.VK_LCONTROL, 0, 0, 0)
        win32api.keybd_event(KEYJSON['A'], 0, 0, 0)
        win32api.keybd_event(KEYJSON['A'], 0, win32con.KEYEVENTF_KEYUP, 0)
        win32api.keybd_event(win32con.VK_LCONTROL, 0, win32con.KEYEVENTF_KEYUP,
                             0)
        pass

        # 把code转list,一个一个 输入进去
        code_list = list(code)
        for value in code_list:
            if value in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ':
                win32api.keybd_event(win32con.VK_SHIFT, 0, 0, 0)
                pass
            win32api.keybd_event(KEYJSON[value], 0, 0, 0)
            win32api.keybd_event(KEYJSON[value], 0, win32con.KEYEVENTF_KEYUP,
                                 0)
            if value in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ':
                win32api.keybd_event(win32con.VK_SHIFT, 0,
                                     win32con.KEYEVENTF_KEYUP, 0)
                pass
            pass

        # 点击搜索按钮
        win32api.SetCursorPos([Pos.YPBMSSBTN_X(), Pos.YPBMSSBTN_Y()])  # 设置鼠标位置
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)  # 左键点击
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)  # 左键点击
        time.sleep(1)
        pass

        # 全选订单明细
        win32api.SetCursorPos([Pos.YPBMSSCHECK_X(),
                               Pos.YPBMSSCHECK_Y()])  # 设置鼠标位置
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)  # 左键点击
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)  # 左键点击
        time.sleep(1)
        pass

        img = ImageGrab.grab(Pos.SCREEN_IMAGE_POSITION())
        px = img.load()
        for x in range(img.width):
            for y in range(img.height):
                if (str(px[x, y]) != str((255, 255, 255))):
                    ishave_num = True
                    break
                pass
            pass

        # 确定选中
        win32api.SetCursorPos([Pos.SUREBTN_X(), Pos.SUREBTN_Y()])  # 设置鼠标位置
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)  # 左键点击
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)  # 左键点击
        time.sleep(1)
        pass

        if ishave_num:
            # 初始化tab焦点
            win32api.SetCursorPos([Pos.FIRSTDATA_X(),
                                   Pos.FIRSTDATA_Y()])  # 设置鼠标位置
            DOUBLE_CLICK()
            time.sleep(0.5)

            count = 0
            # while count < 5 * index + 1:
            while count < 5 * index + 2:  # 2.0
                TAB_KEYUP()
                count += 1
                pass
            time.sleep(0.5)

            # 把code转list,一个一个 输入进去
            batch_list = list(batchno)
            print(batch_list)
            for value in batch_list:
                if value in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ':
                    win32api.keybd_event(win32con.VK_SHIFT, 0, 0, 0)
                    pass

                if value == '-':
                    print(KEYJSON[value])

                win32api.keybd_event(KEYJSON[value], 0, 0, 0)
                win32api.keybd_event(KEYJSON[value], 0,
                                     win32con.KEYEVENTF_KEYUP, 0)
                if value in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ':
                    win32api.keybd_event(win32con.VK_SHIFT, 0,
                                         win32con.KEYEVENTF_KEYUP, 0)
                    pass
                pass

            TAB_KEYUP()

            num_list = list(str(int(num)))
            for value in num_list:
                win32api.keybd_event(KEYJSON[value], 0, 0, 0)
                win32api.keybd_event(KEYJSON[value], 0,
                                     win32con.KEYEVENTF_KEYUP, 0)
                pass
            time.sleep(0.5)

            TAB_KEYUP()

            print(code, num)
            pass
コード例 #28
0
def test_push_cols_lines():
    """
	Test de déplacement de toutes les tiles d'une ligne ou d'une colonne,
	en ajoutant une nouvelle tile qui va pousser les autres.
	Comme dans le jeu de plateau 'Labyrinthe', et dans le challenge CodinGame 'Xmas Rush'
	"""

    # PUSH 3 RIGHT

    board = Board(5, 7)
    setting_data = ("ABCDE", "FGHIJ", "KLMNO", "PQRST", "UVWXY", "01234",
                    "56789")
    board.set_data_from_string(setting_data)

    added_tile = Tile()
    added_tile.data = "#"
    pos_to_permute = [Pos(tile.x, tile.y) for tile in board[::-1, 3]]

    board.circular_permute_tiles(pos_to_permute)
    removed_tile = board[0, 3]
    board.replace_tile(added_tile, Pos(0, 3))
    print(board.render())

    assert removed_tile.data == "T"

    render_result = """

		ABCDE
		FGHIJ
		KLMNO
		#PQRS
		UVWXY
		01234
		56789


	"""
    assert strip_multiline(board.render()) == strip_multiline(render_result)
    print("")

    # PUSH 0 LEFT

    board = Board(5, 7)
    setting_data = ("ABCDE", "FGHIJ", "KLMNO", "PQRST", "UVWXY", "01234",
                    "56789")
    board.set_data_from_string(setting_data)

    added_tile = Tile()
    added_tile.data = "#"
    pos_to_permute = [Pos(tile.x, tile.y) for tile in board[:, 0]]

    board.circular_permute_tiles(pos_to_permute)
    removed_tile = board[4, 0]
    board.replace_tile(added_tile, Pos(4, 0))
    print(board.render())

    assert removed_tile.data == "A"

    render_result = """

		BCDE#
		FGHIJ
		KLMNO
		PQRST
		UVWXY
		01234
		56789


	"""
    assert strip_multiline(board.render()) == strip_multiline(render_result)
    print("")

    # PUSH 4 DOWN

    board = Board(5, 7)
    setting_data = ("ABCDE", "FGHIJ", "KLMNO", "PQRST", "UVWXY", "01234",
                    "56789")
    board.set_data_from_string(setting_data)

    added_tile = Tile()
    added_tile.data = "#"
    pos_to_permute = [Pos(tile.x, tile.y) for tile in board[4, ::-1]]

    board.circular_permute_tiles(pos_to_permute)
    removed_tile = board[4, 0]
    board.replace_tile(added_tile, Pos(4, 0))
    print(board.render())

    assert removed_tile.data == "9"

    render_result = """

		ABCD#
		FGHIE
		KLMNJ
		PQRSO
		UVWXT
		0123Y
		56784


	"""
    assert strip_multiline(board.render()) == strip_multiline(render_result)
    print("")

    # PUSH 1 UP

    board = Board(5, 7)
    setting_data = ("ABCDE", "FGHIJ", "KLMNO", "PQRST", "UVWXY", "01234",
                    "56789")
    board.set_data_from_string(setting_data)

    added_tile = Tile()
    added_tile.data = "#"
    pos_to_permute = [Pos(tile.x, tile.y) for tile in board[1, :]]

    board.circular_permute_tiles(pos_to_permute)
    removed_tile = board[1, board.h - 1]
    board.replace_tile(added_tile, Pos(1, board.h - 1))
    print(board.render())

    assert removed_tile.data == "B"

    render_result = """

		AGCDE
		FLHIJ
		KQMNO
		PVRST
		U1WXY
		06234
		5#789


	"""
    assert strip_multiline(board.render()) == strip_multiline(render_result)
    print("")
コード例 #29
0
def do_shopcart(txt=''):
    global ishave_num
    file_arr = txt.split(' || ')
    txt_arr = []
    for item in file_arr:
        txt_arr.extend(item.split('\n'))
        pass

    txt_data = []
    print('do_shopcart')
    try:
        # txt = open(file_path)
        for item in txt_arr:
            item_text = item.split('&')
            if not (len(item_text) == 1 and len(item_text[0]) == 0):
                txt_data.append(item_text)
                pass
        nrows = len(txt_data)
        pass
    except Exception:
        return Exception
    print('txt_data', txt_data)

    i = 0
    drug_arr = []
    batch_arr = []
    num_arr = []
    drug_code_index = 0  # 医院药品编码的位置索引
    batch_no_index = 1  # 批号
    num_index = 2  # 药品数量的位置索引
    while i < nrows:
        row = txt_data[i]
        print('row', row)
        if len(row) >= drug_code_index and len(
                row) >= batch_no_index and len(row) >= num_index and len(
                    str(row[drug_code_index])) > 0 and len(
                        str(row[drug_code_index])
                    ) > 1 and len(str(row[batch_no_index])) > 0 and len(
                        str(row[num_index])) > 0 and row[num_index].isdigit():
            drug_arr.append(str(row[drug_code_index]))
            batch_arr.append(str(row[batch_no_index]))
            num_arr.append(str(row[num_index]))
            pass
        i += 1
        pass
    print('drug_arr', drug_arr)
    print('batch_arr', batch_arr)
    print('num_arr', num_arr)

    windows = {}  # 所有的窗口
    win_id = 0  # 准备要操作的窗口id

    def find_window_callback(id, key):
        # 获取窗口时候的回调
        if win32gui.GetWindowText(id).strip():
            _item = []
            _item.append(hex(id))
            _item.append(win32gui.GetClassName(id))
            _item.append(win32gui.GetWindowText(id))
            if key == 'windows':
                windows[id] = _item
                pass
            pass

    # 获取所有打开的窗口
    win32gui.EnumWindows(find_window_callback, 'windows')
    shell.SendKeys('%')

    ishave_trade = False
    # 遍历一下,取到当前的
    for item in windows:
        if '东莞交易' in windows[item][2]:
            ishave_trade = True
            win_id = item
            # 最大化
            win32api.PostMessage(win_id, win32con.WM_SYSCOMMAND,
                                 win32con.SC_MAXIMIZE, 0)
            win32gui.SetForegroundWindow(win_id)
            time.sleep(1)

            Pos.now_hWnd = win32gui.WindowFromPoint(
                (int(Pos.SCREEN_X / 2), int(Pos.SCREEN_Y / 2)))
            (Pos.now_hWnd_X1, Pos.now_hWnd_Y1, Pos.now_hWnd_X2,
             Pos.now_hWnd_Y2) = win32gui.GetWindowRect(Pos.now_hWnd)
            break
        pass

    if ishave_trade == False:
        win32api.MessageBox(0, '没有找到交易平台', '错误', win32con.MB_SYSTEMMODAL)
        # os._exit(0)
        # sys.exit()
        return False

    print('-------------------------------------------------')
    print('-------------------------------------------------')

    # 判断当前是否在自动入库页面
    isIn = True
    img = ImageGrab.grab(Pos.TJMX_SCREEN_POS())
    px = img.load()
    for x in range(img.width):
        for y in range(img.height):
            print(str(px[x, y]))
            if (str(px[x, y]) != str((8, 104, 207))):
                isIn = False
                break
            pass
        pass

    if isIn == False:
        win32api.MessageBox(0, '当前不在自动入库模块', '错误', win32con.MB_SYSTEMMODAL)
        return False

    def find_drugs(code, batchno, num, index):
        print(code, num, index)
        global ishave_num

        # 添加明细
        win32api.SetCursorPos([Pos.TJMX_X(), Pos.TJMX_Y()])  # 设置鼠标位置
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)  # 左键点击
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)  # 左键点击
        time.sleep(1)
        pass

        # 药品编码搜索框
        win32api.SetCursorPos([Pos.YPBMSS_X(), Pos.YPBMSS_Y()])  # 设置鼠标位置
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)  # 左键点击
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)  # 左键点击
        time.sleep(0.1)
        pass

        # 清空输入框原有参数
        win32api.keybd_event(win32con.VK_LCONTROL, 0, 0, 0)
        win32api.keybd_event(KEYJSON['A'], 0, 0, 0)
        win32api.keybd_event(KEYJSON['A'], 0, win32con.KEYEVENTF_KEYUP, 0)
        win32api.keybd_event(win32con.VK_LCONTROL, 0, win32con.KEYEVENTF_KEYUP,
                             0)
        pass

        # 把code转list,一个一个 输入进去
        code_list = list(code)
        for value in code_list:
            if value in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ':
                win32api.keybd_event(win32con.VK_SHIFT, 0, 0, 0)
                pass
            win32api.keybd_event(KEYJSON[value], 0, 0, 0)
            win32api.keybd_event(KEYJSON[value], 0, win32con.KEYEVENTF_KEYUP,
                                 0)
            if value in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ':
                win32api.keybd_event(win32con.VK_SHIFT, 0,
                                     win32con.KEYEVENTF_KEYUP, 0)
                pass
            pass

        # 点击搜索按钮
        win32api.SetCursorPos([Pos.YPBMSSBTN_X(), Pos.YPBMSSBTN_Y()])  # 设置鼠标位置
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)  # 左键点击
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)  # 左键点击
        time.sleep(1)
        pass

        # 全选订单明细
        win32api.SetCursorPos([Pos.YPBMSSCHECK_X(),
                               Pos.YPBMSSCHECK_Y()])  # 设置鼠标位置
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)  # 左键点击
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)  # 左键点击
        time.sleep(1)
        pass

        img = ImageGrab.grab(Pos.SCREEN_IMAGE_POSITION())
        px = img.load()
        for x in range(img.width):
            for y in range(img.height):
                if (str(px[x, y]) != str((255, 255, 255))):
                    ishave_num = True
                    break
                pass
            pass

        # 确定选中
        win32api.SetCursorPos([Pos.SUREBTN_X(), Pos.SUREBTN_Y()])  # 设置鼠标位置
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)  # 左键点击
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)  # 左键点击
        time.sleep(1)
        pass

        if ishave_num:
            # 初始化tab焦点
            win32api.SetCursorPos([Pos.FIRSTDATA_X(),
                                   Pos.FIRSTDATA_Y()])  # 设置鼠标位置
            DOUBLE_CLICK()
            time.sleep(0.5)

            count = 0
            # while count < 5 * index + 1:
            while count < 5 * index + 2:  # 2.0
                TAB_KEYUP()
                count += 1
                pass
            time.sleep(0.5)

            # 把code转list,一个一个 输入进去
            batch_list = list(batchno)
            print(batch_list)
            for value in batch_list:
                if value in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ':
                    win32api.keybd_event(win32con.VK_SHIFT, 0, 0, 0)
                    pass

                if value == '-':
                    print(KEYJSON[value])

                win32api.keybd_event(KEYJSON[value], 0, 0, 0)
                win32api.keybd_event(KEYJSON[value], 0,
                                     win32con.KEYEVENTF_KEYUP, 0)
                if value in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ':
                    win32api.keybd_event(win32con.VK_SHIFT, 0,
                                         win32con.KEYEVENTF_KEYUP, 0)
                    pass
                pass

            TAB_KEYUP()

            num_list = list(str(int(num)))
            for value in num_list:
                win32api.keybd_event(KEYJSON[value], 0, 0, 0)
                win32api.keybd_event(KEYJSON[value], 0,
                                     win32con.KEYEVENTF_KEYUP, 0)
                pass
            time.sleep(0.5)

            TAB_KEYUP()

            print(code, num)
            pass

    i = 0
    table_index = 0
    while i < len(drug_arr):
        ishave_num = False
        print('num_arr[i]', num_arr[i])
        find_drugs(drug_arr[i], batch_arr[i], float(num_arr[i]), table_index)
        if ishave_num:
            table_index += 1
        i += 1
        pass

    win32api.MessageBox(0, '录入完成', '成功', win32con.MB_SYSTEMMODAL)

    # txt = open(file_path, 'w')
    # txt.write('')
    # txt.close()
    return True
コード例 #30
0
ファイル: test_position.py プロジェクト: darkrecher/aboard
def test_str():
    p = Pos(23.9, 45.8)
    assert str(p) == "<Pos 23, 45 >"