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

📄 bluff pokerview.cpp

📁 Bluff Poker
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	if (rand() % 6 == 0)
	{
		int callamt = g_bet - g_clients[person].inpot - g_ante;
		int action = rand () % 3;
		switch(action)
		{
			case 0:
				Bet(person, g_clients[person].money, 0);
				break;
			case 1:
				if (g_bet == 0)
					Bet(person, g_clients[person].money * 0.1 * (1 + rand() % 4), 0);
				else
					Bet(person, callamt + (int)floor((float)g_clients[person].money/(float)20) + rand() % (int)floor((float)g_clients[person].money/(float)10), 0);
				break;
			case 2:
				if (g_bet == 0)
					Bet(person, g_clients[person].money * .3 + (1 + rand() % 1000), 0);
				else
					Bet(person, callamt + g_clients[person].money * .3 + (1 + rand() % 1000), 0);
				break;
			default:
				Bet(person, g_clients[person].money, 0);
				break;
		}
		return TRUE;
	}
	return FALSE;
}

void RunComputerAI()
{
	g_clients[g_active].acted = FALSE;
	Wait(1500);
	SeedRandom();
	hand_t hand;
	int callamt = 0;
	int inpot = g_clients[g_active].inpot - g_ante;
	if (g_bet != 0)
		callamt = g_bet - g_clients[g_active].inpot - g_ante;
	hyper rank = 0;
	if (g_active == 1)
	{
		hand = EvaluateMultiples(g_hand2[0], g_hand2[1],
			g_hand2[2], g_hand2[3], g_hand2[4]);
		rank = RankHand(hand);
	}
	if (g_active == 2)
	{
		hand = EvaluateMultiples(g_hand3[0], g_hand3[1],
			g_hand3[2], g_hand3[3], g_hand3[4]);
		rank = RankHand(hand);
	}
	if (g_active == 3)
	{
		hand = EvaluateMultiples(g_hand4[0], g_hand4[1],
			g_hand4[2], g_hand4[3], g_hand4[4]);
		rank = RankHand(hand);
	}

	if (rank > 10000000000 && rank < 20000000000)
	{
		if (FALSE == Bluff(g_active))
		{		
			if (g_bet != 0 && inpot <= inpot + g_clients[g_active].money * .02)
				if ((rand() % 3) == 0 && rank > 11000000000)
				{
					if (inpot > (inpot + g_clients[g_active].money) * 0.6)
						Call(g_active);
					else
						Fold(g_active);
				}
				else
					Fold(g_active);
			else
				Check(g_active);
		}
	}
	
	int shouldcall = 0;
	
	if (rank > 20000000000 && rank < 30000000000)
	{
		
		for (int i = 0; i < 4; i++)
		{
			if (i == g_active || g_clients[i].in == FALSE || g_clients[i].ingame == FALSE)
				continue;
			if (LikelyBluffing(i) == TRUE && g_bet > 0)
				shouldcall = 1;
			else
				shouldcall = 0;
		}
		if (shouldcall == 1)
		{
			Call(g_active);
			return;
		}
		if (g_bet == 0)
			if (rank > 20300000000 && rand() % 2 == 0)
				Bet(g_active, callamt + (int)floor((float)g_clients[g_active].money/(float)30) + rand() % (int)floor((float)g_clients[g_active].money/(float)25), 0);
			else
				Check(g_active);
		else if (g_bet != 0 && inpot <= inpot + g_clients[g_active].money * .05)
			if (inpot <= inpot + g_clients[g_active].money * .03 && rand() % 2 == 0)
				Bet(g_active, (int)floor((double)(callamt * 1.5)), 0);
			else
				Call(g_active);
		else
			Fold(g_active);
	}
	
	int tmp = rand() % 3;
	
	if (rank > 30000000000 && rank < 40000000000)
	{
		for (int i = 0; i < 4; i++)
		{
			if (i == g_active || g_clients[i].in == FALSE || g_clients[i].ingame == FALSE)
				continue;
			if (LikelyBluffing(i) == TRUE && g_bet > 0)
				shouldcall = 1;
		}
		if (shouldcall == 1)
		{
			Call(g_active);
			return;
		}
		if (g_bet == 0)
		{
			int kicker = hand.kickers[0];
			if (kicker == 14)
				kicker = 5;
			if (rand() % 5 < 4)
				if (kicker > 1 && rand() % (int)floor((int)(100 / kicker)) >= 20)
					Bet(g_active, g_clients[g_active].money, 0);
				else
					Bet(g_active, g_clients[g_active].money * 0.1 * (kicker+1), 0);
			else
				Check(g_active);
		}
		
		if (g_bet > 0 && rank < 30200000000 && (inpot > 0 || rand() % 2 == 0))
			if (g_bet != 0 && inpot <= inpot + g_clients[g_active].money * .12)
				if (tmp == 0)
					Bet(g_active, callamt + (int)floor((float)g_clients[g_active].money/(float)20) + rand() % (int)floor((float)g_clients[g_active].money/(float)10), 0);
				else 
					if (tmp == 1)
						Call(g_active);
					else
						Fold(g_active);
			else
				Fold(g_active);
	}
	if (rank > 40000000000 && rank < 50000000000)
	{
		if (g_bet > 0)
			if (rand() % 2 == 0)
				Bet(g_active, g_clients[g_active].money, 0);
			else
				if (callamt < g_clients[g_active].money * .3)
					Bet(g_active, callamt + g_clients[g_active].money * .3 + (100 + rand() % 1000), 0);
				else
					Call(g_active);
		else
			if (tmp == 0)
				Bet(g_active, g_clients[g_active].money, 0);
			else if (tmp == 1)
				Bet(g_active, g_clients[g_active].money * .3 + (1 + rand() % 1000), 0);
			else
				Check(g_active);
	}
	if (rank > 60000000000)
	{
		if (g_bet > 0)
			if (rand() % 2 == 0)
				Bet(g_active, g_clients[g_active].money, 0);
			else
				if (callamt < g_clients[g_active].money * .2)
					Bet(g_active, g_clients[g_active].money * .5 + (100 +rand() % 1000), 0);
				else
					Call(g_active);
		else
			if (tmp == 0)
				Bet(g_active, g_clients[g_active].money, 0);
			else
				Bet(g_active, g_clients[g_active].money * .5 + (1 + rand() % 1000), 0);
	}			
}

