Skip to content

Commit b0c02c3

Browse files
committed
增加java版选将拆分法
1 parent c9cd895 commit b0c02c3

28 files changed

+673
-1
lines changed

mjlib_java/readme.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
由网友ak翻译过来。
1+
split 选将拆分法
2+
3+
table 查表法
4+
5+
查表法由网友ak翻译过来

mjlib_java/split/logic.java

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
import java.util.HashMap;
2+
3+
public class logic
4+
{
5+
static Boolean check__yitiaolong(int[] cards, int gui_num, Boolean eye)
6+
{
7+
int key = 0;
8+
9+
for (int i = 0 ; i < 9 ; i++)
10+
{
11+
key = key * 10 + cards[i];
12+
}
13+
14+
if (key == 0)
15+
{
16+
return false;
17+
}
18+
19+
HashMap<Integer, Boolean> m;
20+
if (!eye)
21+
{
22+
m = gui_tested[gui_num];
23+
}
24+
else
25+
{
26+
m = gui_eye_tested[gui_num];
27+
}
28+
29+
if (m.containsKey(key))
30+
{
31+
return false;
32+
}
33+
34+
m.put(key, true);
35+
36+
for (int i = 0 ; i < 9 ; i++)
37+
{
38+
if (cards[i] > 4)
39+
{
40+
return true;
41+
}
42+
test_cards[i] = cards[i];
43+
}
44+
test_cards[33] = gui_num;
45+
if(!split.get_hu_info(test_cards, 34, 33)){
46+
System.out.println("error: cant't hu");
47+
}
48+
return true;
49+
}
50+
51+
static void parse_table_sub(int[] cards, int num, boolean eye)
52+
{
53+
for (int i = 0 ; i < 9 ; i++)
54+
{
55+
if (cards[i] == 0)
56+
{
57+
continue;
58+
}
59+
60+
cards[i]--;
61+
62+
if (!check_add(cards, num, eye))
63+
{
64+
cards[i]++;
65+
continue;
66+
}
67+
68+
if (num < 4)
69+
{
70+
parse_table_sub(cards, num + 1, eye);
71+
}
72+
cards[i]++;
73+
}
74+
}
75+
76+
static void parse_table(int[] cards, boolean eye)
77+
{
78+
if (!check_add(cards, 0, eye))
79+
{
80+
return;
81+
}
82+
parse_table_sub(cards, 1, eye);
83+
}
84+
85+
static void gen_auto_table_sub(int[] cards, int level, boolean eye)
86+
{
87+
for (int i = 0 ; i < 16 ; ++i)
88+
{
89+
if (i <= 8)
90+
{
91+
if (cards[i] > 3)
92+
{
93+
continue;
94+
}
95+
cards[i] += 3;
96+
}
97+
else
98+
{
99+
int index = i - 9;
100+
if (cards[index] > 5 || cards[index + 1] > 5 || cards[index + 2] > 5)
101+
{
102+
continue;
103+
}
104+
cards[index] += 1;
105+
cards[index + 1] += 1;
106+
cards[index + 2] += 1;
107+
}
108+
109+
parse_table(cards, eye);
110+
if (level < 4)
111+
{
112+
gen_auto_table_sub(cards, level + 1, eye);
113+
}
114+
115+
if (i <= 8)
116+
{
117+
cards[i] -= 3;
118+
}
119+
else
120+
{
121+
int index = i - 9;
122+
cards[index] -= 1;
123+
cards[index + 1] -= 1;
124+
cards[index + 2] -= 1;
125+
}
126+
}
127+
}
128+
129+
static void gen_eye_table()
130+
{
131+
int[] cards = new int[34];
132+
for (int i = 0 ; i < 34 ; ++i)
133+
{
134+
cards[i] = 0;
135+
}
136+
137+
for (int i = 0 ; i < 9 ; ++i)
138+
{
139+
System.out.println("jiang");
140+
cards[i] = 2;
141+
parse_table(cards, true);
142+
gen_auto_table_sub(cards, 1, true);
143+
cards[i] = 0;
144+
}
145+
}
146+
147+
public static void main(String[] args)
148+
{
149+
System.out.println("test single color begin...");
150+
init_cache();
151+
gen_eye_table();
152+
}
153+
}

mjlib_java/split/main.class

1.01 KB
Binary file not shown.

mjlib_java/split/main.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
public class main {
2+
public static void test_success() {
3+
int[] cards = {
4+
1,1,0,0,1,0,1,0,0,
5+
0,0,0,2,4,2,0,0,0,
6+
0,0,0,0,0,0,0,0,0,
7+
0,0,0,0,0,0,2
8+
};
9+
10+
if(split.get_hu_info(cards, 34, 33)){
11+
System.out.println("test success");
12+
}
13+
}
14+
15+
public static void test_fail() {
16+
int[] cards = {
17+
1,1,0,0,1,0,1,0,0,
18+
0,0,0,2,4,2,1,0,0,
19+
0,0,0,0,0,0,0,0,0,
20+
0,0,0,0,0,0,1
21+
};
22+
23+
if(!split.get_hu_info(cards, 34, 33)){
24+
System.out.println("test success");
25+
}
26+
}
27+
28+
public static void main(String[] args) {
29+
// TODO Auto-generated method stub
30+
test_success();
31+
test_fail();
32+
}
33+
34+
}

mjlib_java/split/split.class

2.83 KB
Binary file not shown.

0 commit comments

Comments
 (0)