Example #1
0
 bool IsSubroutine(int code)
 {
     return 
         IsCall(code) || 
         code == RET ||
         code == RETC;       
 }
Example #2
0
static void RemoveVoiceCall(const char *szModule, const char *id)
{
	for(int i = calls.getCount() - 1; i >= 0; --i)
	{
		if (IsCall(&calls[i], szModule, id))
			calls.remove(i);
	}
}
Example #3
0
 bool IsUnconditionalBranch(int code)
 {
     return
         IsCall(code) || 
         code == RET ||
         code == iBU || 
         code == iJUMP || 
         code == syscall_branch;
 }
Example #4
0
VoiceCall * FindVoiceCall(const char *szModule, const char *id, bool add)
{
	for(int i = 0; i < calls.getCount(); i++)
	{
		if (IsCall(&calls[i], szModule, id))
		{
			return &calls[i];
		}
	}

	if (add)
	{
		VoiceProvider *module = FindModule(szModule);
		if (module == NULL)
			return NULL;

		VoiceCall *tmp = new VoiceCall(module, id);
		calls.insert(tmp);
		return tmp;
	}

	return NULL;
}
void PrintDebugAI(PokerAI *ai, VarTran_t h, int flag, int type) {
#if DEBUG_AI
	
	h = VarTran(ai);

	char *CARDS[] = {"XX",                                                  \
	"2S", "2C", "2D", "2H", "3S", "3C", "3D", "3H", "4S", "4C", "4D", "4H", \
	"5S", "5C", "5D", "5H", "6S", "6C", "6D", "6H", "7S", "7C", "7D", "7H", \
	"8S", "8C", "8D", "8H", "9S", "9C", "9D", "9H", "TS", "TC", "TD", "TH", \
	"JS", "JC", "JD", "JH", "QS", "QC", "QD", "QH", "KS", "KC", "KD", "KH", \
	"AS", "AC", "AD", "AH"                                                  \
	};
	char action[20] = "";
	int  actionamount= ai->action.amount;
	int  mynewpot = 0;
	sprintf(action, "%s", ActionGetStringNoHuanHang(&(ai->action)));
	
	//if (h.grp <= 7.0) {
	if (flag || h.round == 600 || h.stack+h.money<=3*h.BB) {
		printf("{%dof%d|%d|%3dr}", h.my_pos, h.noPlayers, h.noPlaying, h.round);
		
		if (type == 0) {
			//preflop
			printf("{ pv:%2d          }", h.pv);
		} else {
			//flop
			printf("{ wp:%4.2f|eg:%4.1f}", h.wp, h.eg);
		}
		
		printf("{pos%d-%d|act:%dc,%dr,%drc}", h.pos, h.pos_type, h.call_no, h.raise_no, h.raise_no_c);
		
		printf("{%.15s:", action);
		if (IsFold()) {
			mynewpot = h.current_bet;
			printf("|%4dcXX>%4d", h.call_amount, mynewpot);
		}
		if (IsCall()) {
			mynewpot = h.call_amount+h.current_bet;
			printf("|%4dc-->%4d", h.call_amount, mynewpot);
		}
		if (IsCheck()){
			mynewpot = h.current_bet;
			printf("|%4db==>%4d", 0, mynewpot);
		}
		if (IsBet()){
			mynewpot = actionamount+h.call_amount+h.current_bet;
			printf("|%4db++>%4d", h.raise_amount, mynewpot);
		}		
		if (IsAllin()) {
			mynewpot = h.stack+h.current_bet;
			printf("|%4db!!>%4d", h.raise_amount, mynewpot);		
		}
		printf("}");
		
		printf("-[pot:%4d|sk%5d|c_m%4d|r_m%4d]", h.pot, h.stack, h.call_amount, h.raise_amount);
		
		printf("-[%2s %2s ", CARDS[ai->game.hand[0]], CARDS[ai->game.hand[1]]);
		
		if (type == 0) {
			//preflop
			
		} else {
			//flop
			//printf("| ");
			for (int i = 0; i < ai->game.communitysize; i++) {
				printf("%2s ", CARDS[ai->game.community[i]]);
			}			
		}
		printf("\b]\n");
	}	
#endif	
}
void SetAggressAction(Aggress_t *agg, PokerAI *ai, VarTran_t h, int (*IsBetter)(int eval, int evalclass)) {

	int stack = h.stack;
	int round = h.round;
	//int pwr   = h.pwr;
	//int pv    = h.pv;
	
	int eval  = h.pwr;
	if (agg->type == 1) {
		eval = h.pwr;
	}
	
	int my_pos 				 = agg->my_pos;
	int beforeme_least_stack = agg->beforeme_least_stack;
	int behindme_best_stack  = agg->behindme_best_stack;
	int sum_other_stack      = agg->sum_other_stack;	
	int is_aggress			 = agg->level;
		
	//~~~~~~~~~~~~~
	int aggbet = MAX(rand()%80, rand()%(is_aggress*stack/10+1));
	//int call_no = ai->game.call_no;
	if (is_aggress 															&& 
		(ai->action.type == ACTION_FOLD||ai->action.type == ACTION_CHECK) 	){
		ai->game.call_no++;
	}
	if (is_aggress == 3) {
		DBASPRINTF("[%4d]===[in-%d-of-%d-lv-%d]", round, my_pos, h.noPlayers, is_aggress);
		if (IsBetter(eval, 3)) {
			aggbet = power3(h.call_no);
			DBASPRINTF("---call %d", h.call_amount);
			AggSetCall();
		} else if (IsBetter(eval, 4)) {
			DBASPRINTF("---raise %d", 4*aggbet);
			AggSetBet(4*aggbet);			
		} else if (h.pv >= 12) {
			DBASPRINTF("---raise %d", 2*aggbet);
			AggSetBet(2*aggbet);
		} else {
			DBASPRINTF("---call %d", h.call_amount);
			AggSetCall();			
		}
		DBASPRINTF("\n");		
	} if (is_aggress == 2) {
		DBASPRINTF("[%4d]===[in-%d-of-%d-lv-%d]", round, my_pos, h.noPlayers, is_aggress);
		if (IsBetter(eval, 3)) {
			DBASPRINTF("---raise %d", 2*aggbet);
			AggSetBet(2*aggbet);		
		} else if (IsBetter(eval, 4)) {
			DBASPRINTF("---raise %d", 2*aggbet);
			AggSetBet(2*aggbet);
		}
		DBASPRINTF("\n");			
	} else if (is_aggress == 1){
		DBASPRINTF("[%4d]===[in-%d-of-%d-lv-%d-%d<<%d<<%d]", round, my_pos, h.noPlayers, is_aggress, behindme_best_stack, stack, beforeme_least_stack);
		if (IsBetter(eval, 2)) {
			aggbet = MIN(aggbet*2, rand()%(ai->game.raise_no*behindme_best_stack/2+1));
			DBASPRINTF("---raise %d", aggbet);
			AggSetBet(aggbet);
		} else if (IsBetter(eval, 3)) {
			aggbet = MIN(aggbet*2, rand()%(ai->game.raise_no*behindme_best_stack/4+1));
			DBASPRINTF("---raise %d", aggbet);
			AggSetBet(aggbet);
		} else if (IsBetter(eval, 4)) {
			DBASPRINTF("---raise %d", aggbet);
			AggSetBet(aggbet);
		}
		DBASPRINTF("\n");
	} // END 激进地争取名次
	
	// 排第一的时候,如果对方没有机会赢,一直fold
	int all_fold_lost_money = (600-round)*(1.5*h.BB)/h.noPlayers;
	if (my_pos == 1 && (stack-sum_other_stack-all_fold_lost_money>0) ) {		
		if (IsBet() || IsAllin()) {SetCall();}
		if (IsCall()) {SetFold();}
		printf("--- fold till end --- no.1 ---\n");
	}	
}
Example #7
0
CPU_STATUS __INTERNAL_FUNC__ ChaosVmCpuRunStepOver(PCHAOSVM_CPU pCPU) {
    CPU_STATUS Status;
    __byte bInt8CodeByte;
    __byte bInstructionLength;

    ChaosVmCpuPrepareForRun(pCPU);

    /*
     * 调用HOOK函数
     */
    Status = ChaosVmCpuInternalCallHookRoutineExecuteInstruction(pCPU);
    if (__CPU_STATUS_HOOK_STOP_CPU__ == Status)
        return Status;
    else if(__CPU_STATUS_HOOK_HANDLE__ == Status)
        return Status;

    /*
     * 读取指令
     */
    if (!__CPU_STATUS_SUCCESS__(ChaosVmMmReadCode(pCPU, __CPU_SR__(pCPU, CHAOSVM_SR_CS), __CPU_EIP__(pCPU), __CPU_CONTEXT_OPCODE_BUFFER_SIZE__, \
                                pCPU->OpcodeBuffer,  &(pCPU->bOpcodeMaxLength)))) {
        return __GET_LAST_STATUS__(pCPU);
    }

    /*
     * 是不是CALL指令?
     */
    bInstructionLength = IsCall(pCPU, pCPU->OpcodeBuffer, pCPU->bOpcodeMaxLength);
    if (bInstructionLength)//是CALL指令则运行到一条指令
        return ChaosVmCpuRunToAddress(pCPU, __CPU_EIP__(pCPU) + bInstructionLength);

    /*
     * 是不是带前缀的串指令?
     */
    bInstructionLength = IsRepString(pCPU, pCPU->OpcodeBuffer, pCPU->bOpcodeMaxLength);
    if (bInstructionLength)//是带前缀的串指令则运行到下一条指令
        return ChaosVmCpuRunToAddress(pCPU, __CPU_EIP__(pCPU) + bInstructionLength);

    /*
     * 不是CALL指令和带前缀串指令则单步执行
     */

    /*
     * 如果是TF标志设置了,则在设置单步模式
     */
    pCPU->bIsSingleStepMode = (__EFLAG_SET__ == __CPU_EFLAG_GET__(pCPU, CHAOSVM_ER_TF)) ? 1 : 0;
    __READ_IMM_UINT8_SAFE__(pCPU, pCPU->bOpcodeLength, bInt8CodeByte);

    Status = pCPU->OneOpcodeTableEntry[bInt8CodeByte].DispatchFunction(pCPU);

    /*
     * 如果当前没有发生中断,且处于单步模式,则触发1号中断(但并处理中断)
     */
    if (!__CPU_IS_INTERRUPT_OCCUR__(pCPU) && (pCPU->bIsSingleStepMode)) {
        /*
         * 清除TF标志
         */
        __CPU_EFLAG_SET__(pCPU, CHAOSVM_ER_TF, __EFLAG_SET__);

        pCPU->InterruptInfomation.bInterruptId = 1;
        pCPU->InterruptInfomation.dwErrorCode = 0;
        Status = __CPU_STATUS_INTERRRUPT_OCCUR__;
    }

    return Status;
}