diff --git a/.gitignore b/.gitignore index 92049cb..f0042ad 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.[oa] +*.log core robot_client robot_server diff --git a/robot_client/AIUtils.cpp b/robot_client/AIUtils.cpp index 53e0ba5..a0cc9af 100644 --- a/robot_client/AIUtils.cpp +++ b/robot_client/AIUtils.cpp @@ -1,6 +1,7 @@ #include - +#include #include "AIUtils.h" +#include "log.h" using namespace std; @@ -1749,14 +1750,16 @@ void AIUtils::handToPointsArray( Hand &hand, int points[CARD_POINT_NUM] ) void AIUtils::printPoints( int points[CARD_POINT_NUM], char endChar ) { + stringstream sstream; for (int i = 0; i < CARD_POINT_NUM; ++i) { for (int j = 0; j < points[i]; ++j) { - cout << POINT_CHAR[i]; + sstream << POINT_CHAR[i]; } } - cout << endChar; + sstream << endChar; + DEBUG("card info: %s", sstream.str().c_str()); } void AIUtils::printHand( Hand &hand ) @@ -1784,7 +1787,6 @@ void AIUtils::printCardInfo( vector& vecContent ) int points[CARD_POINT_NUM] = {0}; cardVecToPointArr(vecContent, points); printPoints(points, ' '); - cout << endl; } int AIUtils::getHandCount( Hand &hand ) diff --git a/robot_client/AbstractProduct.cpp b/robot_client/AbstractProduct.cpp index b507e29..1adefdb 100644 --- a/robot_client/AbstractProduct.cpp +++ b/robot_client/AbstractProduct.cpp @@ -5,6 +5,8 @@ #include "connect.pb.h" #include "org_room2client.pb.h" #include "message.pb.h" +#include "log.h" +#include using namespace PBGameDDZ; using namespace YLYQ; @@ -14,62 +16,46 @@ using namespace message; using namespace org_room2client; using namespace AIUtils; -AbstractProduct::AbstractProduct(){ -} - - -AbstractProduct::~AbstractProduct(){ +void sleep_ms( unsigned int secs ) +{ + struct timeval tval; + tval.tv_sec = secs / 1000; + tval.tv_usec = (secs * 1000) % 1000000; + select(0, NULL ,NULL, NULL, &tval); } //请求认证回应 -GetVerifyAckInfo::GetVerifyAckInfo(){ -} - - -GetVerifyAckInfo::~GetVerifyAckInfo(){ -} - - -string GetVerifyAckInfo::operation( OGLordRobotAI& robot, const string& msg ){ +bool GetVerifyAckInfo::operation( OGLordRobotAI& robot, const string& msg, string& serializedStr ){ //message VerifyAck { // required int32 result = 1; // optional string gameName = 2; // 如果正在游戏中,返回游戏名称,客户端进行初始化,自动快速开始 //} - string serializedStr; VerifyAck verifyAck; if (!verifyAck.ParseFromString(msg)) { - cout << "parse verify ack pb message error." << endl; - return serializedStr; + ERROR("parse verify ack pb message error."); + //cout << "parse verify ack pb message error." << endl; + return false; } int result = verifyAck.result(); if (message::SUCCESS == result) { //认证成功,开始初始化游戏 robot.SetStatus(VERIFIED); - cout << "Robot " << robot.GetRobotId() << " Verify successed, result is: " << result << ", robot status is: " << robot.GetStatus() << endl; + DEBUG("Robot %d verify successed, result is: %d.", robot.GetRobotId(), robot.GetStatus()); } else { - cout << "Robot " << robot.GetRobotId() << " Verify failed, result is: " << result << endl; + DEBUG("Robot %d verify failed, result is: %d.", robot.GetRobotId(), result); } - return serializedStr; + return false; } //初始化游戏回应 -GetInitGameAckInfo::GetInitGameAckInfo(){ -} - - -GetInitGameAckInfo::~GetInitGameAckInfo(){ -} - - -string GetInitGameAckInfo::operation( OGLordRobotAI& robot, const string& msg ){ +bool GetInitGameAckInfo::operation( OGLordRobotAI& robot, const string& msg, string& serializedStr ){ //message InitGameAck { // required int32 result = 1; //} - string serializedStr; InitGameAck initGameAck; initGameAck.ParseFromString(msg); int result = initGameAck.result(); @@ -77,23 +63,17 @@ string GetInitGameAckInfo::operation( OGLordRobotAI& robot, const string& msg ){ { //初始化成功,开始查询报名条件 robot.SetStatus(INITGAME); - cout << "Robot " << robot.GetRobotId() << " Game Init successed, result is: " << result << ", robot status is: " << robot.GetStatus() << endl; + DEBUG("Robot %d Game Init successed, robot status is: %d.", robot.GetRobotId(), robot.GetStatus()); } else { - cout << "Robot " << robot.GetRobotId() << " Game Init failed, result is: " << result << endl; + DEBUG("Robot %d Game Init failed, result is: %d.", robot.GetRobotId(), result); } - return serializedStr; + return false; } //查询报名条件 -GetSignUpCondAckInfo::GetSignUpCondAckInfo(){ -} - -GetSignUpCondAckInfo::~GetSignUpCondAckInfo(){ -} - -string GetSignUpCondAckInfo::operation( OGLordRobotAI& robot, const string& msg ){ +bool GetSignUpCondAckInfo::operation( OGLordRobotAI& robot, const string& msg, string& serializedStr ){ //message OrgRoomDdzSignUpConditionAck { // required int32 result = 1; // message Limit { @@ -113,28 +93,26 @@ string GetSignUpCondAckInfo::operation( OGLordRobotAI& robot, const string& msg // optional int32 startSignUpTime = 6; // 开始报名时间, time_t // optional int32 endSignUpTime = 7; // 结束报名时间, time_t //} - string serializedStr; OrgRoomDdzSignUpConditionAck orgRoomDdzSignUpConditionAck; orgRoomDdzSignUpConditionAck.ParseFromString(msg); int result = orgRoomDdzSignUpConditionAck.result(); if (message::SUCCESS != result) { - cout << "Robot " << robot.GetRobotId() << " Sign up condition failed, result is: " << result << ", robot status is: " << robot.GetStatus() << endl; - return serializedStr; + DEBUG("Robot %d sign up condition failed, result is: %d.", robot.GetRobotId(), result); + return false; } if (!orgRoomDdzSignUpConditionAck.has_limit()) { - cout << "Robot " << robot.GetRobotId() << " Can sign up for free." << endl; + DEBUG("Robot %d can sign up for free.", robot.GetRobotId()); robot.SetCost(0); robot.SetStatus(CANSINGUP); - return serializedStr; } else { bool cond = orgRoomDdzSignUpConditionAck.limit().enable(); if (cond) { - cout << "Robot " << robot.GetRobotId() << " Can sign up." << endl; + DEBUG("Robot %d can sign up.", robot.GetRobotId()); robot.SetStatus(CANSINGUP); int costSize = orgRoomDdzSignUpConditionAck.costlist_size(); int index = 0; @@ -143,33 +121,25 @@ string GetSignUpCondAckInfo::operation( OGLordRobotAI& robot, const string& msg if (orgRoomDdzSignUpConditionAck.costlist(index).enable()) { robot.SetCost(orgRoomDdzSignUpConditionAck.costlist(index).id()); - cout << "Found enable cost in costlist, id is: " << robot.GetCost() << endl; + DEBUG("Found enable cost in costlist, id is: %d.", robot.GetCost()) break; } } if (costSize == index) { - cout << "Doesn't found enable cost in costlist." << endl; + ERROR("Doesn't found enable cost in costlist."); } - return serializedStr; } else { - cout << "Robot " << robot.GetRobotId() << " Cann't sign up." << endl; - return serializedStr; + DEBUG("Robot %d cann't sign up.", robot.GetRobotId()); } } - + return false; } //报名结果回应 -GetSignUpAckInfo::GetSignUpAckInfo(){ -} - -GetSignUpAckInfo::~GetSignUpAckInfo(){ -} - -string GetSignUpAckInfo::operation(OGLordRobotAI & robot, const string & msg){ +bool GetSignUpAckInfo::operation( OGLordRobotAI & robot, const string & msg, string& serializedStr ){ //message OrgRoomDdzSignUpAck { // required int32 result = 1; // message CostGoods { @@ -179,7 +149,6 @@ string GetSignUpAckInfo::operation(OGLordRobotAI & robot, const string & msg){ // repeated CostGoods costList = 2; // optional int32 userCount = 3; // 已报名人数 //} - string serializedStr; OrgRoomDdzSignUpAck orgRoomDdzSignUpAck; orgRoomDdzSignUpAck.ParseFromString(msg); int result = orgRoomDdzSignUpAck.result(); @@ -187,28 +156,18 @@ string GetSignUpAckInfo::operation(OGLordRobotAI & robot, const string & msg){ { //报名成功,开始等待游戏 robot.SetStatus(SIGNUPED); - cout << "Robot " << robot.GetRobotId() << " Sign up succssed, result is: " << result << ", robot status is: " << robot.GetStatus() << endl; + DEBUG("Robot %d sign up succssed, robot status is: %d.", robot.GetRobotId(), robot.GetStatus()); } else { - cout << "Robot " << robot.GetRobotId() << " Sign up failed, result is: " << result << endl; + DEBUG("Robot %d sign up failed, result is: %d.", robot.GetRobotId(), result); } - return serializedStr; + return false; } - - /*++++++++++++++++++游戏阶段 开始++++++++++++++++++++++*/ //游戏开始 -GetGameStartInfo::GetGameStartInfo(){ -} - - -GetGameStartInfo::~GetGameStartInfo(){ -} - - -string GetGameStartInfo::operation( OGLordRobotAI& robot, const string& msg ){ +bool GetGameStartInfo::operation( OGLordRobotAI& robot, const string& msg, string& serializedStr ){ // 游戏开始 //message GameStartNtf { // required string gameName = 1; // 游戏服务通道号 @@ -216,22 +175,21 @@ string GetGameStartInfo::operation( OGLordRobotAI& robot, const string& msg ){ // repeated UserInfo userinfo = 3; // 用户信息 // optional MatchInfo matchInfo = 4; // 如果是游戏场,该字段不用 //} - string serializedStr; + robot.SetStatus(GAMMING); GameStartNtf gameStartNtf; if (!gameStartNtf.ParseFromString(msg)) { - cout << "parse pb message GameStartNtf error." << endl; - return serializedStr; + ERROR("parse pb message GameStartNtf error."); + return false; } int index = 0; int iUserNum = gameStartNtf.userinfo_size(); - cout << gameStartNtf.gamename() << endl; - cout << iUserNum << endl; int robotId = robot.GetRobotId(); for (index = 0; index < iUserNum; ++index)//寻找自己的座位号:0-2 { - cout << "total userNum: " << iUserNum << ", robot name: " << robotId << ", netname:" << ::atoi(gameStartNtf.userinfo(index).username().c_str()) << endl; - if (::atoi(gameStartNtf.userinfo(index).username().c_str()) == robotId) + int netId = ::atoi(gameStartNtf.userinfo(index).username().c_str()); + DEBUG("total userNum: %d, robot id: %d, net id: %d.", iUserNum, robotId, netId); + if (netId == robotId) { break; } @@ -239,45 +197,37 @@ string GetGameStartInfo::operation( OGLordRobotAI& robot, const string& msg ){ if (iUserNum == index) { - cout << "Doesn't find robot name." << endl; + DEBUG("Doesn't find robot name."); } else { robot.SetAiSeat(index); - cout << "Set robot seat successed, seat is: " << index << endl; + DEBUG("Set robot seat successed, seat is: %d.", index); } - return serializedStr; + return false; } //发牌 -InitHardCard::InitHardCard(){ -} - - -InitHardCard::~InitHardCard(){ -} - - -string InitHardCard::operation( OGLordRobotAI& robot, const string& msg ){ +bool InitHardCard::operation( OGLordRobotAI& robot, const string& msg, string& serializedStr ){ // 发牌 //message DealCardNtf { // required int32 headerseat = 1; // 第一个叫分座位号 // repeated HandCardList cards = 2; // 玩家手牌 //} - string serializedStr; + robot.SetStatus(GAMMING); DealCardNtf dealCardNtf; if (!dealCardNtf.ParseFromString(msg)) { - cout << "parse pb message DealCardNtf error." << endl; - return serializedStr; + ERROR("parse pb message DealCardNtf error."); + return false; } int aiSeat = robot.GetAiSeat(); - cout << "my seat is: " << aiSeat << endl; + DEBUG("my seat is: %d.", aiSeat); if (-1 == aiSeat) { - cout << "Not init seat info." << endl; - return serializedStr; + ERROR("Not init seat info."); + return false; } int hearderSeat = dealCardNtf.headerseat(); int cardsSize = dealCardNtf.cards(aiSeat).cards_size();//查看自己的那手牌信息 @@ -288,7 +238,7 @@ string InitHardCard::operation( OGLordRobotAI& robot, const string& msg ){ vecHandCard.push_back(dealCardNtf.cards(aiSeat).cards(index)); } robot.RbtInInitCard(aiSeat, vecHandCard); - cout << "Init hand card successed, hand card info is: " << endl; + DEBUG("Init hand card successed, hand card info is: "); printCardInfo(vecHandCard); //判断自己是不是第一个叫分座位号 @@ -298,39 +248,46 @@ string InitHardCard::operation( OGLordRobotAI& robot, const string& msg ){ robot.RbtOutGetCallScore(myScore); CallScoreReq callScoreReq; callScoreReq.set_score(myScore); - callScoreReq.SerializeToString(&serializedStr); + DEBUG("hearderSeat is: %d, I'm is the first to call score, my score is: %d.", hearderSeat, myScore); + if (!callScoreReq.SerializeToString(&serializedStr)) + { + ERROR("callScoreReq serialize failed."); + } + else + { + DEBUG("callScoreReq serialize successe."); + } + return true; } - return serializedStr; + return false; } //收到叫分通知 -GetCallScoreInfo::GetCallScoreInfo(){ -} - - -GetCallScoreInfo::~GetCallScoreInfo(){ -} - - -string GetCallScoreInfo::operation( OGLordRobotAI& robot, const string& msg ){ +bool GetCallScoreInfo::operation( OGLordRobotAI& robot, const string& msg, string& serializedStr ){ // 叫分 //message UserCallScoreNtf { // required int32 seatno = 1; // 座位号 // required int32 seatnext = 2[default=-1]; // 下一个叫分座位,-1叫分结束 // required int32 score = 3; // 叫分值(1/2/3), 0-不叫 //} - string serializedStr; + robot.SetStatus(GAMMING); UserCallScoreNtf userCallScoreNtf; if (!userCallScoreNtf.ParseFromString(msg)) { - cout << "parse pb message UserCallScoreNtf error." << endl; - return serializedStr; + ERROR("parse pb message UserCallScoreNtf error."); + return false; } int seatNo = userCallScoreNtf.seatno(); int seatNext = userCallScoreNtf.seatnext(); int score = userCallScoreNtf.score(); int aiSeat = robot.GetAiSeat(); + DEBUG("seatno: %d, seatnext: %d, score: %d, my seat: %d.", seatNo, seatNext, score, aiSeat); + if (-1 == seatNext) + { + //停止叫分 + return false; + } if (seatNext != aiSeat) { //没轮到自己,不叫 @@ -341,80 +298,72 @@ string GetCallScoreInfo::operation( OGLordRobotAI& robot, const string& msg ){ int myScore = 0; robot.RbtOutGetCallScore(myScore); int curScore = robot.GetCurScore(); - cout << "My score is: " << myScore << " Cur score is: " << curScore << endl; + DEBUG("My score is: %d, current score is: %d.", myScore, curScore); CallScoreReq callScoreReq; if (score >= myScore) { //目前分数比自己的大,不叫 callScoreReq.set_score(0); - cout << "Doesn't choose call score, curScore is: " << curScore << endl; + DEBUG("Doesn't choose call score, curScore is: %d.", curScore); } else if (score == 0 && robot.GetCurScore() >= myScore) { //上一个用户没叫,且上上一个用户叫的分比自己的高,不叫 callScoreReq.set_score(0); - cout << "Doesn't choose call score, curScore is: " << curScore << endl; + DEBUG("Doesn't choose call score, curScore is: %d.", curScore); } else { //叫分 callScoreReq.set_score(myScore); - cout << "Choose to call score, score is: " << myScore << endl; + DEBUG("Choose to call score, score is: %d.", myScore); + } + if (!callScoreReq.SerializeToString(&serializedStr)) + { + ERROR("callScoreReq serialize failed."); + } + else + { + DEBUG("callScoreReq serialize successe."); } - callScoreReq.SerializeToString(&serializedStr); + return true; } - return serializedStr; + return false; } //收到地主信息 -GetLordInfo::GetLordInfo(){ -} - - -GetLordInfo::~GetLordInfo(){ -} - - -string GetLordInfo::operation( OGLordRobotAI& robot, const string& msg ){ +bool GetLordInfo::operation( OGLordRobotAI& robot, const string& msg, string& serializedStr ){ // 地主确定 //message LordSetNtf { // required int32 seatlord = 1; // 地主座位号 // required int32 callscore = 2; // 地主叫分 //} - string serializedStr; + robot.SetStatus(GAMMING); LordSetNtf lordSetNtf; if (!lordSetNtf.ParseFromString(msg)) { - cout << "parse pb message LordSetNtf error." << endl; - return serializedStr; + ERROR("parse pb message LordSetNtf error."); + return false; } int seatLord = lordSetNtf.seatlord(); robot.SetLordSeat(seatLord); - cout << "Set lord info over, " << seatLord << endl; - return serializedStr; + DEBUG("Set lord info %d over.", seatLord); + return false; } //收到底牌 -GetBaseCardInfo::GetBaseCardInfo(){ -} - - -GetBaseCardInfo::~GetBaseCardInfo(){ -} - - -string GetBaseCardInfo::operation( OGLordRobotAI& robot, const string& msg ){ +bool GetBaseCardInfo::operation( OGLordRobotAI& robot, const string& msg, string& serializedStr ){ // 发底牌 //message SendBaseCardNtf { // repeated int32 basecards = 1; // 底牌数据 //} - string serializedStr; + robot.SetStatus(GAMMING); SendBaseCardNtf sendBaseCardNtf; if (!sendBaseCardNtf.ParseFromString(msg)) { - cout << "parse pb message SendBaseCardNtf error." << endl; - return serializedStr; + ERROR("parse pb message SendBaseCardNtf error."); + return false; } int baseCardSize = sendBaseCardNtf.basecards_size(); int seatLord = robot.GetLordSeat(); @@ -423,18 +372,18 @@ string GetBaseCardInfo::operation( OGLordRobotAI& robot, const string& msg ){ { vecBaseCard.push_back(sendBaseCardNtf.basecards(index)); } - cout << "Base card info:" << endl; + DEBUG("Base card info:"); printCardInfo(vecBaseCard); robot.RbtInSetLord(seatLord, vecBaseCard); - cout << "Set base card over." << endl; + DEBUG("Set base card over."); //判断自己是不是地主 if (robot.GetLordSeat() == robot.GetAiSeat()) { - cout << "I am lord, so it's my turn to take out first card." << endl; + DEBUG("I am lord, so it's my turn to take out first card."); vector vecTackOutCard; robot.RbtOutGetTakeOutCard(vecTackOutCard); - cout << "My (lord) take out cards is:" << endl; + DEBUG("My (lord) take out cards is:"); printCardInfo(vecTackOutCard); TakeoutCardReq takeoutCardReq; @@ -442,22 +391,21 @@ string GetBaseCardInfo::operation( OGLordRobotAI& robot, const string& msg ){ { takeoutCardReq.add_cards(vecTackOutCard[iIndex]); } - takeoutCardReq.SerializeToString(&serializedStr); - cout << "Take out cards over." << endl; + if (!takeoutCardReq.SerializeToString(&serializedStr)) + { + ERROR("Take cout card req serialize failed!"); + } + else + { + DEBUG("Take out cards over, serialized string size is: %d.", serializedStr.length()); + } + return true; } - return serializedStr; + return false; } //收到出牌通知 -GetTakeOutCardInfo::GetTakeOutCardInfo(){ -} - - -GetTakeOutCardInfo::~GetTakeOutCardInfo(){ -} - - -string GetTakeOutCardInfo::operation( OGLordRobotAI& robot, const string& msg ){ +bool GetTakeOutCardInfo::operation( OGLordRobotAI& robot, const string& msg, string& serializedStr ){ // 出牌 //message TakeoutCardNtf { // required int32 seatno = 1; // 出牌座位号 @@ -466,33 +414,35 @@ string GetTakeOutCardInfo::operation( OGLordRobotAI& robot, const string& msg ){ // required int32 cardtype = 4; // 类型 // required int32 multiple = 5; // 当前倍数(炸弹产生的倍数) //} - string serializedStr; + robot.SetStatus(GAMMING); TakeoutCardNtf takeoutCardNtf; if (!takeoutCardNtf.ParseFromString(msg)) { - cout << "parse pb message TakeoutCardNtf error." << endl; - return serializedStr; + ERROR("parse pb message TakeoutCardNtf error."); + return false; } int seatno = takeoutCardNtf.seatno(); int seatnext = takeoutCardNtf.seatnext(); int cardsNum = takeoutCardNtf.cards_size(); + int aiSeat = robot.GetAiSeat(); + DEBUG("seatno: %d, seatnext: %d, cards num: %d, my seat: %d.", seatno, seatnext, cardsNum, aiSeat); vector vecOppTackOutCard; for (int index = 0; index < cardsNum; ++index) { vecOppTackOutCard.push_back(takeoutCardNtf.cards(index)); } - cout << "Current card info is:" << endl; + DEBUG("Current card info is:"); printCardInfo(vecOppTackOutCard); robot.RbtInTakeOutCard(seatno, vecOppTackOutCard); - int aiSeat = robot.GetAiSeat(); + if (seatnext == aiSeat) { //出牌 - cout << "It's my turn to take out card." << endl; + DEBUG("It's my turn to take out card."); vector vecTackOutCard; robot.RbtOutGetTakeOutCard(vecTackOutCard); - cout << "My take out cards is:" << endl; + DEBUG("My take out cards is:"); printCardInfo(vecTackOutCard); TakeoutCardReq takeoutCardReq; @@ -500,109 +450,124 @@ string GetTakeOutCardInfo::operation( OGLordRobotAI& robot, const string& msg ){ { takeoutCardReq.add_cards(vecTackOutCard[iIndex]); } - takeoutCardReq.SerializeToString(&serializedStr); - cout << "Take out cards over." << endl; + if (!takeoutCardReq.SerializeToString(&serializedStr)) + { + ERROR("Take cout card req serialize failed!"); + } + else + { + DEBUG("Take out cards over, serialized string size is: %d.", serializedStr.length()); + } + return true; } else { - cout << "It not my turn to take out card." << endl; + DEBUG("It not my turn to take out card."); } - return serializedStr; + return false; } //游戏结束 -GetGameOverInfo::GetGameOverInfo(){ -} - - -GetGameOverInfo::~GetGameOverInfo(){ -} - - -string GetGameOverInfo::operation( OGLordRobotAI& robot, const string& msg ){ +bool GetGameOverInfo::operation( OGLordRobotAI& robot, const string& msg, string& serializedStr ){ // 游戏结束通知 //message GameOverNtf { // required int32 reason = 1[default=2]; // 结束原因:1-强制结束,2-达到最大游戏盘数 //} - string serializedStr; GameOverNtf gameOverNtf; if (!gameOverNtf.ParseFromString(msg)) { - cout << "parse pb message GameOverNtf error." << endl; - return serializedStr; + ERROR("parse pb message GameOverNtf error."); + return false; } int reason = gameOverNtf.reason(); robot.RbtResetData(); robot.SetStatus(INITGAME); - cout << "Receved game over notify, reset robot to sign up condation." << endl; - return serializedStr; + DEBUG("Receved game over notify, reset robot to sign up condation."); + return false; +} +// +//游戏结果 +bool GetGameResultInfo::operation( OGLordRobotAI& robot, const string& msg, string& serializedStr ){ + // 游戏结果(游戏场和比赛场通用) + //message OrgRoomDdzGameResultNtf { + // required int32 seatlord = 1; // 地主的座位号 + // required int32 seatwin = 2; // 胜利座位 + // required int32 multiple_base = 3; // 基础倍数(叫分值) + // required int32 bombs = 4; // 普通炸弹个数 + // required bool hasrocket = 5; // 是否有火箭 + // required bool hasspring = 6; // 是否春天 + // required string guid = 7; + // message UserResult { + // required string userId = 1; + // required int64 chip_change = 2; // 筹码变化 + // required int64 chip_now = 3; // 当前筹码 + // repeated int32 cards = 4; // 玩家手牌 + // } + // repeated UserResult userresult = 8; + // required int32 tax = 9; // 服务费 + // required int32 incExp = 10; // 增加的经验值 + // required int32 incVipPoints = 11; // 增加的竞技点 + //} + OrgRoomDdzGameResultNtf orgRoomDdzGameResultNtf; + if (!orgRoomDdzGameResultNtf.ParseFromString(msg)) + { + ERROR("parse pb message OrgRoomDdzGameResultNtf error."); + return false; + } + robot.RbtResetData(); + robot.SetStatus(INITGAME); + DEBUG("Receved game result notify, reset robot to sign up condation."); + return false; } //获取叫分结果 -GetCallScoreResultInfo::GetCallScoreResultInfo(){ -} - - -GetCallScoreResultInfo::~GetCallScoreResultInfo(){ -} - - -string GetCallScoreResultInfo::operation( OGLordRobotAI& robot, const string& msg ){ +bool GetCallScoreResultInfo::operation( OGLordRobotAI& robot, const string& msg, string& serializedStr ){ //message CallScoreAck { // required int32 result = 1; //} - string serializedStr; + robot.SetStatus(GAMMING); CallScoreAck callScoreAck; if (!callScoreAck.ParseFromString(msg)) { - cout << "parse pb message CallScoreAck error." << endl; - return serializedStr; + ERROR("parse pb message CallScoreAck error."); + return false; } int result = callScoreAck.result(); if (0 != result) { - cout << "Get call score result, call score failed, result is: " << result << endl; + ERROR("Get call score result, call score failed, result is: %d.", result); } else { - cout << "Get call score result, call score successed." << endl; + DEBUG("Get call score result, call score successed."); } - return serializedStr; + return false; } //获取出牌结果 -GetTakeOutCardResultInfo::GetTakeOutCardResultInfo(){ -} - - -GetTakeOutCardResultInfo::~GetTakeOutCardResultInfo(){ -} - - -string GetTakeOutCardResultInfo::operation( OGLordRobotAI& robot, const string& msg ){ +bool GetTakeOutCardResultInfo::operation( OGLordRobotAI& robot, const string& msg, string& serializedStr ){ //message TakeoutCardAck { // required int32 result = 1; //} - string serializedStr; + robot.SetStatus(GAMMING); TakeoutCardAck takeoutCardAck; if (!takeoutCardAck.ParseFromString(msg)) { - cout << "parse pb message TakeoutCardAck error." << endl; - return serializedStr; + ERROR("parse pb message TakeoutCardAck error."); + return false; } int result = takeoutCardAck.result(); - cout << "Get take out card result, " << result << endl; if (0 != result) { - cout << "Get take out card result, take out card failed, result is: " << result << endl; + ERROR("Get take out card result, take out card failed, result is: %d.", result); robot.RecoveryHandCards();//恢复手牌记录 } else { - cout << "Get take out card result, take out card successed." << endl; + DEBUG("Get take out card result, take out card successed."); } - return serializedStr; + return false; } /*++++++++++++++++++游戏阶段 结束++++++++++++++++++++++*/ diff --git a/robot_client/AbstractProduct.h b/robot_client/AbstractProduct.h index b0546f8..7d0b08c 100644 --- a/robot_client/AbstractProduct.h +++ b/robot_client/AbstractProduct.h @@ -6,55 +6,55 @@ class OGLordRobotAI; class AbstractProduct{ public: - AbstractProduct(); - virtual ~AbstractProduct(); + AbstractProduct(){}; + virtual ~AbstractProduct(){}; public: - virtual string operation( OGLordRobotAI& robot, const string& msg ) = 0; + virtual bool operation( OGLordRobotAI& robot, const string& msg, string& retMsg ) = 0; }; //请求认证回应 class GetVerifyAckInfo:public AbstractProduct{ public: - GetVerifyAckInfo(); - virtual ~GetVerifyAckInfo(); + GetVerifyAckInfo(){}; + virtual ~GetVerifyAckInfo(){}; public: - string operation( OGLordRobotAI& robot, const string& msg ); + bool operation( OGLordRobotAI& robot, const string& msg, string& retMsg ); }; //初始化游戏回应 class GetInitGameAckInfo:public AbstractProduct{ public: - GetInitGameAckInfo(); - virtual ~GetInitGameAckInfo(); + GetInitGameAckInfo(){}; + virtual ~GetInitGameAckInfo(){}; public: - string operation( OGLordRobotAI& robot, const string& msg ); + bool operation( OGLordRobotAI& robot, const string& msg, string& retMsg ); }; //查询报名条件回应 class GetSignUpCondAckInfo:public AbstractProduct{ public: - GetSignUpCondAckInfo(); - virtual ~GetSignUpCondAckInfo(); + GetSignUpCondAckInfo(){}; + virtual ~GetSignUpCondAckInfo(){}; public: - string operation( OGLordRobotAI& robot, const string& msg ); + bool operation( OGLordRobotAI& robot, const string& msg, string& retMsg ); }; //报名回应 class GetSignUpAckInfo:public AbstractProduct{ public: - GetSignUpAckInfo(); - virtual ~GetSignUpAckInfo(); + GetSignUpAckInfo(){}; + virtual ~GetSignUpAckInfo(){}; public: - string operation( OGLordRobotAI& robot, const string& msg ); + bool operation( OGLordRobotAI& robot, const string& msg, string& retMsg ); }; @@ -64,99 +64,111 @@ class GetSignUpAckInfo:public AbstractProduct{ class GetGameStartInfo:public AbstractProduct{ public: - GetGameStartInfo(); - virtual ~GetGameStartInfo(); + GetGameStartInfo(){}; + virtual ~GetGameStartInfo(){}; public: - string operation( OGLordRobotAI& robot, const string& msg ); + bool operation( OGLordRobotAI& robot, const string& msg, string& retMsg ); }; //发牌 class InitHardCard:public AbstractProduct{ public: - InitHardCard(); - virtual ~InitHardCard(); + InitHardCard(){}; + virtual ~InitHardCard(){}; public: - string operation( OGLordRobotAI& robot, const string& msg ); + bool operation( OGLordRobotAI& robot, const string& msg, string& retMsg ); }; //收到叫分通知 class GetCallScoreInfo:public AbstractProduct{ public: - GetCallScoreInfo(); - ~GetCallScoreInfo(); + GetCallScoreInfo(){}; + ~GetCallScoreInfo(){}; public: - string operation( OGLordRobotAI& robot, const string& msg ); + bool operation( OGLordRobotAI& robot, const string& msg, string& retMsg ); }; //收到地主信息 class GetLordInfo:public AbstractProduct{ public: - GetLordInfo(); - ~GetLordInfo(); + GetLordInfo(){}; + ~GetLordInfo(){}; public: - string operation( OGLordRobotAI& robot, const string& msg ); + bool operation( OGLordRobotAI& robot, const string& msg, string& retMsg ); }; //收到底牌 class GetBaseCardInfo:public AbstractProduct{ public: - GetBaseCardInfo(); - ~GetBaseCardInfo(); + GetBaseCardInfo(){}; + ~GetBaseCardInfo(){}; public: - string operation( OGLordRobotAI& robot, const string& msg ); + bool operation( OGLordRobotAI& robot, const string& msg, string& retMsg ); }; //收到出牌通知 class GetTakeOutCardInfo:public AbstractProduct{ public: - GetTakeOutCardInfo(); - ~GetTakeOutCardInfo(); + GetTakeOutCardInfo(){}; + ~GetTakeOutCardInfo(){}; public: - string operation( OGLordRobotAI& robot, const string& msg ); + bool operation( OGLordRobotAI& robot, const string& msg, string& retMsg ); }; //游戏结束 class GetGameOverInfo:public AbstractProduct{ public: - GetGameOverInfo(); - ~GetGameOverInfo(); + GetGameOverInfo(){}; + ~GetGameOverInfo(){}; public: - string operation( OGLordRobotAI& robot, const string& msg ); + bool operation( OGLordRobotAI& robot, const string& msg, string& retMsg ); }; +//游戏结果 +class GetGameResultInfo:public AbstractProduct{ + +public: + GetGameResultInfo(){}; + ~GetGameResultInfo(){}; + +public: + bool operation( OGLordRobotAI& robot, const string& msg, string& retMsg ); +}; + + //获取叫分结果 class GetCallScoreResultInfo:public AbstractProduct{ public: - GetCallScoreResultInfo(); - ~GetCallScoreResultInfo(); + GetCallScoreResultInfo(){}; + ~GetCallScoreResultInfo(){}; public: - string operation( OGLordRobotAI& robot, const string& msg ); + bool operation( OGLordRobotAI& robot, const string& msg, string& retMsg ); }; //获取出牌结果 class GetTakeOutCardResultInfo:public AbstractProduct{ public: - GetTakeOutCardResultInfo(); - ~GetTakeOutCardResultInfo(); + GetTakeOutCardResultInfo(){}; + ~GetTakeOutCardResultInfo(){}; public: - string operation( OGLordRobotAI& robot, const string& msg ); + bool operation( OGLordRobotAI& robot, const string& msg, string& retMsg ); }; /*++++++++++++++++++游戏阶段 结束++++++++++++++++++++++*/ diff --git a/robot_client/Makefile b/robot_client/Makefile index c513159..724f40b 100644 --- a/robot_client/Makefile +++ b/robot_client/Makefile @@ -3,7 +3,8 @@ TARGET = robot_client CC = g++ LIB = -lprotobuf\ - -levent + -levent\ + -llog4cplus -lpthread OBJC = $(subst .cpp,.o,$(wildcard *.cpp)) diff --git a/robot_client/NetLib.cpp b/robot_client/NetLib.cpp index 98ebc30..ca0b41f 100644 --- a/robot_client/NetLib.cpp +++ b/robot_client/NetLib.cpp @@ -12,6 +12,7 @@ #include "connect.pb.h" #include "org_room2client.pb.h" #include "stringutil.h" +#include "log.h" using namespace std; using namespace YLYQ; @@ -24,7 +25,7 @@ NetLib::NetLib() { if (!Init()) { - cout << "Get params error, please check configure file!" << endl; + ERROR("Get params error, please check configure file!"); ::exit(0); } memset(&server_addr, 0, sizeof(server_addr) ); @@ -32,8 +33,7 @@ NetLib::NetLib() server_addr.sin_port = htons(port_); inet_aton(ip_.c_str(), &server_addr.sin_addr); base = event_init(); - cout << "ip: " << ip_.c_str() << endl; - cout << "port: " << port_ << endl; + DEBUG("ip: %s, port: %d.", ip_.c_str(), port_); connect(); @@ -56,21 +56,21 @@ void NetLib::connect() if (!insertResult.second) { //插入失败 - cout << "ERROR: insert failed." << endl; + ERROR("Insert into bevToRobot failed."); ::exit(0); } bufferevent_socket_connect(insertResult.first->first, (struct sockaddr *)&server_addr, sizeof(server_addr)); bufferevent_setcb(insertResult.first->first, server_msg_cb, NULL, event_cb, this); - bufferevent_enable(insertResult.first->first, EV_READ | EV_PERSIST); - cout << "Create a connection, index is: " << index << ", init a Robot, Id is: " << robotIdStart_ + index << endl; + bufferevent_enable(insertResult.first->first, EV_READ | EV_WRITE); + DEBUG("Create a connection, index is: %d, init a Robot, Id is: %d.", index, robotIdStart_ + index); } else { - cout << "Robot Id range is bigger than robot num." << endl; + DEBUG("Robot Id range is bigger than robot num."); break; } } - cout << "Total init " << index << " robots and connections." << endl; + DEBUG("Total init %d robots and connections.", index); } void NetLib::start() @@ -121,7 +121,7 @@ void NetLib::server_msg_cb(struct bufferevent* bev, void* arg) map::iterator it = (netlib->bevToRobot).find(bev); if ((netlib->bevToRobot).end() == it) { - cout << "Error! Cannot find robot." << endl; + ERROR("Cannot find robot."); return; } @@ -130,7 +130,7 @@ void NetLib::server_msg_cb(struct bufferevent* bev, void* arg) int iMsgLen = 0; int msgId = 0; int dataLength = evbuffer_get_length(bufferevent_get_input(bev)); - cout << "Reveive data length is: " << dataLength << endl; + //DEBUG("Reveive data length is: %d.", dataLength); while (dataLength > 0) { //读取msg length @@ -138,65 +138,73 @@ void NetLib::server_msg_cb(struct bufferevent* bev, void* arg) len = bufferevent_read(bev, msgLen, 4); if (4 != len) { - cout << "Doesn't has 4 byte len info." << endl; + ERROR("Doesn't has 4 byte len info."); break; } int *pMsgLen = (int*)msgLen; iMsgLen = ntohl(*pMsgLen); if (0 == iMsgLen) { - cout << "Error! Convent data length failed." << endl; + ERROR("Error! Convent data length failed."); break; } - cout << "Msg len: " << iMsgLen << endl; + //DEBUG("Msg len: %d.", iMsgLen); //读取msgid memset(msgLen, '\0', 4); len = bufferevent_read(bev, msgLen, 4); if (4 != len) { - cout << "Doesn't has 4 byte MsgId info." << endl; + ERROR("Doesn't has 4 byte MsgId info."); break; } pMsgLen = (int*)msgLen; msgId = ntohl(*pMsgLen); - cout << "MsgId is: " << msgId << endl; + //DEBUG("MsgId is: %d.", msgId); //读取消息体 char* msg = new char[iMsgLen + 1]; len = bufferevent_read(bev, msg, iMsgLen); - cout << "Receive " << len << " byte from server for robot :" << (it->second).GetRobotId() - << " in message " << msgId << endl; + DEBUG("Receive %d byte from server for robot %d in message %d.", len, (it->second).GetRobotId(), msgId); string strMsg; strMsg.append(msg, iMsgLen); delete [] msg; - string strRet = (it->second).RobotProcess(msgId, strMsg); + string strRet; + bool result = (it->second).RobotProcess(msgId, strMsg, strRet); - if (0 != strRet.length()) + if (result) { - if (NOTIFY_CALLSCORE == msgId || NOTIFY_TAKEOUT == msgId ||\ - NOTIFY_DEALCARD == msgId || NOTIFY_BASECARD == msgId) + int msgIdBak = msgId; + if (NOTIFY_CALLSCORE == msgId || NOTIFY_DEALCARD == msgId) + { + msgId = MSGID_CALLSCORE_REQ; + } + else if (NOTIFY_TAKEOUT == msgId || NOTIFY_BASECARD == msgId) + { + msgId = MSGID_TAKEOUT_REQ; + } + string strSend = netlib->SerializeMsg(msgId, strRet); + + if (NOTIFY_DEALCARD == msgIdBak || NOTIFY_BASECARD == msgIdBak) + { + //添加延时发送消息的定时器 + pMsgNode oneMsgNode = new msgNode(bev, strSend, msgId, (it->second).GetRobotId()); + evtimer_set(&netlib->ev_timer_delay, delay_send_msg_time_cb, oneMsgNode); + event_add(&(netlib->ev_timer_delay), &(netlib->timerEventDelay)); + DEBUG("Add a timer, will delay send message: %d to server for robot %d.", msgId, (it->second).GetRobotId()); + } + else { - if (NOTIFY_CALLSCORE == msgId || NOTIFY_DEALCARD == msgId) - { - msgId = MSGID_CALLSCORE_REQ; - } - else if (NOTIFY_TAKEOUT == msgId || NOTIFY_BASECARD == msgId) - { - msgId = MSGID_TAKEOUT_REQ; - } - string strSend = netlib->SerializeMsg(msgId, strRet); //把消息发送给服务器端 bufferevent_write(bev, strSend.c_str(), strSend.length()); - cout << "Send message: " << msgId << " to server for robot :" - << (it->second).GetRobotId() << endl; + DEBUG("Send message: %d to server for robot %d.", msgId, (it->second).GetRobotId()); } } dataLength = evbuffer_get_length(bufferevent_get_input(bev)); - cout << "Data still has length: " << dataLength << endl; + //DEBUG("Data still has length %d.", dataLength); } - cout << "Read data this time over." << endl; + //DEBUG("Read data this time over."); } void NetLib::heart_beat_time_cb(int fd, short events, void* arg) @@ -214,7 +222,7 @@ void NetLib::heart_beat_time_cb(int fd, short events, void* arg) { bufferevent_write(it->first, serializedStr.c_str(), serializedStr.length()); } - cout << "Send once heard beat." << endl; + DEBUG("Send once heard beat."); event_add(&(netlib->ev_timer_heart_beat), &(netlib->timerEventHeartBeat));/*重新添加定时器*/ } @@ -241,7 +249,7 @@ void NetLib::verify_time_cb(int fd, short events, void* arg) verifyReq.SerializeToString(&serializedStr); serializedStr = netlib->SerializeMsg(connect::MSGID_VERIFY_REQ, serializedStr); bufferevent_write(it->first, serializedStr.c_str(), serializedStr.length()); - cout << "Robot " << (it->second).GetRobotId() << " send verify successed." << endl; + DEBUG("Robot %d send verify once.", (it->second).GetRobotId()); bHasUnviryfiedRobot = true; } } @@ -275,7 +283,7 @@ void NetLib::init_game_time_cb(int fd, short events, void* arg) if (VERIFIED == (it->second).GetStatus()) { bufferevent_write(it->first, serializedStr.c_str(), serializedStr.length()); - cout << "Robot " << (it->second).GetRobotId() << " send init game successed." << endl; + DEBUG("Robot %d send init game once.", (it->second).GetRobotId()); bHasUnInitedRobot = true; } } @@ -304,7 +312,7 @@ void NetLib::sign_up_cond_time_cb(int fd, short events, void* arg) if (INITGAME == (it->second).GetStatus()) { bufferevent_write(it->first, serializedStr.c_str(), serializedStr.length()); - cout << "Robot " << (it->second).GetRobotId() << " send sign up cond req successed" << endl; + DEBUG("Robot %d send init sign up cond req once.", (it->second).GetRobotId()); } } event_add(&(netlib->ev_timer_sign_in_cond), &(netlib->timerEventSignInCond));/*重新添加定时器*/ @@ -331,26 +339,34 @@ void NetLib::sign_up_time_cb(int fd, short events, void* arg) serializedStr = netlib->SerializeMsg(org_room2client::MSGID_DDZ_SIGN_UP_REQ, serializedStr); bufferevent_write(it->first, serializedStr.c_str(), serializedStr.length()); - cout << "Robot " << (it->second).GetRobotId() << " send sign up req successed" << endl; + DEBUG("Robot %d send init sign up req once.", (it->second).GetRobotId()); } } event_add(&(netlib->ev_timer_sign_in), &(netlib->timerEventSignIn));/*重新添加定时器*/ } +void NetLib::delay_send_msg_time_cb(int fd, short events, void* arg) +{ + pMsgNode oneMsgNode = static_cast(arg); + bufferevent_write(oneMsgNode->bev_, (oneMsgNode->msg_).c_str(), (oneMsgNode->msg_).length()); + DEBUG("Send delay message: %d to server for robot %d.", oneMsgNode->msgId_, oneMsgNode->robotId_); + delete oneMsgNode; +} + void NetLib::event_cb(struct bufferevent *bev, short event, void *arg) { NetLib* netlib = static_cast(arg); if (event & BEV_EVENT_EOF) { - cout << "connection closed." << endl; + DEBUG("Connection closed."); } else if (event & BEV_EVENT_ERROR) { - printf("some other error\n"); + ERROR("Some other error."); } else if( event & BEV_EVENT_CONNECTED) { - printf("the client has connected to server\n"); + DEBUG("One client has connected to server."); return ; } @@ -360,7 +376,7 @@ void NetLib::event_cb(struct bufferevent *bev, short event, void *arg) { //这将自动close套接字和free读写缓冲区 bufferevent_free(bev); - cout << "Robot " << (it->second).GetRobotId() << " disconnected." << endl; + DEBUG("Robot %d disconnected.", (it->second).GetRobotId()); (netlib->bevToRobot).erase(it); } } @@ -403,7 +419,7 @@ bool NetLib::Init() initGameTime_ = ::atoi(strInitGameTime.c_str()); signUpCondTime_ = ::atoi(strSignUpCondTime.c_str()); signUpTime_ = ::atoi(strSignUpTime.c_str()); - cout << "Get configure successed." << endl; + DEBUG("Get configure successed."); } return bResult; @@ -431,30 +447,35 @@ void NetLib::InitTimer() timerEventSignIn.tv_sec = signUpTime_; timerEventSignIn.tv_usec = 0; + //延时发送消息定时器初始化 + timerEventDelay.tv_sec = 5;//先设为5s + timerEventDelay.tv_usec = 0; + //添加心跳协议定时器 evtimer_set(&ev_timer_heart_beat, heart_beat_time_cb, this); event_add(&ev_timer_heart_beat, &timerEventHeartBeat); - cout << "Heart beat timer started!" << endl; + DEBUG("Heart beat timer started!"); //添加验证身份定时器 evtimer_set(&ev_timer_verify, verify_time_cb, this); event_add(&ev_timer_verify, &timerEventVerify); - cout << "Verify timer started!" << endl; + DEBUG("Verify timer started!"); //添加初始化游戏定时器 evtimer_set(&ev_timer_init_game, init_game_time_cb, this); event_add(&ev_timer_init_game, &timerEventInitGame); - cout << "Init game timer started!" << endl; + DEBUG("Init game timer started!"); //添加查询报名条件定时器 evtimer_set(&ev_timer_sign_in_cond, sign_up_cond_time_cb, this); event_add(&ev_timer_sign_in_cond, &timerEventSignInCond); - cout << "Sign up cond timer started!" << endl; + DEBUG("Sign up cond timer started!"); //添加报名定时器 evtimer_set(&ev_timer_sign_in, sign_up_time_cb, this); event_add(&ev_timer_sign_in, &timerEventSignIn); - cout << "Sign up timer started!" << endl; + + DEBUG("Sign up timer started!"); } diff --git a/robot_client/NetLib.h b/robot_client/NetLib.h index 6f5f692..edd9e5e 100644 --- a/robot_client/NetLib.h +++ b/robot_client/NetLib.h @@ -28,7 +28,19 @@ class NetLib static void init_game_time_cb(int fd, short events, void* arg); static void sign_up_cond_time_cb(int fd, short events, void* arg); static void sign_up_time_cb(int fd, short events, void* arg); + static void delay_send_msg_time_cb(int fd, short events, void* arg); + private: + + typedef struct MsgNode{ + MsgNode(struct bufferevent* bev, const std::string& msg, int msgId, int robotId) + :bev_(bev), msg_(msg), msgId_(msgId), robotId_(robotId){} + struct bufferevent* bev_; + std::string msg_; + int msgId_; + int robotId_; + }*pMsgNode, msgNode; + std::string ip_; int port_; int robotNum_; @@ -41,6 +53,7 @@ class NetLib int initGameTime_; int signUpCondTime_; int signUpTime_; + int delaySendMsgTime_; //libevent基础数据结构 struct event_base* base; @@ -71,6 +84,10 @@ class NetLib struct event ev_timer_sign_in; struct timeval timerEventSignIn; + //延时发送消息的定时器 + struct event ev_timer_delay; + struct timeval timerEventDelay; + void connect(); bool Init(); void InitTimer(); diff --git a/robot_client/OGLordRobotAI.cpp b/robot_client/OGLordRobotAI.cpp index d2eb0a7..4d008f8 100644 --- a/robot_client/OGLordRobotAI.cpp +++ b/robot_client/OGLordRobotAI.cpp @@ -1,7 +1,7 @@ #include "OGLordRobotAI.h" #include "AIUtils.h" #include "message.pb.h" - +#include "log.h" using namespace std; using namespace AIUtils; @@ -28,31 +28,28 @@ OGLordRobotAI::~OGLordRobotAI(void) { } -string OGLordRobotAI::RobotProcess(int msgId, const string& msg) +bool OGLordRobotAI::RobotProcess(int msgId, const string& msg, string& result) { - string result; - //处理消息 product = factory.createProduct(msgId); if (NULL == product) { cout << "Doesn't need to process this kind of message. msgId: " << msgId << endl; - return result; + return false; } YLYQ::Protocol::message::Message message; if (!message.ParseFromString(msg)) { cout << "Parse message pb error." << endl; - return result; + return false; } if (!message.has_body()) { cout << "Doesn't has body info." << endl; - return result; + return false; } string bodyMsg = message.body(); - result = product->operation(*this, bodyMsg); - return result; + return product->operation(*this, bodyMsg, result); } void OGLordRobotAI::RecoveryHandCards() @@ -254,11 +251,6 @@ bool OGLordRobotAI::RbtInTakeOutCard( int argSeat, std::vector argCards) curHand = hand; curHandSeat = argSeat; } - - for (int i=0; i<3; ++i) - { - printPoints(playerInfo[i].points, '\n'); - } return true; } @@ -296,14 +288,8 @@ bool OGLordRobotAI::RbtOutGetTakeOutCard(std::vector &vecCards) } takeOutHand(hand, vecCards); - cout << "take out hand: "; + DEBUG("take out hand: "); printHand(hand); - cout << endl; - for (unsigned i=0; i &vecCards) } } - cout << "remain cards after takeout: "; - for (unsigned i=0; ilordSeat = lordSeat; }; virtual int GetLordSeat() { return lordSeat; }; - std::string RobotProcess( int msgId, const std::string& msg ); + bool RobotProcess( int msgId, const std::string& msg, std::string& result ); void RecoveryHandCards(); private: diff --git a/robot_client/Robot.h b/robot_client/Robot.h index 715c0c1..383e314 100644 --- a/robot_client/Robot.h +++ b/robot_client/Robot.h @@ -18,6 +18,7 @@ enum RobotStatus INITGAME, //游戏初始化通过 CANSINGUP, //可以报名 SIGNUPED, //报名成功 + GAMMING, //正在游戏中 }; enum CardPoint diff --git a/robot_client/SimpleFactory.cpp b/robot_client/SimpleFactory.cpp index 8d1072f..8ec5ce8 100644 --- a/robot_client/SimpleFactory.cpp +++ b/robot_client/SimpleFactory.cpp @@ -25,6 +25,9 @@ AbstractProduct* SimpleFactory::createProduct(int type){ case NOTIFY_GAMEOVER: temp = new GetGameOverInfo(); break; + case MSGID_DDZ_GAME_RESULT_NTF: + temp = new GetGameResultInfo(); + break; case MSGID_CALLSCORE_ACK: temp = new GetCallScoreResultInfo(); break; diff --git a/robot_client/SimpleFactory.h b/robot_client/SimpleFactory.h index 136d5a9..f17fb6f 100644 --- a/robot_client/SimpleFactory.h +++ b/robot_client/SimpleFactory.h @@ -12,6 +12,7 @@ enum msgID { NOTIFY_SETLORD = 5058, // 地主确定 NOTIFY_TAKEOUT = 5059, // 出牌 NOTIFY_GAMEOVER = 5060, // 结束游戏 + MSGID_DDZ_GAME_RESULT_NTF = 2100, // 游戏结果 MSGID_CALLSCORE_REQ = 5001, // 叫分请求 MSGID_CALLSCORE_ACK = 5002, // 叫分请求结果 diff --git a/robot_client/main.cpp b/robot_client/main.cpp index 21a57d5..e04866f 100644 --- a/robot_client/main.cpp +++ b/robot_client/main.cpp @@ -2,6 +2,7 @@ #include #include "NetLib.h" #include "confaccess.h" +#include "log.h" using namespace std; @@ -9,7 +10,7 @@ void InitConfig(const char *confFile) { if (NULL == confFile) { - cout << "Doesn't has configure file." << endl; + ERROR("Doesn't has configure file."); ::exit(0); } CConfAccess* confAccess = CConfAccess::GetConfInstance(); @@ -19,6 +20,7 @@ void InitConfig(const char *confFile) int main(int argc, char** argv) { const char confFile[] = "./robot.conf"; + log::CLog::Initialize(""); InitConfig(confFile); NetLib netLib; netLib.start(); diff --git a/robot_client/robot.conf b/robot_client/robot.conf index 6cdbd3a..9c4b295 100644 --- a/robot_client/robot.conf +++ b/robot_client/robot.conf @@ -1,6 +1,6 @@ #this config file is for robot program [robot] -IQLevel = 0 +IQLevel = 1 robotIdStart = 110001 robotIdEnd = 110002 robotNum = 2