void RunFrame(CBluffPokerView* pView)
{
	// alright, i needa think this one out.
	if (g_showcards == FALSE)
		if (g_active == 0)
			RunPlayer();
		else
			RunComputerAI();
//	if (g_quit == 0)
		if (g_showcards == TRUE)
		{
			//ShowCards();
			g_winners = ResultsHand();
			DivideWinnings();
			pView->OnDraw(pView->GetDC());
			CheckEndOfGame();
			g_needinitialize = 1;
			
		}
		else
			NextPerson(1);
}

int g_startyellow = 0;
CRect g_rect(466, 325, 539, 365);

void DrawStartButton (CDC* pDC)
{
	//CRect rect(466, 325, 539, 365);
	pDC->Rectangle(465, 324, 540, 366);
	if (g_startyellow == 1)
	{
		pDC->FillSolidRect(g_rect, RGB(255, 255, 0));
		pDC->SetBkColor(RGB(255, 255, 0));
	}
	else
	{
		pDC->SetBkColor(RGB(0, 150, 0));
		pDC->FillSolidRect(g_rect, RGB(0, 150, 0));
	}
	pDC->TextOut(487, 335, "Start");
}

void DrawSplashScreen(CDC* pDC)
{
	pDC->FillSolidRect(CRect(0,0,1024,768), RGB(0, 150, 0));
	for (int i = 0; i < 4; i++)
		(*_cards.DrawCard)(pDC->GetSafeHdc(), (i*70) + 325, 200, (i*4) + 38, 0, RGB(255,255,255));
	(*_cards.DrawCard)(pDC->GetSafeHdc(), (i*70) + 325, 200, 2, 0, RGB(255,255,255));
	pDC->TextOut(466, 300, "Bluff Poker");
	DrawStartButton(pDC);
}

void ClearScreen(CDC* pDC)
{
	for (int i = 0; i < 5; i++)
		(*_cards.DrawCard)(pDC->GetSafeHdc(), (i*70) + 325, 200, 0, 4, RGB(0, 150, 0));
	pDC->SetBkColor(RGB(0, 150, 0));
	pDC->TextOut(388, 300, "                                                         ");
}

/////////////////////////////////////////////////////////////////////////////
// CBluffPokerView



IMPLEMENT_DYNCREATE(CBluffPokerView, CView)

BEGIN_MESSAGE_MAP(CBluffPokerView, CView)
	//{{AFX_MSG_MAP(CBluffPokerView)
	ON_COMMAND(ID_FILE_NEW, OnFileNew)
	ON_WM_TIMER()
	ON_WM_CREATE()
	ON_WM_LBUTTONDOWN()
	ON_WM_MOUSEMOVE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBluffPokerView construction/destruction

CBluffPokerView::CBluffPokerView()
{
	CSize sSize(0,0);
	(*_cards.InitCards)((int *)&sSize.cx, (int *)&sSize.cy);
//	InitializeGame();
//	SetTimer(1, 1, NULL);
}

CBluffPokerView::~CBluffPokerView()
{
}

