ms_toollib 1.2.9__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 @@
1
+ /target
@@ -0,0 +1,29 @@
1
+ [package]
2
+ name = "ms_toollib"
3
+ version = "1.2.9"
4
+ description = "Algorithms for Minesweeper"
5
+ documentation = "https://docs.rs/ms_toollib/"
6
+ license = "MIT"
7
+ readme = "README.md"
8
+ keywords = ["minesweeper", "possibility", "mine", "laymine"]
9
+ edition = "2018"
10
+ authors = ["Wang Jianing <wangjianing@88.com>"]
11
+
12
+ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
13
+
14
+ [dependencies]
15
+ pyo3 = { version ="0.15.1", features = ["extension-module"] }
16
+ ms_toollib = { version ="1.2.10", features = ["py"] }
17
+
18
+
19
+ [lib]
20
+ name = "ms_toollib"
21
+ crate-type = ["cdylib", "lib"]
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
@@ -0,0 +1,17 @@
1
+ Metadata-Version: 2.1
2
+ Name: ms_toollib
3
+ Version: 1.2.9
4
+ Classifier: Programming Language :: Python
5
+ Summary: Algorithms for minesweeper.
6
+ Keywords: minesweeper,possibility,mine,laymine
7
+ Author: Wang Jianing
8
+ Author-email: wangjianing@88.com
9
+ Maintainer-email: Wang Jianing <wangjianing@88.com>
10
+ License: MIT
11
+ Requires-Python: >=3.6
12
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
13
+ Project-URL: homepage, https://github.com/eee555/ms_toollib
14
+ Project-URL: documentation, https://docs.rs/ms_toollib/latest/ms_toollib
15
+ Project-URL: repository, https://github.com/eee555/ms_toollib
16
+
17
+ (还没写)
@@ -0,0 +1,56 @@
1
+ [project]
2
+ name = "ms_toollib"
3
+ version = "1.2.9"
4
+ description = "Algorithms for minesweeper."
5
+ readme = "readme.md"
6
+ requires-python = ">=3.6"
7
+ keywords = ["minesweeper", "possibility", "mine", "laymine"]
8
+ authors = [
9
+ {email = "wangjianing@88.com"},
10
+ {name = "Wang Jianing"}
11
+ ]
12
+ maintainers = [
13
+ {name = "Wang Jianing", email = "wangjianing@88.com"}
14
+ ]
15
+ classifiers = [ "Programming Language :: Python" ]
16
+
17
+ # dependencies = [
18
+ # "httpx",
19
+ # "gidgethub[httpx]>4.0.0",
20
+ # "django>2.1; os_name != 'nt'",
21
+ # "django>2.0; os_name == 'nt'"
22
+ # ]
23
+
24
+ [project.optional-dependencies]
25
+ # test = [
26
+ # "pytest < 5.0.0",
27
+ # "pytest-cov[all]"
28
+ # ]
29
+
30
+ [project.urls]
31
+ homepage = "https://github.com/eee555/ms_toollib"
32
+ documentation = "https://docs.rs/ms_toollib/latest/ms_toollib"
33
+ repository = "https://github.com/eee555/ms_toollib"
34
+ # changelog = "github.com/me/spam/blob/master/CHANGELOG.md"
35
+
36
+ # [project.scripts]
37
+ # spam-cli = "spam:main_cli"
38
+
39
+ # [project.gui-scripts]
40
+ # spam-gui = "spam:main_gui"
41
+
42
+ # [project.entry-points."spam.magical"]
43
+ # tomatoes = "spam:main_tomatoes"
44
+
45
+
46
+ [build-system]
47
+ requires = ["maturin>=0.12,<0.13"]
48
+ build-backend = "maturin"
49
+
50
+ # [tool.maturin]
51
+ # bindings = "cffi"
52
+ # compatibility = "linux"
53
+
54
+
55
+
56
+
@@ -0,0 +1 @@
1
+ (还没写)
@@ -0,0 +1,79 @@
1
+ use ms_toollib::*;
2
+ use pyo3::prelude::*;
3
+
4
+ #[pyclass(name = "MinesweeperBoard")]
5
+ pub struct PyMinesweeperBoard {
6
+ pub core: MinesweeperBoard,
7
+ }
8
+
9
+ #[pymethods]
10
+ impl PyMinesweeperBoard {
11
+ #[new]
12
+ pub fn new(board: Vec<Vec<i32>>) -> PyMinesweeperBoard {
13
+ let c = MinesweeperBoard::new(board.clone());
14
+ PyMinesweeperBoard {
15
+ core: c,
16
+ }
17
+ }
18
+ pub fn step(&mut self, e: &str, pos: (usize, usize)) {
19
+ self.core.step(e, pos).unwrap();
20
+ }
21
+ pub fn step_flow(&mut self, operation: Vec<(&str, (usize, usize))>) {
22
+ self.core.step_flow(operation).unwrap();
23
+ }
24
+ #[getter]
25
+ fn get_game_board(&self) -> PyResult<Vec<Vec<i32>>> {
26
+ Ok(self.core.game_board.clone())
27
+ }
28
+ #[getter]
29
+ fn get_left(&self) -> PyResult<usize> {
30
+ Ok(self.core.left)
31
+ }
32
+ #[getter]
33
+ fn get_right(&self) -> PyResult<usize> {
34
+ Ok(self.core.right)
35
+ }
36
+ #[getter]
37
+ fn get_chording(&self) -> PyResult<usize> {
38
+ Ok(self.core.chording)
39
+ }
40
+ #[getter]
41
+ fn get_ces(&self) -> PyResult<usize> {
42
+ Ok(self.core.ces)
43
+ }
44
+ #[getter]
45
+ fn get_flag(&self) -> PyResult<usize> {
46
+ Ok(self.core.flag)
47
+ }
48
+ #[getter]
49
+ fn get_solved3BV(&self) -> PyResult<usize> {
50
+ Ok(self.core.solved3BV)
51
+ }
52
+ }
53
+
54
+ #[pyclass(name = "AvfVideo")]
55
+ pub struct PyAvfVideo {
56
+ pub core: AvfVideo,
57
+ }
58
+
59
+ #[pymethods]
60
+ impl PyAvfVideo {
61
+ #[new]
62
+ pub fn new(file_name: &str) -> PyAvfVideo {
63
+ let c = AvfVideo::new(file_name);
64
+ PyAvfVideo {
65
+ core: c,
66
+ }
67
+ }
68
+ pub fn parse_video(&mut self) {
69
+ self.core.parse_video().unwrap();
70
+ }
71
+ pub fn analyse(&mut self) {
72
+ self.core.analyse();
73
+ }
74
+ pub fn analyse_for_features(&mut self, controller: Vec<&str>) {
75
+ self.core.analyse_for_features(controller);
76
+ }
77
+ }
78
+
79
+
@@ -0,0 +1,303 @@
1
+ use pyo3::prelude::*;
2
+ use pyo3::wrap_pyfunction;
3
+ // use pyo3::PyTraverseError;
4
+ // use pyo3::class::basic::PyObjectProtocol;
5
+ // use std::cmp::{max, min};
6
+
7
+ use ms_toollib::*;
8
+ mod board;
9
+ pub use board::{PyAvfVideo, PyMinesweeperBoard};
10
+
11
+ // pip install maturin
12
+ // maturin publish --manylinux 2014
13
+
14
+ #[pyfunction]
15
+ #[pyo3(name = "refresh_matrix")]
16
+ fn py_refresh_matrix(
17
+ board_of_game: Vec<Vec<i32>>,
18
+ ) -> PyResult<(Vec<Vec<i32>>, Vec<(usize, usize)>, Vec<i32>)> {
19
+ Ok(refresh_matrix(&board_of_game))
20
+ }
21
+
22
+ #[pyfunction]
23
+ #[pyo3(name = "refresh_matrixs")]
24
+ fn py_refresh_matrixs(
25
+ board_of_game: Vec<Vec<i32>>,
26
+ ) -> PyResult<(
27
+ Vec<Vec<Vec<i32>>>,
28
+ Vec<Vec<(usize, usize)>>,
29
+ Vec<Vec<i32>>,
30
+ usize,
31
+ usize,
32
+ )> {
33
+ Ok(refresh_matrixs(&board_of_game))
34
+ }
35
+
36
+ #[pyfunction]
37
+ #[pyo3(name = "cal_op")]
38
+ fn py_cal_op(board: Vec<Vec<i32>>) -> PyResult<usize> {
39
+ Ok(cal_op(board))
40
+ }
41
+
42
+ #[pyfunction]
43
+ #[pyo3(name = "laymine_number")]
44
+ fn py_laymine_number(
45
+ row: usize,
46
+ column: usize,
47
+ mine_num: usize,
48
+ x0: usize,
49
+ y0: usize,
50
+ ) -> PyResult<Vec<Vec<i32>>> {
51
+ // 通用标准埋雷引擎
52
+ // 输出为二维的局面
53
+ Ok(laymine_number(row, column, mine_num, x0, y0))
54
+ }
55
+
56
+ #[pyfunction]
57
+ #[pyo3(name = "cal3BV")]
58
+ fn py_cal3BV(board: Vec<Vec<i32>>) -> PyResult<usize> {
59
+ Ok(cal3BV(&board))
60
+ }
61
+
62
+ // #[pyfunction]
63
+ // fn solve_minus(
64
+ // mut matrix_as: Vec<Vec<Vec<i32>>>,
65
+ // mut matrix_xs: Vec<Vec<(usize, usize)>>,
66
+ // mut matrix_bs: Vec<Vec<i32>>,
67
+ // mut board_of_game: Vec<Vec<i32>>,
68
+ // ) -> PyResult<(Vec<Vec<Vec<i32>>>, Vec<Vec<(usize, usize)>>, Vec<Vec<i32>>, Vec<Vec<i32>>, Vec<(usize, usize)>, Vec<(usize, usize)>)> {
69
+ // let (not_mine, is_mine) = ms_toollib_rs::solve_minus(&mut matrix_as, &mut matrix_xs, &mut matrix_bs, &mut board_of_game);
70
+ // Ok((matrix_as, matrix_xs, matrix_bs, board_of_game, not_mine, is_mine))
71
+ // }
72
+
73
+ #[pyfunction]
74
+ #[pyo3(name = "refresh_board")]
75
+ fn py_refresh_board(
76
+ board: Vec<Vec<i32>>,
77
+ mut board_of_game: Vec<Vec<i32>>,
78
+ ClickedPoses: Vec<(usize, usize)>,
79
+ ) -> PyResult<Vec<Vec<i32>>> {
80
+ refresh_board(&board, &mut board_of_game, ClickedPoses);
81
+ Ok(board_of_game)
82
+ }
83
+
84
+ #[pyfunction]
85
+ #[pyo3(name = "get_all_not_mine_on_board")]
86
+ fn py_get_all_not_mine_on_board(game_board: Vec<Vec<i32>>) -> PyResult<Vec<(usize, usize)>> {
87
+ Ok(get_all_not_mine_on_board(&game_board, 40))
88
+ }
89
+
90
+ // #[pyfunction]
91
+ // fn solve_direct(
92
+ // mut MatrixA: Vec<Vec<i32>>,
93
+ // mut Matrixx: Vec<(usize, usize)>,
94
+ // mut Matrixb: Vec<i32>,
95
+ // mut board_of_game: Vec<Vec<i32>>,
96
+ // ) -> PyResult<(Vec<Vec<i32>>, Vec<(usize, usize)>, Vec<(usize, usize)>)> {
97
+ // let (notMine, is_mine) = ms_toollib_rs::solve_direct(&mut MatrixA, &mut Matrixx, &mut Matrixb, &mut board_of_game);
98
+ // Ok((board_of_game, notMine, is_mine))
99
+ // }
100
+
101
+ #[pyfunction]
102
+ #[pyo3(name = "laymine_op_number")]
103
+ fn py_laymine_op_number(
104
+ row: usize,
105
+ column: usize,
106
+ mine_num: usize,
107
+ x0: usize,
108
+ y0: usize,
109
+ ) -> PyResult<Vec<Vec<i32>>> {
110
+ Ok(laymine_op_number(row, column, mine_num, x0, y0))
111
+ }
112
+
113
+ // #[pyfunction(enuLimit = 30)]
114
+ // fn solve_enumerate(
115
+ // Matrix_as: Vec<Vec<Vec<i32>>>,
116
+ // Matrix_xs: Vec<Vec<(usize, usize)>>,
117
+ // Matrix_bs: Vec<Vec<i32>>,
118
+ // mut board_of_game: Vec<Vec<i32>>,
119
+ // enuLimit: usize,
120
+ // ) -> PyResult<(Vec<Vec<i32>>, Vec<(usize, usize)>, Vec<(usize, usize)>)> {
121
+ // let (notMine, is_mine) = ms_toollib_rs::solve_enumerate(
122
+ // &Matrix_as,
123
+ // &Matrix_xs,
124
+ // &Matrix_bs,
125
+ // enuLimit,
126
+ // );
127
+ // Ok((board_of_game, notMine, is_mine))
128
+ // }
129
+
130
+ #[pyfunction]
131
+ #[pyo3(name = "unsolvable_structure")]
132
+ fn py_unsolvable_structure(boardCheck: Vec<Vec<i32>>) -> PyResult<bool> {
133
+ Ok(unsolvable_structure(&boardCheck))
134
+ }
135
+
136
+ #[pyfunction(enuLimit = 30)]
137
+ #[pyo3(name = "is_solvable")]
138
+ fn py_is_solvable(board: Vec<Vec<i32>>, x0: usize, y0: usize, enuLimit: usize) -> PyResult<bool> {
139
+ Ok(is_solvable(&board, x0, y0, enuLimit))
140
+ }
141
+
142
+ #[pyfunction(min3BV = 0, max3BV = 1000_000, max_times = 1000_000, method = 0)]
143
+ #[pyo3(name = "laymine_op")]
144
+ pub fn py_laymine_op(
145
+ row: usize,
146
+ column: usize,
147
+ mine_num: usize,
148
+ x0: usize,
149
+ y0: usize,
150
+ min3BV: usize,
151
+ max3BV: usize,
152
+ max_times: usize,
153
+ method: usize,
154
+ ) -> PyResult<(Vec<Vec<i32>>, Vec<usize>)> {
155
+ Ok(laymine_op(
156
+ row, column, mine_num, x0, y0, min3BV, max3BV, max_times, method,
157
+ ))
158
+ }
159
+
160
+ #[pyfunction(min3BV = 0, max3BV = 1000000, max_times = 1000000, enuLimit = 30)]
161
+ #[pyo3(name = "laymine_solvable")]
162
+ pub fn py_laymine_solvable(
163
+ row: usize,
164
+ column: usize,
165
+ mine_num: usize,
166
+ x0: usize,
167
+ y0: usize,
168
+ min3BV: usize,
169
+ max3BV: usize,
170
+ max_times: usize,
171
+ method: usize,
172
+ ) -> PyResult<(Vec<Vec<i32>>, Vec<usize>)> {
173
+ Ok(laymine_solvable(
174
+ row, column, mine_num, x0, y0, min3BV, max3BV, max_times, method,
175
+ ))
176
+ }
177
+
178
+ #[pyfunction(min3BV = 0, max3BV = 1000_000, max_times = 1000_000, method = 0)]
179
+ #[pyo3(name = "laymine")]
180
+ pub fn py_laymine(
181
+ row: usize,
182
+ column: usize,
183
+ mine_num: usize,
184
+ x0: usize,
185
+ y0: usize,
186
+ min3BV: usize,
187
+ max3BV: usize,
188
+ max_times: usize,
189
+ method: usize,
190
+ ) -> PyResult<(Vec<Vec<i32>>, Vec<usize>)> {
191
+ Ok(laymine(
192
+ row, column, mine_num, x0, y0, min3BV, max3BV, max_times, method,
193
+ ))
194
+ }
195
+
196
+ #[pyfunction(min3BV = 0, max3BV = 1000000, max_times = 1000000, enuLimit = 30)]
197
+ #[pyo3(name = "laymine_solvable_thread")]
198
+ pub fn py_laymine_solvable_thread(
199
+ row: usize,
200
+ column: usize,
201
+ mine_num: usize,
202
+ x0: usize,
203
+ y0: usize,
204
+ min3BV: usize,
205
+ max3BV: usize,
206
+ mut max_times: usize,
207
+ enuLimit: usize,
208
+ ) -> PyResult<(Vec<Vec<i32>>, [usize; 3])> {
209
+ Ok(laymine_solvable_thread(
210
+ row, column, mine_num, x0, y0, min3BV, max3BV, max_times, enuLimit,
211
+ ))
212
+ }
213
+
214
+ #[pyfunction]
215
+ #[pyo3(name = "cal_possibility")]
216
+ fn py_cal_possibility(
217
+ board_of_game: Vec<Vec<i32>>,
218
+ mine_num: f64,
219
+ ) -> PyResult<(Vec<((usize, usize), f64)>, f64, [usize; 3])> {
220
+ // mine_num为局面中雷的总数,不管有没有标
221
+ // 还返回局面中雷数的范围
222
+ let mut board_of_game = board_of_game.clone();
223
+ mark_board(&mut board_of_game);
224
+ match cal_possibility(&board_of_game, mine_num) {
225
+ Ok(t) => return Ok(t),
226
+ Err(e) => return Ok((vec![], f64::NAN, [0, 0, 0])),
227
+ };
228
+ }
229
+
230
+ #[pyfunction]
231
+ #[pyo3(name = "cal_possibility_onboard")]
232
+ fn py_cal_possibility_onboard(
233
+ board_of_game: Vec<Vec<i32>>,
234
+ mine_num: f64,
235
+ ) -> PyResult<(Vec<Vec<f64>>, [usize; 3])> {
236
+ // mine_num为局面中雷的总数,不管有没有标
237
+ let mut board_of_game = board_of_game.clone();
238
+ mark_board(&mut board_of_game);
239
+ match cal_possibility_onboard(&board_of_game, mine_num) {
240
+ Ok(t) => return Ok(t),
241
+ Err(e) => return Ok((vec![], [0, 0, 0])),
242
+ };
243
+ }
244
+
245
+ #[pyfunction]
246
+ #[pyo3(name = "sample_3BVs_exp")]
247
+ fn py_sample_3BVs_exp(x0: usize, y0: usize, n: usize) -> PyResult<Vec<usize>> {
248
+ Ok((&sample_3BVs_exp(x0, y0, n)).to_vec())
249
+ }
250
+
251
+ #[pyfunction]
252
+ #[pyo3(name = "OBR_board", text_signature = "(data_vec, height, width)")]
253
+ fn py_OBR_board(data_vec: Vec<usize>, height: usize, width: usize) -> PyResult<Vec<Vec<i32>>> {
254
+ // Ok(OBR_board(data_vec, height, width).unwrap())
255
+ match OBR_board(data_vec, height, width) {
256
+ //判断方法结果
257
+ Ok(ans) => Ok(ans),
258
+ Err(e) => Ok(vec![vec![200]]),
259
+ }
260
+ }
261
+
262
+ // #[pyproto]
263
+ // impl PyObjectProtocol for Minesweeperboard {
264
+ // fn __getattr__(&self, name: &str) -> PyResult<usize> {
265
+ // match name {
266
+ // "left" => return Ok(self.left),
267
+ // "right" => return Ok(self.right),
268
+ // "chording" => return Ok(self.chording),
269
+ // "solved3BV" => return Ok(self.solved3BV),
270
+ // "ces" => return Ok(self.ces),
271
+ // "flag" => return Ok(self.flag),
272
+ // _ => return Ok(999),
273
+ // }
274
+ // }
275
+ // }
276
+
277
+ #[pymodule]
278
+ fn ms_toollib(_py: Python, m: &PyModule) -> PyResult<()> {
279
+ m.add_function(wrap_pyfunction!(py_refresh_matrix, m)?)?;
280
+ m.add_function(wrap_pyfunction!(py_refresh_matrixs, m)?)?;
281
+ m.add_function(wrap_pyfunction!(py_cal_op, m)?)?;
282
+ m.add_function(wrap_pyfunction!(py_cal3BV, m)?)?;
283
+ m.add_function(wrap_pyfunction!(py_laymine_number, m)?)?;
284
+ m.add_function(wrap_pyfunction!(py_refresh_board, m)?)?;
285
+ m.add_function(wrap_pyfunction!(py_laymine, m)?)?;
286
+ m.add_function(wrap_pyfunction!(py_get_all_not_mine_on_board, m)?)?;
287
+ m.add_function(wrap_pyfunction!(py_laymine_op_number, m)?)?;
288
+ m.add_function(wrap_pyfunction!(py_laymine_op, m)?)?;
289
+ // m.add_function(wrap_pyfunction!(solve_direct, m)?)?;
290
+ // m.add_function(wrap_pyfunction!(solve_enumerate, m)?)?;
291
+ m.add_function(wrap_pyfunction!(py_unsolvable_structure, m)?)?;
292
+ m.add_function(wrap_pyfunction!(py_is_solvable, m)?)?;
293
+ // m.add_function(wrap_pyfunction!(enuOneStep, m)?)?;
294
+ m.add_function(wrap_pyfunction!(py_laymine_solvable, m)?)?;
295
+ m.add_function(wrap_pyfunction!(py_laymine_solvable_thread, m)?)?;
296
+ m.add_function(wrap_pyfunction!(py_cal_possibility, m)?)?;
297
+ m.add_function(wrap_pyfunction!(py_sample_3BVs_exp, m)?)?;
298
+ m.add_function(wrap_pyfunction!(py_OBR_board, m)?)?;
299
+ m.add_function(wrap_pyfunction!(py_cal_possibility_onboard, m)?)?;
300
+ m.add_class::<PyMinesweeperBoard>()?;
301
+ m.add_class::<PyAvfVideo>()?;
302
+ Ok(())
303
+ }