numberplace_core/
lib.rs

1use crate::normal_game::setting::BlockSize;
2use crate::normal_game::setting::GameSetting;
3use crate::normal_game::NormalGame;
4
5mod generator;
6mod normal_game;
7mod pattern;
8
9/// Generate a number-place problem.
10/// The first element of the returned Tuple is the question, and the next element is the answer.
11///
12/// ナンバープレースの問題を生成する。
13/// 返却される Tuple の最初の要素は問題で、次の要素は答えである。
14///
15/// Issues of the following block-sizes can be generated quickly. For other sizes, it takes time to generate them.
16/// 以下のブロックサイズの問題はある程度素早く生成することが可能である。それ以外のサイズについては、生成に時間がかかる。
17///
18/// 1x3, 2x2, 2x3, 3x2, 4x2, 2x4, 3x3, 2x5, 5x2, 4x3, 3x4, 4x4, 4x5, 5x4, 5x5
19///
20/// Even though it is quick, it will take a few seconds for 3x4 and 4x3 sizes,
21/// about 30 seconds for 4x5 and 5x4 sizes, and about a minute for 5x5 sizes.
22/// 素早くと言っても、3x4,4x3のサイズで数秒、4x5,5x4のサイズで約30秒、5x5のサイズで1分程度の時間はかかると思われる。
23///
24/// # Examples
25///
26/// ```
27/// let (issue, solved) = generate_numberplace(BlockSize {
28///     height: 3,
29///     width: 3,
30/// });
31/// ```
32pub fn generate_numberplace(block_size: BlockSize) -> (NormalGame, NormalGame) {
33    NormalGame::generate(block_size)
34}
35
36/// Solve number-place issues.
37/// The second argument, issue, can be a string such as the following.  
38///
39/// ナンバープレースの問題を解く。  
40///  第二引数の issue は例えば以下のような文字列を指定可能である。  
41///
42/// - `"5 2 9 1|   1   8|3    6  2| 4    7|6       1|  5    9|9  7    4| 6   3|  7 2 5 3"`
43/// - `"7, , ,11,4, , ,10,2, , ,1,12, , ,5| , ,6, , ,3, , , , ,16, , ,10| ,10,14, , ,13,7, , ,5,6, , ,3,1,|2, , , , , , ,15,13, , , , , , ,14|8, , , , , , ,1,12, , , , , , ,11| ,13,12, , ,8,15, , ,9,5, , ,14,16| , ,10, , ,2, , , , ,11, , ,7,|15, , ,9,5, , ,12,4, , ,2,6, , ,8|10, , ,5,1, , ,16,15, , ,9,8, , ,4| , ,8, , ,10, , , , ,1, , ,6| ,7,11, , ,4,8, , ,14,12, , ,5,3|4, , , , , , ,5,7, , , , , , ,10|9, , , , , , ,14,10, , , , , , ,1| ,6,2, , ,7,5, , ,11,9, , ,4,8| , ,13, , ,15, , , , ,3, , ,16|16, , ,3,10, , ,4,6, , ,14,13, , ,12"`
44///
45/// # Examples
46///
47/// ```
48/// let solved = solve_numberplace(
49///     BlockSize {
50///         height: 3,
51///         width: 3,
52///     },
53///     "5 2 9 1|   1   8|3    6  2| 4    7|6       1|  5    9|9  7    4| 6   3|  7 2 5 3",
54/// );
55/// ```
56pub fn solve_numberplace(block_size: BlockSize, issue: &str) -> Option<NormalGame> {
57    let mut game = NormalGame::new(GameSetting::new(block_size));
58    game.load(issue);
59    game.solve()
60}
61
62#[cfg(test)]
63mod tests {
64    use super::*;
65    mod generate_numberplace {
66        use super::*;
67        #[test]
68        #[ignore]
69        fn test() {
70            let (issue, solved) = generate_numberplace(BlockSize {
71                height: 3,
72                width: 3,
73            });
74            println!("{}", issue.to_string_with_comma());
75            println!("{}", solved.to_string_with_comma());
76            assert!(false);
77        }
78    }
79    mod solve {
80        use super::*;
81        #[ignore]
82        #[test]
83        fn test() {
84            let solved = solve_numberplace(
85                BlockSize {
86                    height: 3,
87                    width: 3,
88                },
89                "5 2 9 1|   1   8|3    6  2| 4    7|6       1|  5    9|9  7    4| 6   3|  7 2 5 3",
90            );
91            println!("{}", solved.unwrap().to_string_with_comma());
92            assert!(false);
93        }
94    }
95}