random-walk-lib 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,33 @@
1
+ Metadata-Version: 2.4
2
+ Name: random-walk-lib
3
+ Version: 1.0.0
4
+ Summary: A Python library for 2D random walk with visualization
5
+ Home-page: https://github.com/hello1-UI/random-walk-lib
6
+ Author: hello1-UI
7
+ Author-email: freetongdynastynet@hotmail.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.8
12
+ Description-Content-Type: text/markdown
13
+ Requires-Dist: matplotlib>=3.0
14
+
15
+ # Random Walk Lib
16
+ 一个实现二维随机游走的Python库,支持步数控制、位置记录和路径可视化。
17
+
18
+ ## 安装
19
+ ### 本地安装
20
+ ```bash
21
+ # 进入项目根目录
22
+ cd path/to/random_walk_lib
23
+ pip install .
24
+ ```
25
+
26
+ ---
27
+
28
+ ### 第二步:本地安装并测试
29
+ 打开终端,按以下步骤操作:
30
+ #### 1. 进入项目根目录
31
+ ```bash
32
+ cd path/to/random_walk_lib # 替换成你的项目根目录路径
33
+ ```
@@ -0,0 +1,19 @@
1
+ # Random Walk Lib
2
+ 一个实现二维随机游走的Python库,支持步数控制、位置记录和路径可视化。
3
+
4
+ ## 安装
5
+ ### 本地安装
6
+ ```bash
7
+ # 进入项目根目录
8
+ cd path/to/random_walk_lib
9
+ pip install .
10
+ ```
11
+
12
+ ---
13
+
14
+ ### 第二步:本地安装并测试
15
+ 打开终端,按以下步骤操作:
16
+ #### 1. 进入项目根目录
17
+ ```bash
18
+ cd path/to/random_walk_lib # 替换成你的项目根目录路径
19
+ ```
@@ -0,0 +1,4 @@
1
+ [build-system]
2
+ # 指定打包依赖和构建后端
3
+ requires = ["setuptools>=61.0", "wheel"]
4
+ build-backend = "setuptools.build_meta"
@@ -0,0 +1,11 @@
1
+ # random_walk_lib/__init__.py
2
+ """
3
+ Random Walk Library
4
+ 一个实现二维随机游走的Python库,支持步数控制、位置记录和路径可视化
5
+ """
6
+
7
+ # 暴露核心类,方便外部导入
8
+ from .random_walk import RandomWalk
9
+
10
+ # 定义库的版本(可选)
11
+ __version__ = "1.0.0"
@@ -0,0 +1,84 @@
1
+ # random_walk_lib/random_walk.py
2
+ import random
3
+ from typing import List, Optional
4
+
5
+
6
+ class RandomWalk:
7
+ """
8
+ 随机游走类,实现二维平面上的随机方向移动
9
+
10
+ Attributes:
11
+ rn (list): 当前位置坐标 [x, y]
12
+ all_positions (list): 记录所有走过的位置,格式为 [[x1,y1], [x2,y2], ...]
13
+ """
14
+
15
+ def __init__(self, start_position: List[int] = None):
16
+ """
17
+ 初始化随机游走对象
18
+
19
+ Args:
20
+ start_position: 起始位置,默认 [0, 0]
21
+ """
22
+ self.rn = start_position if start_position is not None else [0, 0]
23
+ self.CHOICES = ['up', 'down', 'left', 'right']
24
+ self.UD = ['up', 'down']
25
+ self.LR = ['left', 'right']
26
+ self.all_positions = [self.rn.copy()] # 初始化位置记录
27
+
28
+ def _choice_walk(self) -> List[int]:
29
+ """私有方法:执行单次随机移动,更新位置"""
30
+ choice = random.choice(self.CHOICES)
31
+ if choice in self.UD:
32
+ self.rn[0] += 1 if choice == 'up' else -1
33
+ else:
34
+ self.rn[1] += 1 if choice == 'right' else -1
35
+ self.all_positions.append(self.rn.copy())
36
+ return self.rn
37
+
38
+ def walk(self, steps: int, verbose: bool = True) -> List[List[int]]:
39
+ """
40
+ 执行指定步数的随机游走
41
+
42
+ Args:
43
+ steps: 移动步数
44
+ verbose: 是否打印每步位置,默认 True
45
+
46
+ Returns:
47
+ 所有走过的位置列表
48
+ """
49
+ for step in range(1, steps + 1):
50
+ self._choice_walk()
51
+ if verbose:
52
+ print(f"Step {step}: x={self.rn[0]}, y={self.rn[1]}")
53
+ return self.all_positions
54
+
55
+ def plot_walk(self, figsize: tuple = (8, 6)) -> None:
56
+ """
57
+ 可视化随机游走路径(需安装matplotlib)
58
+
59
+ Args:
60
+ figsize: 图表尺寸,默认 (8,6)
61
+ """
62
+ try:
63
+ import matplotlib.pyplot as plt
64
+ except ImportError:
65
+ raise ImportError("请先安装matplotlib: pip install matplotlib")
66
+
67
+ x_coords = [pos[0] for pos in self.all_positions]
68
+ y_coords = [pos[1] for pos in self.all_positions]
69
+
70
+ plt.figure(figsize=figsize)
71
+ plt.plot(x_coords, y_coords, marker='o', markersize=4, linestyle='-', color='blue')
72
+ plt.scatter(x_coords[0], y_coords[0], color='green', s=100, label='Start')
73
+ plt.scatter(x_coords[-1], y_coords[-1], color='red', s=100, label='End')
74
+ plt.xlabel('X Position')
75
+ plt.ylabel('Y Position')
76
+ plt.title('Random Walk Path')
77
+ plt.legend()
78
+ plt.grid(True)
79
+ plt.show()
80
+
81
+ @property
82
+ def current_position(self) -> str:
83
+ """返回当前位置的可读字符串"""
84
+ return f"x position: {self.rn[0]}, y position: {self.rn[1]}"
@@ -0,0 +1,33 @@
1
+ Metadata-Version: 2.4
2
+ Name: random-walk-lib
3
+ Version: 1.0.0
4
+ Summary: A Python library for 2D random walk with visualization
5
+ Home-page: https://github.com/hello1-UI/random-walk-lib
6
+ Author: hello1-UI
7
+ Author-email: freetongdynastynet@hotmail.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.8
12
+ Description-Content-Type: text/markdown
13
+ Requires-Dist: matplotlib>=3.0
14
+
15
+ # Random Walk Lib
16
+ 一个实现二维随机游走的Python库,支持步数控制、位置记录和路径可视化。
17
+
18
+ ## 安装
19
+ ### 本地安装
20
+ ```bash
21
+ # 进入项目根目录
22
+ cd path/to/random_walk_lib
23
+ pip install .
24
+ ```
25
+
26
+ ---
27
+
28
+ ### 第二步:本地安装并测试
29
+ 打开终端,按以下步骤操作:
30
+ #### 1. 进入项目根目录
31
+ ```bash
32
+ cd path/to/random_walk_lib # 替换成你的项目根目录路径
33
+ ```
@@ -0,0 +1,10 @@
1
+ README.md
2
+ pyproject.toml
3
+ setup.cfg
4
+ random_walk_lib/__init__.py
5
+ random_walk_lib/random_walk.py
6
+ random_walk_lib.egg-info/PKG-INFO
7
+ random_walk_lib.egg-info/SOURCES.txt
8
+ random_walk_lib.egg-info/dependency_links.txt
9
+ random_walk_lib.egg-info/requires.txt
10
+ random_walk_lib.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ matplotlib>=3.0
@@ -0,0 +1 @@
1
+ random_walk_lib
@@ -0,0 +1,26 @@
1
+ [metadata]
2
+ name = random-walk-lib
3
+ version = 1.0.0
4
+ author = hello1-UI
5
+ author_email = freetongdynastynet@hotmail.com
6
+ description = A Python library for 2D random walk with visualization
7
+ long_description = file: README.md
8
+ long_description_content_type = text/markdown
9
+ url = https://github.com/hello1-UI/random-walk-lib
10
+ classifiers =
11
+ Programming Language :: Python :: 3
12
+ License :: OSI Approved :: MIT License
13
+ Operating System :: OS Independent
14
+
15
+ [options]
16
+ packages = find:
17
+ python_requires = >=3.8
18
+ install_requires = matplotlib>=3.0
19
+
20
+ [options.packages.find]
21
+ where = .
22
+
23
+ [egg_info]
24
+ tag_build =
25
+ tag_date = 0
26
+