⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bluff pokerview.cpp

📁 Bluff Poker
💻 CPP
📖 第 1 页 / 共 3 页
字号:
		g_patterns[1].handsplayed++;

		people++;
	}
	if (g_clients[2].in == TRUE)
	{
		hand3 = EvaluateMultiples(g_hand3[0], g_hand3[1],
			g_hand3[2], g_hand3[3], g_hand3[4]);
		r3 = RankHand(hand3);
		
		if (g_patterns[2].handsplayed >= MAX_HANDS)
		{
			g_patterns[2].handsplayed = MAX_HANDS - 1;
			for (int l = 1; l < MAX_HANDS; l++)
				g_patterns[2].handranks[l-1] = g_patterns[2].handranks[l];
		}
		g_patterns[2].handranks[g_patterns[2].handsplayed] = r3;
		g_patterns[2].handsplayed++;

		people++;
	}
	if (g_clients[3].in == TRUE)
	{
		hand4 = EvaluateMultiples(g_hand4[0], g_hand4[1],
			g_hand4[2], g_hand4[3], g_hand4[4]);
		r4 = RankHand(hand4);
		
		if (g_patterns[3].handsplayed >= MAX_HANDS)
		{
			g_patterns[3].handsplayed = MAX_HANDS - 1;
			for (int l = 1; l < MAX_HANDS; l++)
				g_patterns[3].handranks[l-1] = g_patterns[3].handranks[l];
		}
		g_patterns[3].handranks[g_patterns[3].handsplayed] = r4;
		g_patterns[3].handsplayed++;

		people++;
	}
	//hand_t hands[4] = { hand1, hand2, hand3, hand4 };
	hyper hand[4] = { r1, r2, r3, r4 };
	hyper score;
	int total = 0;
	winners_t ret;
	ret.numwinners = 1;
	for (int i = 0; i < 4; i++)
		ret.winners[i] = 0;
	for (i = 0; i < 4; i++)
	{
		score = hand[i];
		for (int j = 0; j < total; j++)
		{
			if (score > hand[j])
				break;
		}
		for (int k = total; k > j; k--)
		{
			hand[k] = hand[k-1];
		}
			
		hand[j] = score;
		total++;
	}
	int split = 1;
	if (hand[0] == hand[1])
	{
		split = 2;
	}
	if (hand[0] == hand[2])
	{
		split = 3;
	}
	if (hand[0] == hand[3])
	{
		split = 4;
	}
	if (hand[0] == r1 && g_clients[0].in == TRUE)
		TextMessage(split, hand1);
	else if (hand[0] == r2 && g_clients[1].in == TRUE)
		TextMessage(split, hand2);
	else if (hand[0] == r3 && g_clients[2].in == TRUE)
		TextMessage(split, hand3);
	else if (hand[0] == r4 && g_clients[3].in == TRUE)
		TextMessage(split, hand4);
	i = 0;
	if (hand[0] == r1 && g_clients[0].in == TRUE)
	{
		ret.winners[i] = 1;
		i++;
	}
	if (hand[0] == r2 && g_clients[1].in == TRUE)
	{
		ret.winners[i] = 2;
		i++;
	}
	if (hand[0] == r3 && g_clients[2].in == TRUE)
	{
		ret.winners[i] = 3;
		i++;
	}
	if (hand[0] == r4 && g_clients[3].in == TRUE)
	{
		ret.winners[i] = 4;
		i++;
	}
	ret.numwinners = split;
	return ret;
}

void Ante();
void NextPerson(int check);

void InitializeHand()
{
	AddToEdit("-------------------------------------------------");
	g_peoplein = g_people;
	g_played = 0;
	g_needinitialize = 0;
	for(int i = 0; i < 4; i++)
	{
		g_clients[i].allin = FALSE;
		if (g_clients[i].ingame == FALSE)
			g_clients[i].in = FALSE;
		else
			g_clients[i].in = TRUE;
		g_clients[i].inpot = 0;
		g_clients[i].called = FALSE;
		g_clients[i].acted = FALSE;
	}
	g_bet = 0;
	g_pot = 0;
	g_allin = FALSE;
	g_allinperson = 0;
	g_allinamt = 0;
	g_showcards = FALSE;
	g_ante += 5;
	//CString strText;
	//strText.Format("It's player %i's turn.", g_active + 1);
	//AddToEdit(strText);
	if (g_clients[g_active].ingame == FALSE)
		NextPerson(0);
	else
	{
		if (g_active == -1)
			NextPerson(0);
		else
		{
			g_active--;
			NextPerson(0);
		}
	}
	Ante();
	ShuffleDeck();
	DealHand();
}