BOOL CBluffPokerView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CBluffPokerView drawing

int g_gamestarted = 0;

void CBluffPokerView::OnDraw(CDC* pDC)
{
	CBluffPokerDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	//g_pDC = pDC;
	pDC->SetBkColor(RGB(0, 150, 0));
	//g_edMessages.GetDC()->FillSolidRect(CRect(0,0,600,600), RGB(255,255,255));
	//390, 360, 1000, 596
	
	
	CBluffPokerApp* pApp = (CBluffPokerApp*)AfxGetApp();
	CMainFrame* pFrame = (CMainFrame*)pApp->GetMainWnd();
	pFrame->SetWindowText("Bluff Poker by Eric Idelson (erici_69@yahoo.com)");
	if (g_gamestarted == 0)
	{
		DrawSplashScreen(pDC);
		return;
	}
	pDC->FillSolidRect(CRect(0,0,390,768), RGB(0, 150, 0));
	pDC->FillSolidRect(CRect(390,0,1024,360), RGB(0, 150, 0));
	pDC->FillSolidRect(CRect(390,596,1024,768), RGB(0, 150, 0));
	pDC->FillSolidRect(CRect(1000,360,1024,596), RGB(0, 150, 0));
	//g_strMessage += "                                                           ";
	//pDC->TextOut(20, 500, g_strMessage);
	//g_strMessage = "";
	CString strText;
	CString strTmp;
	if (g_clients[0].ingame == TRUE)
	{
		
		if (g_clients[0].in == TRUE)
			DrawHand(pDC, CPoint(20,80), 0);
		else
			DrawHand(pDC, CPoint(20,80), -1);
		
		if (g_clients[0].money == 0)
			strTmp = "All-in";
		else
			strTmp.Format("$%i", g_clients[0].money);
		strText.Format("Player 1: %s                   ", strTmp);

		if ((g_active == 0 && g_showcards == FALSE) || (g_showcards == TRUE && g_onewin == 1))
			pDC->SetTextColor(RGB(255, 255, 0));
		else
			pDC->SetTextColor(RGB(0, 0, 0));
		
		pDC->TextOut(20, 180, strText);
	}
	else
	{
		DrawHand(pDC, CPoint(20,80), -1);
		pDC->TextOut(20, 180, "                                ");
	}
	pDC->SetTextColor(RGB(0, 0, 0));
	if (g_clients[1].ingame == TRUE)
	{
		if (g_clients[1].in == TRUE)
			DrawHand(pDC, CPoint(20,220), 1);
		else
			DrawHand(pDC, CPoint(20,220), -1);
		
		if (g_clients[1].money == 0)
			strTmp = "All-in";
		else
			strTmp.Format("$%i", g_clients[1].money);
		strText.Format("Player 2: %s                   ", strTmp);
		
		if ((g_active == 1 && g_showcards == FALSE) || (g_showcards == TRUE && g_twowin == 1))
			pDC->SetTextColor(RGB(255, 255, 0));
		else
			pDC->SetTextColor(RGB(0, 0, 0));
		
		pDC->TextOut(20, 320, strText);
	}
	else
	{
		DrawHand(pDC, CPoint(20,220), -1);
		pDC->TextOut(20, 320, "                                ");
	}
	pDC->SetTextColor(RGB(0, 0, 0));
	if (g_clients[2].ingame == TRUE)
	{
		
		if (g_clients[2].in == TRUE)
			DrawHand(pDC, CPoint(20,360), 2);
		else
			DrawHand(pDC, CPoint(20,360), -1);
		
		if (g_clients[2].money == 0)
			strTmp = "All-in";
		else
			strTmp.Format("$%i", g_clients[2].money);
		strText.Format("Player 3: %s                   ", strTmp);
		
		if ((g_active == 2 && g_showcards == FALSE) || (g_showcards == TRUE && g_threewin == 1))
			pDC->SetTextColor(RGB(255, 255, 0));
		else
			pDC->SetTextColor(RGB(0, 0, 0));
		
		pDC->TextOut(20, 460, strText);
	}
	else
	{
		DrawHand(pDC, CPoint(20,360), -1);
		pDC->TextOut(20, 460, "                                ");
	}
	pDC->SetTextColor(RGB(0, 0, 0));
	if (g_clients[3].ingame == TRUE)
	{
		
		if (g_clients[3].in == TRUE)
			DrawHand(pDC, CPoint(20,500), 3);
		else
			DrawHand(pDC, CPoint(20,500), -1);
		
		if (g_clients[3].money == 0)
			strTmp = "All-in";
		else
			strTmp.Format("$%i", g_clients[3].money);
		strText.Format("Player 4: %s                   ", strTmp);
		
		if ((g_active == 3 && g_showcards == FALSE) || (g_showcards == TRUE && g_fourwin == 1))
			pDC->SetTextColor(RGB(255, 255, 0));
		else
			pDC->SetTextColor(RGB(0, 0, 0));
		
		pDC->TextOut(20, 600, strText);
	}
	else
	{
		DrawHand(pDC, CPoint(20,500), -1);
		pDC->TextOut(20, 600, "                                ");
	}
	pDC->SetTextColor(RGB(0, 0, 0));
	strText.Format("Pot: $%i Bet: $%i                        ", g_pot, g_bet);
	pDC->TextOut(630, 250, strText);
	
//	if (g_gamestarted == 0)
//		OnFileNew();
}

