资源简介
麻将胡牌算法以及AI算法,麻将AlphaGo,java代码,可直接运行
代码片段和文件信息
package com.github.esrrhs.majiang_algorithm;
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
public class AICommon
{
public static ConcurrentHashMap> table;
public static int N;
public static String NAME;
public static String[] CARD;
public static boolean huLian;
public static double baseP;
public static final int LEVEL = 5;
public static void main(String[] args)
{
AICommon.table = new ConcurrentHashMap<>();
AICommon.N = 9;
AICommon.NAME = “normal“;
AICommon.CARD = AITable.names;
AICommon.huLian = true;
AICommon.baseP = 36.d / 136;
HashMap> tmpcards = new HashMap<>();
for (int inputNum = 0; inputNum <= LEVEL; inputNum++)
{
int[] tmpnum = new int[N];
HashSet tmpcard = new HashSet<>();
gen_card(tmpcard tmpnum 0 inputNum);
tmpcards.put(inputNum tmpcard);
}
long key = 20110000;
check_ai(key tmpcards);
try
{
File file = new File(“majiang_ai_“ + NAME + “.txt“);
if (file.exists())
{
file.delete();
}
file.createNewFile();
FileOutputStream out = new FileOutputStream(file true);
output(key out);
out.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static void gen()
{
final HashSet card = new HashSet<>();
for (int i = 0; i <= 14; i++)
{
int[] num = new int[N];
gen_card(card num 0 i);
}
HashMap> tmpcards = new HashMap<>();
for (int inputNum = 0; inputNum <= LEVEL; inputNum++)
{
int[] tmpnum = new int[N];
HashSet tmpcard = new HashSet<>();
gen_card(tmpcard tmpnum 0 inputNum);
tmpcards.put(inputNum tmpcard);
}
System.out.println(card.size());
try
{
File file = new File(“majiang_ai_“ + NAME + “.txt“);
if (file.exists())
{
file.delete();
}
file.createNewFile();
final FileOutputStream out = new FileOutputStream(file true);
ExecutorService fixedThreadPool = Executors.newFixedThreadPool(8);
final long begin = System.currentTimeMillis();
final AtomicInteger i = new AtomicInteger(0);
for (final long l : card)
{
fixedThreadPool.execute(new Runnable() {
public void run()
{
try
{
check_ai(l tmpcards);
output(l out);
i.addAndGet(1);
long now = System.currentTimeMillis();
float per = (float) (now - begin) / i.intValue();
synchronized (AICommon.class)
{
System.out.println((float) i.intValue() / card.size() + “ 需要“
+ per * (card.size() - i.intValue()) / 60 / 1000 + “分“ + “ 用时“
+ (now - begin) / 60 / 1000 + “分“ + “ 速度“
+ i.intValue() / ((float) (now - begin) / 1000) + “条/秒“);
}
}
catch (Exception e)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-10-16 09:48 majiang_algorithm-master\
文件 208 2018-10-16 09:48 majiang_algorithm-master\README.md
文件 7044 2018-10-16 09:48 majiang_algorithm-master\ai.md
文件 108 2018-10-16 09:48 majiang_algorithm-master\deploy.bat
文件 5827 2018-10-16 09:48 majiang_algorithm-master\hu.md
目录 0 2018-10-16 09:48 majiang_algorithm-master\img\
文件 39040 2018-10-16 09:48 majiang_algorithm-master\img\ai1.png
文件 64530 2018-10-16 09:48 majiang_algorithm-master\img\ai2.png
文件 72236 2018-10-16 09:48 majiang_algorithm-master\img\ai3.png
文件 29278 2018-10-16 09:48 majiang_algorithm-master\img\ai4.png
文件 44054 2018-10-16 09:48 majiang_algorithm-master\img\ai5.png
文件 59293 2018-10-16 09:48 majiang_algorithm-master\img\ai6.png
文件 44919 2018-10-16 09:48 majiang_algorithm-master\img\bianma.png
文件 89925 2018-10-16 09:48 majiang_algorithm-master\img\bianmada.png
文件 43176 2018-10-16 09:48 majiang_algorithm-master\img\feng.png
文件 57473 2018-10-16 09:48 majiang_algorithm-master\img\gui.png
文件 122681 2018-10-16 09:48 majiang_algorithm-master\img\hu.png
文件 30196 2018-10-16 09:48 majiang_algorithm-master\img\jian.png
文件 26575 2018-10-16 09:48 majiang_algorithm-master\img\jiang.png
文件 41439 2018-10-16 09:48 majiang_algorithm-master\img\kezi.png
文件 35462 2018-10-16 09:48 majiang_algorithm-master\img\lianzi.png
文件 1277968 2018-10-16 09:48 majiang_algorithm-master\img\readme.png
文件 109383 2018-10-16 09:48 majiang_algorithm-master\img\ting.png
文件 25464 2018-10-16 09:48 majiang_algorithm-master\img\tingde.png
文件 100190 2018-10-16 09:48 majiang_algorithm-master\img\wan.png
文件 31154176 2018-10-16 09:48 majiang_algorithm-master\majiang.db
文件 72126 2018-10-16 09:48 majiang_algorithm-master\majiang_ai_feng.txt
文件 13422 2018-10-16 09:48 majiang_algorithm-master\majiang_ai_jian.txt
文件 87398052 2018-10-16 09:48 majiang_algorithm-master\majiang_ai_normal.txt
文件 23373 2018-10-16 09:48 majiang_algorithm-master\majiang_clien_feng.txt
文件 4460 2018-10-16 09:48 majiang_algorithm-master\majiang_clien_jian.txt
............此处省略27个文件信息
评论
共有 条评论