Skip to content

Commit

Permalink
增加java版选将拆分法
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanfengyun committed Nov 13, 2017
1 parent c9cd895 commit b0c02c3
Show file tree
Hide file tree
Showing 28 changed files with 673 additions and 1 deletion.
6 changes: 5 additions & 1 deletion mjlib_java/readme.txt
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
由网友ak翻译过来。
split 选将拆分法

table 查表法

查表法由网友ak翻译过来
153 changes: 153 additions & 0 deletions mjlib_java/split/logic.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import java.util.HashMap;

public class logic
{
static Boolean check__yitiaolong(int[] cards, int gui_num, Boolean eye)
{
int key = 0;

for (int i = 0 ; i < 9 ; i++)
{
key = key * 10 + cards[i];
}

if (key == 0)
{
return false;
}

HashMap<Integer, Boolean> m;
if (!eye)
{
m = gui_tested[gui_num];
}
else
{
m = gui_eye_tested[gui_num];
}

if (m.containsKey(key))
{
return false;
}

m.put(key, true);

for (int i = 0 ; i < 9 ; i++)
{
if (cards[i] > 4)
{
return true;
}
test_cards[i] = cards[i];
}
test_cards[33] = gui_num;
if(!split.get_hu_info(test_cards, 34, 33)){
System.out.println("error: cant't hu");
}
return true;
}

static void parse_table_sub(int[] cards, int num, boolean eye)
{
for (int i = 0 ; i < 9 ; i++)
{
if (cards[i] == 0)
{
continue;
}

cards[i]--;

if (!check_add(cards, num, eye))
{
cards[i]++;
continue;
}

if (num < 4)
{
parse_table_sub(cards, num + 1, eye);
}
cards[i]++;
}
}

static void parse_table(int[] cards, boolean eye)
{
if (!check_add(cards, 0, eye))
{
return;
}
parse_table_sub(cards, 1, eye);
}

static void gen_auto_table_sub(int[] cards, int level, boolean eye)
{
for (int i = 0 ; i < 16 ; ++i)
{
if (i <= 8)
{
if (cards[i] > 3)
{
continue;
}
cards[i] += 3;
}
else
{
int index = i - 9;
if (cards[index] > 5 || cards[index + 1] > 5 || cards[index + 2] > 5)
{
continue;
}
cards[index] += 1;
cards[index + 1] += 1;
cards[index + 2] += 1;
}

parse_table(cards, eye);
if (level < 4)
{
gen_auto_table_sub(cards, level + 1, eye);
}

if (i <= 8)
{
cards[i] -= 3;
}
else
{
int index = i - 9;
cards[index] -= 1;
cards[index + 1] -= 1;
cards[index + 2] -= 1;
}
}
}

static void gen_eye_table()
{
int[] cards = new int[34];
for (int i = 0 ; i < 34 ; ++i)
{
cards[i] = 0;
}

for (int i = 0 ; i < 9 ; ++i)
{
System.out.println("jiang");
cards[i] = 2;
parse_table(cards, true);
gen_auto_table_sub(cards, 1, true);
cards[i] = 0;
}
}

public static void main(String[] args)
{
System.out.println("test single color begin...");
init_cache();
gen_eye_table();
}
}
Binary file added mjlib_java/split/main.class
Binary file not shown.
34 changes: 34 additions & 0 deletions mjlib_java/split/main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
public class main {
public static void test_success() {
int[] cards = {
1,1,0,0,1,0,1,0,0,
0,0,0,2,4,2,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,2
};

if(split.get_hu_info(cards, 34, 33)){
System.out.println("test success");
}
}

public static void test_fail() {
int[] cards = {
1,1,0,0,1,0,1,0,0,
0,0,0,2,4,2,1,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,1
};

if(!split.get_hu_info(cards, 34, 33)){
System.out.println("test success");
}
}

public static void main(String[] args) {
// TODO Auto-generated method stub
test_success();
test_fail();
}

}
Binary file added mjlib_java/split/split.class
Binary file not shown.
Loading

0 comments on commit b0c02c3

Please sign in to comment.