robot_zuixin/libs/robot_common_bak/src/test/java/Test.java

658 lines
29 KiB
Java
Raw Normal View History

2026-07-06 21:00:10 +08:00
import com.taurus.core.plugin.PluginService;
import hunan.DoTest;
import hunan.JiQiRens;
import taurus.client.NetManager;
//import java.sql.SQLException;
//import java.util.ArrayList;
//import java.util.List;
//
//import com.game.Util;
//import com.taurus.core.entity.ITArray;
//import com.taurus.core.entity.ITObject;
//import com.taurus.core.entity.TObject;
//import com.taurus.core.events.Event;
//import com.taurus.core.events.IEventListener;
//import com.taurus.core.plugin.PluginService;
//import com.taurus.core.plugin.database.DataBase;
//import com.taurus.core.plugin.redis.Redis;
//import com.taurus.core.util.ICallback;
//import com.taurus.core.util.StringUtil;
//
//import hunan.*;
////import taurus.algorithm.HongZhongSuanFa;
////import taurus.algorithm.PaoDeKuaiSuanFa;
//import redis.clients.jedis.Jedis;
//import taurus.client.Message;
//import taurus.client.MessageResponse;
//import taurus.client.NetManager;
//import taurus.client.SocketCode;
//import taurus.client.TaurusClient;
//import taurus.client.TaurusClient.ConnectionProtocol;
//import taurus.client.TaurusClient.NetClientEvent;
//import taurus.client.business.AccountBusiness;
//import taurus.client.business.GroupRoomBusiness;
//import taurus.util.CardObj;
//import taurus.util.CardUtil;
//import taurus.util.GroupData;
//import taurus.util.PaoDeKuaiSuanFaTest;
//
public class Test {
// // 扣点点玩家手牌
// public static List<Integer> cardInhand = new ArrayList<Integer>();
//
//
////
//// //跑得快算法
//// private static PaoDeKuaiSuanFa paoDeKuaiSuanFa;
//
// //红中其它玩家打的牌
//// public static String hongZhongCard = "";
//
// //扣点点别人打的牌
// public static String card = "";
//
//
// // 玩家座位号
// public static int seat = 0;
// // 玩家ID
// public static int playerId = 0;
// // 登录密码
// public static String password = "123456";
// // 会话标识
// public static String session = "";
// // 访问令牌
// public static String token = "";
// // 玩法ID
// public static String wanfaId = "";
//
// // 客户端连接对象
// public static TaurusClient client = null;
//
// public static TObject datas = null;
//
// //圈子id
// public static int groupId = 0;
//
// //房间id
// public static String roomId = "";
//
// public static int count = 0;
//
// static final void get() {
// TObject data = GroupData.getData();
// datas = data;
// }
//
//
// /**
// * TCP测试方法用于建立客户端连接并处理游戏事件
// *
// * @throws Exception
// */
// static final void tcp_test() throws Exception {
// get();
// if (datas.size() != 0) {
// ITArray rooid = datas.getTArray("rooid"); //房间id
// ITArray robotIds = datas.getTArray("robotIds"); //机器人账号
// ITArray groupid = datas.getTArray("groupid"); //圈子id
//
// for (int i = 0; i < groupid.size(); i++) {
// groupId = groupid.getInt(i);
// break;
// }
//
// ITObject object = null;
// AccountBusiness accountBusiness = null;
// //房间id
// accountBusiness = new AccountBusiness();
// //用户 查找需要的房间数量,然后用户循环次数是根据房间数量循环的
// for (int j = 0; j < rooid.size(); j++) {
// for (count = count; count < robotIds.size(); ) {
// Integer anInt = rooid.getInt(j);
// roomId = String.valueOf(anInt);
// playerId = robotIds.getInt(count);
// // 登录获取session跟token
// object = accountBusiness.idPasswordLogin(playerId, password);
// ITObject validate = TObject.newInstance();
// //修改使用过的机器人账号标识为1 已使用
// String sql = String.format("UPDATE `account` SET start = %d WHERE id = %d", 1, playerId);
// DataBase.use().executeUpdate(sql);
// validate.putString("token", object.getString("token"));
// token = object.getString("token");
// session = accountBusiness.getSession();
// System.out.println(session + "," + object.getString("token"));
// // group进入房间
// ITObject roomInfo = GroupRoomBusiness.joinRoom(groupId, roomId, session, null);
// //根据房间id获取 玩法
// Jedis jedis0 = Redis.use("group1_db0").getJedis();
// wanfaId = jedis0.hget("room:" + roomId, "game");
// System.out.println("wanfaId 12223 " + wanfaId);
// //连接根据不同的玩法id 配置不同的连接
// if ("22".equalsIgnoreCase(wanfaId)) { //湖南红中麻将
// client = new TaurusClient("8.138.120.167:46421", "game", ConnectionProtocol.Tcp);
// }
// if ("66".equalsIgnoreCase(wanfaId)) { //跑的快
// client = new TaurusClient("8.138.120.167:46841", "game", ConnectionProtocol.Tcp);
// }
//
// if ("17".equalsIgnoreCase(wanfaId)) { //字牌 放炮罚
// client = new TaurusClient("8.138.120.167:48017", "game", ConnectionProtocol.Tcp);
// }
// if ("108".equalsIgnoreCase(wanfaId)) { //转转麻将
// client = new TaurusClient("8.138.120.167:46331", "game", ConnectionProtocol.Tcp);
// }
// client.connect();
// // 添加事件监听器处理网络消息
// client.addEventListener(NetClientEvent.OnEvent, new IEventListener() {
// @Override
// public void handleEvent(Event event) {
// // 获取 msg
// Message message = (Message) event.getParameter("msg");
// if (message == null) {
// return;
// }
// ITObject param = message.param;
//// if (param == null) { 部分协议 param为空
//// return;
//// }
// //回调协议号
// String command = message.command;
// //根据玩法id 调用不同的回调
// if (StringUtil.isNotEmpty(command)) {
// if ("93".equalsIgnoreCase(wanfaId)) { //扣点点
// if ("812".equalsIgnoreCase(command)) { //出牌广播
// sleepTime(1000);
// drawCard(command, message);
// } else if ("820".equalsIgnoreCase(command)) {
// changePlayer(command, message);
// } else if ("819".equalsIgnoreCase(command)) { //摸牌
// getCard(command, message);
// } else if ("811".equalsIgnoreCase(command)) { //初始化手牌
// cardInHead(command, message, wanfaId);
// } else if ("813".equalsIgnoreCase(command)) { //出牌,牌权
// sleepTime(2000);
// outCard(command, message, wanfaId);
// } else if ("817".equalsIgnoreCase(command)) {
// ready();
// //杠碰胡通知协议
// } else if ("814".equalsIgnoreCase(command)) {
// sleepTime(2000);
// actionCard(param);
// //doGang杠后补牌 补杠事件
// } else if ("838".equalsIgnoreCase(command)) {
// System.out.println("杠后补牌 补杠事件");
// sleepTime(2000);
// buGang(param);
// }
// } else if ("66".equalsIgnoreCase(wanfaId)) {//跑的快
// System.out.println("command" + command);
// if ("2011".equalsIgnoreCase(command)) { //跑的快 初始化手牌
// HuNanPaoDeKuai.paoDeKuaiCardInHead(param, client);
// } else if ("2021".equalsIgnoreCase(command)) { //出牌广播
// HuNanPaoDeKuai.paoDekuaiChupaiGuangBo(param);
// } else if ("2004".equalsIgnoreCase(command)) { //出牌提示事件,牌权
// //出牌
// HuNanPaoDeKuai.outCard(client);
// } else if ("2007".equalsIgnoreCase(command)) { //结算准备
// HuNanPaoDeKuai.seatRemainHistory.clear();
// HuNanPaoDeKuai.paoDekuaiCardInhand.clear();
// ITArray card_list = HuNanPaoDeKuai.card_list.getTArray("card_list");
// card_list.clear();
// ready();
// } else if ("2009".equalsIgnoreCase(command)) {
// ready();
// }
// } else if ("22".equalsIgnoreCase(wanfaId)) { //湖南红中麻将
// System.out.println("command" + command);
// if ("812".equalsIgnoreCase(command)) { //出牌广播
// sleepTime(1000);
// HuNanHongZhong.drawCard(command, message);
// } else if ("811".equalsIgnoreCase(command)) {//初始化手牌
// HuNanHongZhong.cardInHead(command, message, client);
// } else if ("819".equalsIgnoreCase(command)) { //摸牌
// HuNanHongZhong.getCard(command, message);
// } else if ("813".equalsIgnoreCase(command)) { //出牌,牌权
//// sleepTime(2000);
// HuNanHongZhong.outCard(client);
// } else if ("817".equalsIgnoreCase(command)) {//结算
// HuNanHongZhong.hongZhongCardInhand.clear();
// HuNanHongZhong.hongZhongchuguopai.clear();
// System.out.println("结算");
// ready();
// } else if ("814".equalsIgnoreCase(command)) {//杠碰胡通知协议
//// sleepTime(2000);
// HuNanHongZhong.actionCard(param, client);
// } else if ("820".equalsIgnoreCase(command)) {
// HuNanHongZhong.changePlayer(command, message);
// } else if ("815".equalsIgnoreCase(command)) { //服务器通知客户端有玩家执行了操作
// HuNanHongZhong.shanchuchuguopai(param);
// } else if ("2008".equalsIgnoreCase(command)) { //解散房间时候恢复机器人账号可以使用
// try {
// String sql = String.format("UPDATE `account` SET start = %d WHERE id = %d", 0, playerId);
// DataBase.use().executeUpdate(sql);
// System.out.println("恢复机器人账户 --------");
// } catch (SQLException e) {
// System.out.println(e);
// }
// }
// } else if ("17".equalsIgnoreCase(wanfaId)) { //字牌放炮罚
// System.out.println("放炮罚command " + command);
// if ("811".equalsIgnoreCase(command)) { //初始化手牌
// HuNanFangPaoFa.cardInHead(command, message, client);
// System.out.println("字牌放炮罚 初始化手牌");
// } else if ("819".equalsIgnoreCase(command)) { //摸牌
// HuNanFangPaoFa.getCard(command, message);
// } else if ("813".equalsIgnoreCase(command)) { //出牌 牌权
// HuNanFangPaoFa.outCard(client);
// } else if ("812".equalsIgnoreCase(command)) { //出牌广播
// HuNanFangPaoFa.drawCard(command, message);
// } else if ("814".equalsIgnoreCase(command)) { //可执行的 操作 吃碰 偎提胡
// HuNanFangPaoFa.actionCard(param, client);
// } else if ("817".equalsIgnoreCase(command)) { //结算
// HuNanFangPaoFa.fangPaoFaCardInhand.clear();
// ready();
// } else if ("822".equalsIgnoreCase(command)) { //放跑提示
// System.out.println("放跑提示");
// HuNanFangPaoFa.fangPaoTipEvent(message, client);
// }
// } else if ("108".equalsIgnoreCase(wanfaId)) {//转转麻将
// if ("811".equalsIgnoreCase(command)) {//初始化收手牌
// HuNanZhuanZhuan.cardInHead(command, message, client);
// } else if ("812".equalsIgnoreCase(command)) {//出牌广播
// HuNanZhuanZhuan.drawCard(command, message);
// } else if ("819".equalsIgnoreCase(command)) {//摸牌
// HuNanZhuanZhuan.getCard(command, message);
// } else if ("813".equalsIgnoreCase(command)) {//出牌提示
// HuNanZhuanZhuan.outCard(client);
// } else if ("814".equalsIgnoreCase(command)) {//放招提示
// HuNanZhuanZhuan.actionCard(param, client);
// } else if ("817".equalsIgnoreCase(command)) {//结算
// HuNanZhuanZhuan.zhuanZhuanCardInhand.clear();
// HuNanZhuanZhuan.zhuanZhuanchuguopai.clear();
// ready();
// } else if ("815".equalsIgnoreCase(command)) { //服务器通知客户端有玩家执行了操作
// HuNanZhuanZhuan.shanchuchuguopai(param);
// } else if ("820".equalsIgnoreCase(command)) {//换牌提示
// HuNanZhuanZhuan.changePlayer(command, message);
// }
// }
// }
// }
// });
// // 添加连接状态监听器
// client.addEventListener(NetClientEvent.Connect, new IEventListener() {
// @Override
// public void handleEvent(Event event) {
// SocketCode code = (SocketCode) event.getParameter("code");
// if (code == SocketCode.Connect) {
// System.out.println("连接成功");
// } else {
// System.out.println("连接失败");
//
// }
// }
// });
// ITObject params = TObject.newInstance();
// params.putString("session", session + "," + object.getString("token"));
//
// joinRoom(); //进入房间
// System.out.println(566666);
// ready(); //准备
// ++count;
// break;
// }
// }
// }
//
// }
//
//
// /**
// * 出牌广播协议 812
// *
// * @param command 协议号
// * @param message 消息对象
// * @return
// */
// public static String drawCard(String command, Message message) {
// if (command.equalsIgnoreCase("812")) {
// ITObject param = message.param;
// if (param == null) {
// return null;
// }
// card = param.getString("card");
// System.out.println("座位号:" + param.getInt("seat") + "的用户出牌:" + param.getInt("card"));
// }
// return null;
// }
//
// /**
// * 位置转换协议 820
// *
// * @param command 协议号
// * @param message 消息对象
// * @return
// */
// public static String changePlayer(String command, Message message) {
// if (command.equalsIgnoreCase("820")) {
// ITObject param = message.param;
// if (param == null) {
// return null;
// }
// System.out.println("出牌权转移到座位号:" + param.getInt("seat") + "的用户");
//// {seat=2}
//
// }
// return null;
// }
//
// /**
// * 摸牌协议 819
// *
// * @param command 协议号
// * @param message 消息对象
// * @return
// */
// public static String getCard(String command, Message message) {
// if (command.equalsIgnoreCase("819")) {
// ITObject param = message.param;
// if (param == null) {
// return null;
// }
//// {seat=2, Ishupai=0, isBaoTing=-1, tingcard=0, isgang=0, card=101, left_count=106}
// System.out.println("轮到座位号:" + param.getInt("seat") + "的用户摸牌" + ",牌为:" + param.getInt("card"));
// if (param.getInt("seat") != null && seat == param.getInt("seat")) {
// cardInhand.add(param.getInt("card"));
//// cardInhand.add(104);
// }
// }
// return null;
// }
//
// /**
// * 扣点点 初始化手牌协议 811
// *
// * @param command 协议号
// * @param message 消息对象
// * @param wanfaId 玩法ID
// * @return
// */
// public static String cardInHead(String command, Message message, String wanfaId) {
// if (command.equalsIgnoreCase("811")) {
// ITObject param = message.param;
// if (param == null) {
// return null;
// }
//// {bank_seat=1, laiziCard=0, laiziCard2=0, laiziCard2Before=0, jing=0, laiziCardBefore=0, card_list=[101, 103, 104, 201, 204, 207, 208, 209, 307, 309, 501, 502, 503]}
// ITArray cardList = param.getTArray("card_list");
// for (int i = 0; i < cardList.size(); i++) {
// cardInhand.add(cardList.getInt(i));
// }
// if (cardInhand.size() > 13) {
// outCard(command, message, wanfaId);
// System.out.println("机器人:" + param.getInt("seat") + "为庄家,需要出牌" + ",牌为:" + cardInhand.get(0));
//
// }
// System.out.println("机器人:" + param.getInt("seat") + "初始化手牌" + ",牌为:" + cardInhand.toString());
//
// }
// return null;
// }
//
// /**
// * 出牌方法
// *
// * @param command 协议号
// * @param message 消息对象
// * @param wanfaId 玩法ID
// * @return
// */
// public static String outCard(String command, Message message, String wanfaId) {
// //todo 根据房间的玩法id 调不同的业务服务 出牌 碰杠
//
//// String paoDeKuaiOutCard = paoDeKuaiSuanFa.paoDeKuaiOutCardSuanFa(cardInhand, card);//跑得快出牌
//// System.out.println("跑得快出牌" + paoDeKuaiOutCard);
//// if ("22".equalsIgnoreCase(wanfaId)) { //红中
//// String hongZhongOutCard = hongZhongSuanFa.hongZhongOutCardSuanFa(cardInhand, card); //红中出牌
//// System.out.println("红中出牌" + hongZhongOutCard);
//// }
//
//
// ITObject params = TObject.newInstance();
// params.putString("session", session + "," + token);
// params.putInt("card1", 0);
// params.putInt("card", cardInhand.get(0));
// cardInhand.remove(0);
// System.out.println("目前剩余手牌:" + cardInhand.toString());
// client.send("611", params, response -> {
// System.out.println("出牌成功: " + response.returnCode);
// });
// return null;
// }
//
// /**
// * 处理杠碰胡操作
// *
// * @param param 消息参数
// * @return
// */
// public static String actionCard(ITObject param) {
// //获取碰杠胡参数 type 和id 后续算法接入,是否能让碰和杠
// ITArray tipList = param.getTArray("tip_list");
// int id = 0;
// int type = 0;
// int opcard = 0;
// ITObject params = TObject.newInstance();
// if (tipList != null && tipList.size() > 0) {
// TObject firstTip = (TObject) tipList.get(0).getObject();
// id = firstTip.getInt("id");
// type = firstTip.getInt("type");
// opcard = firstTip.getTArray("opcard").getInt(0);
// System.out.println("id ++ " + id);
// System.out.println("type ++ " + type);
// }
// //弃 是根据算法选择是否要弃掉 不进行碰杠胡
// //params.putInt("qi", 0);
// //params.putInt("id", 0);
//
// //执行碰牌
// if (type == 2) {
// params.putString("session", session + "," + token);
// params.putInt("qi", 0);
// params.putInt("id", 1);
// Util.removeCard(cardInhand, opcard, 2);
// System.out.println("删除碰的牌");
//// Global.logger.info("删除碰的牌");
// //执行胡牌
// } else if (type == 6) {
// params.putString("session", session + "," + token);
// params.putInt("qi", 0);
// params.putInt("id", 1);
// System.out.println("执行胡牌");
// //执行吃杠
// } else if (type == 3) {
// params.putString("session", session + "," + token);
// params.putInt("qi", 0);
// params.putInt("id", 1);
// Util.removeCard(cardInhand, opcard, 3);
// System.out.println("执行吃杠");
// //执行自杠
// } else if (type == 4) {
// params.putString("session", session + "," + token);
// params.putInt("qi", 0);
// params.putInt("id", 1);
// Util.removeCard(cardInhand, opcard, 4);
// System.out.println("执行自杠");
// // 碰后补杠
// } else if (type == 5) {
// params.putString("session", session + "," + token);
// params.putInt("qi", 0);
// params.putInt("id", 1);
// Util.removeCard(cardInhand, opcard, 1);
// System.out.println("执行碰后补杠");
// }
//
//// cardInhand.remove(0);
//// cardInhand.remove(1);
// System.out.println("执行id为" + 0 + "的操作");
//
// client.send("612", params, response -> {
// System.out.println("操作成功: " + response.returnCode);
// });
// return null;
// }
//
// /**
// * 处理补杠操作
// *
// * @param param 消息参数
// */
// public static void buGang(ITObject param) {
// Integer card = param.getInt("card");
// ITObject params = TObject.newInstance();
// params.putInt("card", card);
// client.send("839", params, response -> {
// System.out.println("操作成功: " + response.returnCode);
// });
// }
//
//
// /**
// * 准备方法
// *
// * @return
// */
// public static String ready() {
// try {
// // 添加1秒延迟
// Thread.sleep(1000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// cardInhand = new ArrayList<Integer>();
// HuNanHongZhong.hongZhongCardInhand();
// HuNanFangPaoFa.fangPaoFaCardInhand();
// System.out.println("准备1111");
// ITObject params = TObject.newInstance();
// params.putString("session", session + "," + token);
//
// client.send("1003", params, new ICallback<MessageResponse>() {
//
// @Override
// public void action(MessageResponse messageResponse) {
// System.out.println("准备成功: ");
//
// System.out.println(messageResponse);
// System.out.println(messageResponse.returnCode);
// System.out.println(messageResponse.messageData.param);
// }
// });
// return null;
// }
//
// /**
// * 加入房间方法
// *
// * @return
// */
// public static String joinRoom() {
// try {
// // 添加2秒延迟
// Thread.sleep(5000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// ITObject params = TObject.newInstance();
// params.putString("session", session + "," + token);
//
// System.out.println("进入房间");
// client.send("1002", params, response -> {
// System.out.println("进入房间成功: " + response.returnCode);
// System.out.println(response.returnCode);
// System.out.println(response.messageData.param);
// ITObject obj = response.messageData.param.getTObject("tableInfo");
//
// ITArray array = obj.getTArray("playerData");
// for (int i = 0; i < array.size(); i++) {
// System.out.println("座位准备" + array.getTObject(i).getInt("seat"));
// if (playerId == array.getTObject(i).getInt("aid")) {
//// seat = array.getTObject(i).getInt("seat");
// HuNanHongZhong.seat = array.getTObject(i).getInt("seat"); //湖南红中麻将
// HuNanZhuanZhuan.seat = array.getTObject(i).getInt("seat"); //湖南转转麻将
// HuNanFangPaoFa.seat = array.getTObject(i).getInt("seat"); //字牌放炮罚
// HuNanPaoDeKuai.seat = array.getTObject(i).getInt("seat"); //跑得快
//
// }
// }
// });
// return null;
// }
//
// /**
// * 线程休眠方法
// *
// * @param time 休眠时间(毫秒)
// */
// public static void sleepTime(int time) {
// try {
// // 添加延迟
// Thread.sleep(time);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// }
//
/**
*
*
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
try {
PluginService.me().loadConfig();
} catch (Exception e1) {
e1.printStackTrace();
}
DoTest doTest = new DoTest();
doTest.doTest();
while (true) {
NetManager.processEvents();
try {
Thread.sleep(8);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
// public static void main(String[] args) {
// HuNanHongZhong HuNanHongZhong = new HuNanHongZhong();
// HongZhongSuanFaTest hongZhongSuanFaTest = new HongZhongSuanFaTest();
// String s = HuNanHongZhong.outCard(null,Arrays.asList(302,305,305,303,302,301,203,203,202,202,101,101,412,412));
//// hongZhongSuanFaTest.analyzeDrawCard(Arrays.asList(305,304,303,207,205,204,202,107,107,104,104,412,412), 208);
//// Boolean s = HuNanHongZhong.shouldPong(207);
//// hongZhongSuanFaTest.separateAndAnalyzeHand(Arrays.asList(101, 101, 101, 102, 103, 204, 204, 206, 209, 303, 305, 306, 306, 208));
//// System.out.println(s);
// }
// public static void main(String[] args) {
// JiQiRens jiQiRens = new JiQiRens();
// try {
// jiQiRens.tcp_test(1, 11, 1);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
}
//// ... existing code ...