int g_gameinitialize = 0;

void InitializeGame()
{
	for (int i = 0; i < 4; i++)
	{
		g_clients[i].ingame = TRUE;
		g_clients[i].money = 25000;
		g_patterns[i].handsplayed = 0;
		for (int j = 0; j < MAX_HANDS; j++)
			g_patterns[i].handranks[j] = 0;
	}
	g_gameinitialize = 0;
	g_active = -1;
	g_edMessages.SetWindowText("");
	g_showwinner = FALSE;
	g_people = 4;
//	SetTimer(1, 1, NULL);
	g_ante = 5;
	InitializeHand();
	
}

void Call(int person);

void Check(int person)
{
	// more of my crappy fixes!!
	if (g_clients[person].acted == TRUE)
		return;
	if (g_bet > 0)
	{
		Call(person);
		return;
	}
	/////
	CString strText;
	strText.Format("Player %i checks.", person + 1);
	AddToEdit(strText);
	g_clients[person].acted = TRUE;
	g_played++;
	if (g_played == g_people)
		g_showcards = TRUE;
}

void CheckEndOfGame()
{
	g_people = 4;
	int people = 4;
	for (int i = 0; i < 4; i++)
	{
		if (g_clients[i].money == 0)
		{
			if (i == 0)
			{
				AfxMessageBox("You lose! Click OK to play again.");
				g_gameinitialize = 1;
				return;
			}
			g_clients[i].ingame = FALSE;
			people--;
			g_people--;
		}
	}
	if (people == 1)
	{
		for (i = 0; i < 4; i++)
			if (g_clients[i].ingame == TRUE)
			{
				g_strMessage.Format("Player %i wins!", i + 1);
				AddToEdit(g_strMessage);
				g_showwinner = TRUE;
				//AfxMessageBox(g_strMessage + " Go to File->New to play again.");
				//KillTimer(1);
				//ShowWinner(i);
				//InitializeGame();
				return;
			}
	}
}

void EveryoneCalled()
{
	int failed = 0;
	for (int i = 0; i < 4; i++)
	{
		if (g_clients[i].in == FALSE || g_clients[i].ingame == FALSE)
			continue;
		if (g_clients[i].called == FALSE)
			failed = 1;
	}
	for (i = 0; i < 4; i++)
	{
		if (g_clients[i].in == FALSE || g_clients[i].ingame == FALSE)
			continue;
		if(g_clients[i].allin == FALSE)
			if (failed == 1)
				return;
	}
	g_showcards = TRUE;
}

void Fold(int person)
{
	if (g_clients[person].acted == TRUE)
		return;
	g_clients[person].in = FALSE;
	g_strMessage.Format("Player %i folds.", person + 1);
	g_clients[person].acted = TRUE;
	AddToEdit(g_strMessage);
	int people = 4;
	for (int i = 0; i < 4; i++)
		if (g_clients[i].in == FALSE)
			people--;
	if (people == 1)
	{
		for (i = 0; i < 4; i++)
			if (g_clients[i].in == TRUE)
			{
				g_clients[i].money += g_pot;
				g_strMessage.Format("Player %i wins the pot.", i + 1);
				AddToEdit(g_strMessage);
				//InitializeHand();
				g_needinitialize = 1;
				return;
			}
	}
	
	EveryoneCalled();
}

void Bet(int person, int amt, int ante);

void Call(int person)
{
	if (g_clients[person].acted == TRUE)
		return;
	int callamt = g_bet - g_clients[person].inpot - g_ante;
	Bet(person, callamt, 0);
	CString strText;
	strText.Format("Player %i calls.", person + 1);
	AddToEdit(strText);
	g_clients[person].called = TRUE;
	g_clients[person].acted = TRUE;
	EveryoneCalled();
}