//I love you
/////////////////////////////////////////////////////////////////////////////
// CBluffPokerView diagnostics

#ifdef _DEBUG
void CBluffPokerView::AssertValid() const
{
	CView::AssertValid();
}

void CBluffPokerView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CBluffPokerDoc* CBluffPokerView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CBluffPokerDoc)));
	return (CBluffPokerDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CBluffPokerView message handlers

void CBluffPokerView::OnFileNew() 
{
	// TODO: Add your command handler code here
	g_gamestarted = 1;
	ClearScreen(this->GetDC());
	g_edMessages.ShowWindow(TRUE);
	InitializeGame();
	
	while(g_showwinner == FALSE)
	{
		if (g_gameinitialize == 1)
			OnFileNew();
		
		if (g_needinitialize == 1)
		{
			Wait(4000);
			if (g_quit == 0)
			{
				InitializeHand();
				OnDraw(this->GetDC());
			}
			else
				break;
		}
		else
			OnDraw(this->GetDC());
		if (g_quit == 0)
			RunFrame(this);
		else
			break;
	}
	if (g_quit == 0)
	{
		AfxMessageBox(g_strMessage + " Go to File->New to play again.");
		OnDraw(this->GetDC());
	}
	//else
	//{
	//	PostQuitMessage(0);
	//}
	
	//SetTimer(1, 1, NULL);
}

void CBluffPokerView::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
//	if (g_showwinner == FALSE)
//		RunFrame();
	CView::OnTimer(nIDEvent);
}

/////////////////////////////////////////////////////////////////////////////
// CPlayerDlg dialog


CPlayerDlg::CPlayerDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CPlayerDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPlayerDlg)
	//}}AFX_DATA_INIT
}


void CPlayerDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPlayerDlg)
	DDX_Control(pDX, IDC_MONEY, m_edBet);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPlayerDlg, CDialog)
	//{{AFX_MSG_MAP(CPlayerDlg)
	ON_EN_CHANGE(IDC_MONEY, OnChangeMoney)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPlayerDlg message handlers

BOOL CPlayerDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_edBet.SetWindowText("1");
	CheckRadioButton(IDC_FOLD, IDC_BETRAISE, IDC_FOLD);
//	m_spSpinner.SetRange(1, g_clients[g_active].money);
	return FALSE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CPlayerDlg::OnOK() 
{
	// TODO: Add extra validation here
	m_nAction = GetCheckedRadioButton(IDC_FOLD, IDC_BETRAISE);
	if (m_nAction == IDC_BETRAISE)
	{
		CString strText;
		m_edBet.GetWindowText(strText);
		if (strText == "")
			m_nBet = 1;
		else
			m_nBet = atoi(strText);
	}
	else
		m_nBet = 0;
	CDialog::OnOK();
}

int CBluffPokerView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;
	//OnFileNew();
	// TODO: Add your specialized creation code here
	g_edMessages.Create(ES_MULTILINE | ES_READONLY | ES_LEFT | ES_AUTOVSCROLL | WS_CHILD |
		WS_BORDER, CRect (390, 360, 1000, 596), this, 1);
	g_edMessages.ShowWindow(FALSE);
	return 0;
}

void CPlayerDlg::OnChangeMoney() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	CheckRadioButton(IDC_FOLD, IDC_BETRAISE, IDC_BETRAISE);

	// TODO: Add your control notification handler code here
	
}

void CBluffPokerView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(g_gamestarted == 0 && g_rect.PtInRect(point))
	{
		g_gamestarted = 1;
		OnFileNew();
	}
	CView::OnLButtonDown(nFlags, point);
}

void CBluffPokerView::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	int tmp = g_startyellow;
	if (g_rect.PtInRect(point))
		g_startyellow = 1;
	else
		g_startyellow = 0;
	if (tmp != g_startyellow && g_gamestarted == 0)
		DrawStartButton(this->GetDC());
	CView::OnMouseMove(nFlags, point);
}

⌨️ 快捷键说明

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