void Bet(int person, int amt, int ante)
{
	if (g_clients[person].acted == TRUE)
		return;
	int callamt = g_bet - (g_clients[person].inpot - g_ante);
	int i = person;
	if (amt == 0)
		return;
	if (amt < callamt)
		amt = callamt;
	if(g_allin == TRUE && (amt > g_allinamt))
		amt = g_allinamt;
	if(amt >= g_clients[i].money)
	{

		g_clients[i].allin = TRUE;
		g_allin = TRUE;
		g_allinamt = g_clients[i].money;
		for (i = 0; i < 4; i++)
		{
			if (g_clients[i].in && g_clients[i].inpot > g_clients[person].money)
			{
				int tmp = g_clients[i].inpot - g_clients[person].money;
				g_clients[i].inpot -= tmp;
				g_clients[i].money += tmp;
				g_pot -= tmp;
			}
		}
		i = person;
		if (ante == 0)
			g_bet = g_allinamt;
		g_clients[person].inpot += g_clients[person].money;
		g_pot += g_clients[person].money;
		CString strText;
		strText.Format("Player %i goes all-in with $%i.", person + 1, g_clients[person].money);
		if (amt > g_bet)
		{
			for (i = 0; i < 4; i++)
				g_clients[i].called = FALSE;
		}
		g_clients[person].called = TRUE;
		g_clients[person].acted = TRUE;
		AddToEdit(strText);
		g_clients[person].money = 0;
		//g_clients[i].bet = g_clients[person].money;
		
		return;
	}
	if (amt > g_bet && ante == 0)
	{
		if (g_bet == 0)
		{
			CString strText;
			strText.Format("Player %i bets $%i.", person + 1, amt);
			AddToEdit(strText);
			for (i = 0; i < 4; i++)
				g_clients[i].called = FALSE;
			g_clients[person].called = TRUE;
			g_clients[person].acted = TRUE;
		}
		else
		{
			CString strText;
			strText.Format("Player %i raises to $%i.", person + 1, amt);
			AddToEdit(strText);
			g_clients[person].acted = TRUE;
			for (i = 0; i < 4; i++)
				g_clients[i].called = FALSE;
			g_clients[person].called = TRUE;
		}
		g_bet += amt - g_bet;
	}
	if (amt == g_bet)
	{
		CString strText;
		strText.Format("Player %i calls.", person + 1);
		g_clients[person].acted = TRUE;
	}
	if (ante == 0)
		g_clients[person].inpot += amt;
	g_clients[person].money -= amt;
	g_pot += amt;
	

}

//CDC* g_pDC;
int g_quit = 0;

void RunPlayer()
{
	g_clients[g_active].acted = FALSE;
	CPlayerDlg dlg;
	int ret = dlg.DoModal();
	if (ret == IDCANCEL)
	{
		PostQuitMessage(0);
		g_quit = 1;
		return;
	}
	switch(dlg.m_nAction)
	{
		case IDC_FOLD:
			if (g_bet == 0)
				Check(g_active);
			else
				Fold(g_active);
			break;
		case IDC_CHECKCALL:
			if (g_bet == 0)
				Check(g_active);
			else
				Call(g_active);
			break;
		case IDC_BETRAISE:
			Bet(g_active, dlg.m_nBet + g_bet, 0);
			break;
		default:
			break;
	}
}

void Ante()
{
	int newante = g_ante;
	for (int i = 0; i < 4; i++)
	{
		if (g_clients[i].ingame == TRUE)
			if (g_clients[i].money < g_ante)
				newante = g_clients[i].money;
	}
	for (i = 0; i < 4; i++)
	{
		if (g_clients[i].ingame == TRUE)
			Bet (i, newante, 1);
	}
	if (g_allin == TRUE)
		g_showcards = TRUE;
}



void Wait(DWORD ms)
{

	MSG msg;
	DWORD goal = GetTickCount() + ms;
	DWORD g1 = GetTickCount() + 1;
	while(goal > GetTickCount())
	{
	    if (g1 > GetTickCount())
		{
			PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE);
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
			//if (msg.message == WM_QUIT)
			//{
			//	g_quit = 1;
			//}
	}
}

// A quick crappy fix for my AI bug

void QuickCrappyFixForMyAIBug(int person)
{
	
	if (g_clients[person].acted == FALSE && (g_clients[person].in == TRUE || g_clients[person].ingame == TRUE))
	{
		SeedRandom();
		hand_t hand;
		hyper rank = 0;
		if (person == 1)
		{
			hand = EvaluateMultiples(g_hand2[0], g_hand2[1],
				g_hand2[2], g_hand2[3], g_hand2[4]);
			rank = RankHand(hand);
		}
		if (person == 2)
		{
			hand = EvaluateMultiples(g_hand3[0], g_hand3[1],
				g_hand3[2], g_hand3[3], g_hand3[4]);
			rank = RankHand(hand);
		}
		if (person == 3)
		{
			hand = EvaluateMultiples(g_hand4[0], g_hand4[1],
				g_hand4[2], g_hand4[3], g_hand4[4]);
			rank = RankHand(hand);
		}
		if (hand.hand == 1 && g_bet > 0)
			Fold(person);
		else
			Check(person);
		if (hand.hand == 2 && g_bet > 0)
			Call(person);
		else
			Check(person);
		if (hand.hand == 3 && g_bet > 0)
			Call(person);
		else
			Check(person);
		if (hand.hand > 3 && g_bet > 0)
			Call(person);
		else
			Bet(person, g_clients[person].money, 0);
	}
}


void NextPerson(int check)
{
	
	g_previous = g_active;
	
	if (check == 1)
		QuickCrappyFixForMyAIBug(g_active);
	if (g_showcards == TRUE)
		return;
	// ^ Hey, I'm only 15, never did anything with AI, spent the last 2 weeks working on this,
	// had a long day, got lost in Washington D.C. for an hour and a half, didn't get to spend
	// much time at the WW II memorial, didn't get to see much at all, and I'm having a bad day.
	// Cut me some slack.

	do
	{
		g_active++;
		if (g_active > 3)
			g_active = 0;
	}
	while (g_clients[g_active].ingame == FALSE || g_clients[g_active].in == FALSE);
	
	if (g_clients[g_active].money == 0)
	{
		g_showcards = TRUE;
		return;
	}
	else if (g_needinitialize == 0)
	{
		CString strText;
		strText.Format("It's player %i's turn.", g_active + 1);
		AddToEdit(strText);
	}
}

int g_onewin = 0;
int g_twowin = 0;
int g_threewin = 0;
int g_fourwin = 0;

void DivideWinnings()
{
	g_onewin = 0;
	g_twowin = 0;
	g_threewin = 0;
	g_fourwin = 0;
	CString strText;
	if (g_winners.numwinners == 1)
		strText = "Winner: ";
	else
		strText = "Winners: ";
	for (int i = 0; i < g_winners.numwinners; i++)
	{
		switch(g_winners.winners[i] - 1)
		{
			case 0:
				g_onewin = 1;
				break;
			case 1:
				g_twowin = 1;
				break;
			case 2:
				g_threewin = 1;
				break;
			case 3:
				g_fourwin = 1;
				break;
			default:
				break;
		}
		CString str;
		str.Format("%i ", g_winners.winners[i]);
		strText += str;
		g_clients[g_winners.winners[i] - 1].money += g_pot / g_winners.numwinners;
	}
	AddToEdit(strText);
}

float GetPercentage(int person)
{
	int goodhands = 0;
	for (int i = 0; i <= g_patterns[person].handsplayed; i++)
		if (g_patterns[person].handranks[i] > 20000000000)
			goodhands++;
	float ret = (float)goodhands/(float)g_patterns[person].handsplayed;
	return ret;
}

BOOL LikelyBluffing (int person)
{
	SeedRandom();
	if (g_patterns[person].handsplayed < 5)
		return FALSE;
	float percent = GetPercentage(person);
	int total = g_clients[person].inpot + g_clients[person].money;
	float inpotpercent = (float)((float)total / (float)g_clients[person].inpot);
	percent *= inpotpercent;
	percent *= 1000;
	if (rand() % 10000 < percent)
		return TRUE;
	else
		return FALSE;

}

BOOL Bluff(int person)
{
	if (g_clients[person].money < 1000)
		return FALSE;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -