static gboolean do_computer_turns (void) { if (!players[CurrentPlayer].comp) { last_timeout = 0; return FALSE; } if (ready_to_advance_player) { NextPlayer (); return TRUE; } if (players[CurrentPlayer].finished) { NextPlayer (); return TRUE; } ComputerRolling (CurrentPlayer); if (NoDiceSelected () || (NumberOfRolls >= NUM_ROLLS)) { ComputerScoring (CurrentPlayer); ready_to_advance_player = TRUE; } else { RollSelectedDice (); UpdateRollLabel (); } if (!DoDelay) do_computer_turns (); return TRUE; }
void GSVe3ViewOtherPlayers::OnActive() { GSGui::OnActive(); m_gui = LoadGui("gui-ve3-viewotherplayers.txt"); Assert(m_gui); GetElementByName(m_gui, "back-button")->SetCommand(OnBack); GetElementByName(m_gui, "prev-player-button")->SetCommand(OnPrevPlayer); GetElementByName(m_gui, "next-player-button")->SetCommand(OnNextPlayer); GetElementByName(m_gui, "make-trade-button")->SetCommand(Amju::OnMakeATrade); GetElementByName(m_gui, "see-guestbook-button")->SetCommand(Amju::OnSeeGuestbook); // Initialise character if (m_player && m_player->GetId() != GetLocalPlayerId()) // could happen if you log out, then in as this player { ShowPlayer(m_player, m_gui); } else { NextPlayer(); } SetHomeButton(); }
float alphaBetaMax(BNTBoard board, float alpha, float beta, float depthleft, BNTPlayer player) { if (depthleft == 0 || IsGameEnd(board)) return EvaluateBoard(board, player); for (int x = 0; x < BOARD_SIZE; ++x) { for (int y = 0; y < BOARD_SIZE; ++y) { if (board[x][y] == BNTPlayerNone) { board[x][y] = NextPlayer(board); float score = alphaBetaMin(board, alpha, beta, depthleft - 1, player); board[x][y] = BNTPlayerNone; if (score >= beta) { return beta; } if (score > alpha) { alpha = score; } } } } return alpha; }
int MovePlayer(BNTPlayer player, BNTField field, BNTBoard board) { if (player == BNTPlayerNone) { printf("Could not make the move: error -1"); return -1; } if (IsBoardFull(board)) { printf("Could not make the move: error -2"); return -2; } if (NextPlayer(board) != player) { printf("Could not make the move: error -3"); return -3; } if (board[field.x][field.y] == BNTPlayerO || board[field.x][field.y] == BNTPlayerX) { printf("Could not make the move: error -4"); return -4; } if (IsGameEnd(board)) { printf("Could not make the move: error -5"); return -5; } board[field.x][field.y] = player; return 1; }
void GameData::decodeUpdate_Packet(sf::Packet &packet) { sf::Vector2i mouseposition; packet >> mouseposition.x >> mouseposition.y; //do capture stuff if (gameMap.getCurrentBox(mouseposition).isCapturable()) { Box newUserBox(*playerList_it); //set the size to 50... newUserBox.setSize(sf::Vector2f(50, 50)); newUserBox.setScore(playerList_it->getNextScore()); sf::Vector2f position = gameMap.getCurrentBox(mouseposition).getPosition(); //set the new position for userBox newUserBox.setPosition(position); //set the score newUserBox.txt_score.setPosition(position.x + 5, position.y + 5); newUserBox.txt_score.setCharacterSize(30); newUserBox.txt_score.setColor(sf::Color(0, 0, 0, 255)); //copy the box into the map gameMap.captureBox(newUserBox, mouseposition); //next player move NextPlayer(); } }
void MainWindow::PlayerLeft() { ui->txt_Log->appendPlainText("You don't have enough money, you lose"); players[cPlayer]->leftGame(); players.removeAt(cPlayer); if (players.size() == 1) { QMessageBox::information(this,"The champion","The player : " + players[0]->getPiece() + " win this game",QMessageBox::Ok,QMessageBox::NoButton); ui->btn_Leave->setEnabled(false); ui->btn_Roll->setEnabled(false); } else NextPlayer(); }
void NL_Holdem::Logic() { switch (state) { case State::preflop_deal: { deck.Shuffle(); // deal cards to all players for ( auto& p : players) { p->Hand( deck.Deal(2) ); p->Output(); } // put blinds out potSize += players[CurrentPlayer()]->Bet(smallBlind); sharedGameInformation.AddPlayerAction(SharedGameInformation::PlayerAction(CurrentPlayer(), SharedGameInformation::PlayerActionType::raise, smallBlind)); NextPlayer(); potSize += players[CurrentPlayer()]->Bet(bigBlind); sharedGameInformation.AddPlayerAction(SharedGameInformation::PlayerAction(CurrentPlayer(), SharedGameInformation::PlayerActionType::raise, bigBlind)); NextPlayer(); state = State::preflop_bet; } break; case State::flop_deal: { deck.Deal(1); // burn flop = deck.Deal(3); cout << flop << endl; state = State::flop_bet; } break; default:; } }
void TurnLogic() { Short kept; Short x; // Update DrawCurrScore(); /* * Player lost turn */ if ( ( stor.scorethisroll == 0 && !stor.flash ) || StayBit ) { if ( StayBit ) { stor.player[stor.currplayer].score += stor.scorethisturn; } NextPlayer(); return; } stor.YMNWTBYM = false; DrawCurrScore(); for( x = 0 ; x < NumCubes ; x++ ) DrawKeepBit(x); kept = 0; for ( x = 0 ; x < NumCubes ; x++ ) { if ( stor.cube[x].keep ) { kept++; } } if ( kept == 5 ) { // You May Not Want To But You Must stor.YMNWTBYM = true; for ( x = 0 ; x < NumCubes ; x++ ) { stor.cube[x].keep = false; } } DrawStayButton(); StatusLine(); }
void NL_Holdem::Input() { switch (state) { case State::preflop_bet: { auto p = players.begin() + actionPos; SharedGameInformation::PlayerAction pa = (*p)->Input(sharedGameInformation); if ( pa.actionType == SharedGameInformation::PlayerActionType::call ) { // make sure players call what they need to or call all in. if (!(sharedGameInformation.HowMuchToCall(actionPos) == pa.betSize || pa.betSize == (*p)->Stack())) { cerr << "call size is invalid" << endl; exit(1); } } //if (pa.betSize != currBetSize) { // cerr << "player's action doesn't correlate to current bet size"; // exit(1); //} sharedGameInformation.AddPlayerAction(pa); if (ActionOnBB() && pa.Checked() ) { // go to next state in game state = State::flop_deal; } NextPlayer(); } break; case State::flop_bet: { hand = false; } break; default:; } }
float alphaBetaMin(BNTBoard board, float alpha, float beta, float depthleft, BNTPlayer player) { if (depthleft == 0 || IsGameEnd(board)) return -1 * EvaluateBoard(board, player); for (int x = 0; x < BOARD_SIZE; ++x) { for (int y = 0; y < BOARD_SIZE; ++y) { if (board[x][y] == BNTPlayerNone) { board[x][y] = NextPlayer(board); float score = alphaBetaMax(board, alpha, beta, depthleft - 1, player); board[x][y] = BNTPlayerNone; if(score <= alpha) return alpha; // fail hard alpha-cutoff if(score < beta) beta = score; // beta acts like min in MiniMax } } } return beta; }
long _EXPORT FAR PASCAL WndProc( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam ) /*********************************************************************/ { static HANDLE hdlginstance; static BOOL got_watzee_bonus; PAINTSTRUCT ps; FARPROC dlg_proc; HDC hdc; POINT point; short x; short y; short dy; short i; switch( message ) { case WM_CREATE : hdlginstance = ((CREATESTRUCT far *) MK_FP32((void*)lparam))->hInstance; x = CharWidth * 22 + CharWidth / 2; y = CharHeight * 3; dy = CharHeight * 3; dy += dy / 7; /* create the check marks for the dice bitmaps, and the ROLL and OK buttons */ for( i = 0; i < 5; i++, y += dy ) { CreateWindow( "BUTTON", "", WS_CHILD|WS_VISIBLE|BS_CHECKBOX, x, y, CharWidth, CharHeight, hwnd, (HMENU)(IDW_DICE1+i), hdlginstance, NULL ); } CreateWindow( "BUTTON", "ROLL", WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, x, CharHeight * 19, 9 * CharWidth / 2 , CharHeight * 2, hwnd, (HMENU)IDW_ROLL, hdlginstance, NULL ); CreateWindow( "BUTTON", "OK", WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, x, 43 * CharHeight / 2, 9 * CharWidth / 2, CharHeight * 2, hwnd, (HMENU)IDW_OK, hdlginstance, NULL ); return( 0 ); case WMW_START_NEW_GAME : dlg_proc = MakeProcInstance( (FARPROC)GetNumPlayersDialogProc, hdlginstance ); DialogBox( hdlginstance, "GetNumPlayers", hwnd, (DLGPROC)dlg_proc ); FreeProcInstance( dlg_proc ); dlg_proc = MakeProcInstance( (FARPROC)GetInitialsDialogProc, hdlginstance ); DialogBox( hdlginstance, "GetPlayersInitials", hwnd, (DLGPROC)dlg_proc ); FreeProcInstance( dlg_proc ); EnableWindow( GetDlgItem( hwnd, IDW_OK ), FALSE ); EnableWindow( GetDlgItem( hwnd, IDW_ROLL ), TRUE ); PlayingGameYet = TRUE; InvalidateRect( hwnd, NULL, FALSE ); for( i = 0; i < NumberOfPlayers; i++ ) { if( Player[i][IS_COMPUTER] ) break; } if( i < NumberOfPlayers && !GotTimer ) { while( !SetTimer( hwnd, ID_TIMER, TIMER_INTERVAL, NULL ) ) { if( MessageBox( hwnd, "Too many clocks or timers are active", AppName, MB_ICONEXCLAMATION|MB_RETRYCANCEL ) == IDCANCEL ) { DestroyWindow( hwnd ); return( 0 ); } } GotTimer = TRUE; } if( i == 0 ) { PCTurn = TRUE; EnableWindow( GetDlgItem( hwnd, IDW_ROLL ), FALSE ); } hdc = GetDC( hwnd ); RollDice( hwnd, hdc ); GetDiceInfo(); ReleaseDC( hwnd, hdc ); // SetFocus( hwnd ); return( 0 ); case WM_COMMAND : switch( LOWORD( wparam ) ) { case IDM_NEWGAME : if( GotTimer ) { KillTimer( hwnd, ID_TIMER ); } if( MessageBox( hwnd, "Start New Game: Are you sure?", "WATZEE", MB_YESNO | MB_ICONEXCLAMATION ) == IDYES ) { InitializeGameData(); InvalidateRect( hwnd, NULL, TRUE ); SendMessage( hwnd, WMW_START_NEW_GAME, 0, 0 ); } else if( GotTimer ) { SetTimer( hwnd, ID_TIMER, TIMER_INTERVAL, NULL ); } break; case IDM_OPTIONS : if( GotTimer ) { KillTimer( hwnd, ID_TIMER ); } dlg_proc = MakeProcInstance( (FARPROC)OptionsDialogProc, hdlginstance ); DialogBox( hdlginstance, "Options", hwnd, (DLGPROC)dlg_proc ); FreeProcInstance( dlg_proc ); if( GotTimer ) { SetTimer( hwnd, ID_TIMER, TIMER_INTERVAL, NULL ); } break; case IDM_EXIT : DestroyWindow( hwnd ); break; case IDM_SCORING : if( GotTimer ) { KillTimer( hwnd, ID_TIMER ); } dlg_proc = MakeProcInstance( (FARPROC)HelpDialogProc, hdlginstance ); DialogBox( hdlginstance, "WatzeeHelp", hwnd, (DLGPROC)dlg_proc ); FreeProcInstance( dlg_proc ); if( GotTimer ) { SetTimer( hwnd, ID_TIMER, TIMER_INTERVAL, NULL ); } break; case IDM_ABOUT : if( GotTimer ) { KillTimer( hwnd, ID_TIMER ); } dlg_proc = MakeProcInstance( (FARPROC)AboutDialogProc, hdlginstance ); DialogBox( hdlginstance, "AboutWatzee", hwnd, (DLGPROC)dlg_proc ); FreeProcInstance( dlg_proc ); if( GotTimer ) { SetTimer( hwnd, ID_TIMER, TIMER_INTERVAL, NULL ); } break; case IDW_DICE1 : case IDW_DICE2 : case IDW_DICE3 : case IDW_DICE4 : case IDW_DICE5 : if( !PCTurn && CurrentRoll < 2 ) { SendMessage( hwnd, WMW_DIE_CHECK, wparam, 0 ); } break; case IDW_ROLL : SendMessage( hwnd, WMW_ROLL, 0, 0 ); break; case IDW_OK : SendMessage( hwnd, WMW_OK, 0, 0 ); break; } return( 0 ); case WM_LBUTTONUP : if( !PCTurn ) { MAKE_POINT( point, lparam ); if( point.x > CharWidth * 24 && point.y < CharHeight * 20 ) { wparam = GetDieCheck( hwnd, point ); if( wparam && CurrentRoll < 2 ) { SendMessage( hwnd, WMW_DIE_CHECK, wparam, 0 ); } } else { wparam = GetScoreCheck( point ); if( wparam && Player[CurrentPlayer][wparam] == UNDEFINED ) { SendMessage( hwnd, WMW_SCORE_CHECK, wparam, 0 ); } } } return( 0 ); case WMW_DIE_CHECK : i = LOWORD( wparam ) - IDW_DICE1; Dice[i].is_checked = !Dice[i].is_checked; CheckDlgButton( hwnd, wparam, (BOOL)Dice[i].is_checked ); // SetFocus( hwnd ); return( 0 ); case WMW_SCORE_CHECK : hdc = GetDC( hwnd ); if( wparam != LastScoreSelection ) { DoScore( hdc, wparam ); EnableWindow( GetDlgItem( hwnd, IDW_OK ), TRUE ); } ReleaseDC( hwnd, hdc ); // SetFocus( hwnd ); return( 0 ); case WMW_ROLL : hdc = GetDC( hwnd ); if( DieCheckMeansRoll ) { for( i = 0; i < 5; i++ ) { if( Dice[i].is_checked ) break; } } else { for( i = 0; i < 5; i++ ) { if( !Dice[i].is_checked ) break; } } if( i < 5 ) { if( LastScoreSelection ) { Player[CurrentPlayer][LastScoreSelection] = UNDEFINED; WriteScore( hdc, CurrentPlayer, LastScoreSelection ); DoScoreTotals( hdc ); LastScoreSelection = 0; } got_watzee_bonus = FALSE; CurrentRoll++; RollDice( hwnd, hdc ); GetDiceInfo(); if( DiceInfo.got_watzee && Player[CurrentPlayer][WATZEE] == 50 ) { got_watzee_bonus = TRUE; } if( CurrentRoll == 2 ) { EnableWindow( GetDlgItem( hwnd, IDW_ROLL ), FALSE ); } } ReleaseDC( hwnd, hdc ); // SetFocus( hwnd ); return( 0 ); case WMW_OK : hdc = GetDC( hwnd ); LastScoreSelection = 0; if( got_watzee_bonus ) { DoScore( hdc, WATZEE_BONUS ); LastScoreSelection = 0; got_watzee_bonus = FALSE; } NextPlayer( hwnd, hdc ); ReleaseDC( hwnd, hdc ); // SetFocus( hwnd ); return( 0 ); case WMW_GAME_OVER : hdc = GetDC( hwnd ); WriteScoreOptions( hdc ); ReleaseDC( hwnd, hdc ); if( GotTimer ) { KillTimer( hwnd, ID_TIMER ); GotTimer = FALSE; } if( MessageBox( hwnd, "Another Game ?", "WATZEE", MB_YESNO ) == IDYES ) { InitializeGameData(); InvalidateRect( hwnd, NULL, TRUE ); SendMessage( hwnd, WMW_START_NEW_GAME, 0, 0 ); } else { DestroyWindow( hwnd ); } return( 0 ); case WM_TIMER : if( PCTurn ) { PCPlay( hwnd ); } return( 0 ); case WM_PAINT : hdc = BeginPaint( hwnd, &ps ); DrawDice( hwnd, hdc ); DrawScoreCard( hdc ); WriteScoreOptions( hdc ); if( PlayingGameYet ) { WriteInitials( hdc ); HighliteName( hdc, CurrentPlayer ); WriteScores( hdc ); } EndPaint( hwnd, &ps ); return( 0 ); case WM_DESTROY : { HBITMAP hbm; if( GotTimer ) { KillTimer( hwnd, ID_TIMER ); } for( i = 0; i < 6; i++ ) { hbm = (HBITMAP)GetWindowLong( hwnd, i * sizeof( DWORD ) ); DeleteObject( hbm ); } PostQuitMessage( 0 ); return( 0 ); } } return( DefWindowProc( hwnd, message, wparam, lparam ) ); }
void MainWindow::on_btn_Roll_clicked() { if(ui->btn_Roll->text() == "Next player") { NextPlayer(); ui->btn_Roll->setText("Roll"); return; } int oldPos = players[cPlayer]->getPos(); if(spaces[oldPos]->is2XSpeed()) ui->txt_Log->appendPlainText("2XSpeed, hurry up!!!!\nYour roll dive result is: " + QString::number(players[cPlayer]->rollDice(spaces[oldPos]->is2XSpeed()))); else ui->txt_Log->appendPlainText("Your roll dive result is: " + QString::number(players[cPlayer]->rollDice(spaces[oldPos]->is2XSpeed()))); int newPos = players[cPlayer]->getPos(); if (newPos < oldPos) { ui->txt_Log->appendPlainText(players[cPlayer]->getPiece() + " complete new round, take new 350$"); players[cPlayer]->setMoney(players[cPlayer]->getMoney() + 350); } if (spaces[newPos]->isChance()) { chance(&cPlayer); } else if (spaces[newPos]->isChest()) { chest(&cPlayer); } else if (spaces[newPos]->isPrison()) { if (players[cPlayer]->getMoney() >= 50) { ui->txt_Log->appendPlainText(players[cPlayer]->getPiece() + " fall in prison, you have to pay 50$"); players[cPlayer]->setMoney(players[cPlayer]->getMoney() - 50); } else { ui->txt_Log->appendPlainText(players[cPlayer]->getPiece() + " fall in prison, you lost the next turn"); players[cPlayer]->setLostTurn(players[cPlayer]->getLostTurn() + 1); } } else if (!spaces[newPos]->isPark()) { if (spaces[newPos]->isFree() && players[cPlayer]->getMoney() >= spaces[newPos]->getPrice()) { if (QMessageBox::question(this,"Buy a park", "Would you like to buy " + spaces[newPos]->getName(), QMessageBox::Yes,QMessageBox::No) == QMessageBox::Yes) { spaces[newPos]->setOwner(players[cPlayer]->getPiece()); players[cPlayer]->setMoney( players[cPlayer]->getMoney() - spaces[newPos]->getPrice()); if (!spaces[newPos]->isUp() && players[cPlayer]->getMoney() >= spaces[newPos]->getPrice()) { if (QMessageBox::question(this,"Upgrade", "Would you like to upgrade " + spaces[newPos]->getName() + ", it'll double price and fees too", QMessageBox::Yes,QMessageBox::No) == QMessageBox::Yes) { players[cPlayer]->setMoney( players[cPlayer]->getMoney() - spaces[newPos]->getPrice()); spaces[newPos]->upgrade(); } } } } else { if (spaces[newPos]->getOwner().compare( players[cPlayer]->getPiece()) == 0) { if (!spaces[newPos]->isUp() && players[cPlayer]->getMoney() >= spaces[newPos]->getPrice()) { if (QMessageBox::question(this,"Upgrade", "Would you like to upgrade " + spaces[newPos]->getName() + ", it'll double price and fees too", QMessageBox::Yes,QMessageBox::No) == QMessageBox::Yes) { players[cPlayer]->setMoney( players[cPlayer]->getMoney() - spaces[newPos]->getPrice()); spaces[newPos]->upgrade(); } } if (QMessageBox::question(this,"Sell", "Would you like to sell " + spaces[newPos]->getName() + ", to bank", QMessageBox::Yes,QMessageBox::No) == QMessageBox::Yes) { players[cPlayer]->setMoney( players[cPlayer]->getMoney() + spaces[newPos]->getPrice()); spaces[newPos]->setOwner("No One"); } } else { for (int l = 0; l < players.size(); ++l) { if (l != cPlayer) { if (players[l]->getPiece().compare( spaces[newPos]->getOwner()) == 0) { QMessageBox::information(this,"Notice", "You have to pay " + (QString::number(spaces[newPos]->getPrice()/ 10)) + "$ to " + players[l]->getPiece() + "player\n",QMessageBox::Ok); if (players[cPlayer]->getMoney() >= spaces[newPos]->getPrice() / 10) { players[cPlayer]->setMoney( players[cPlayer]->getMoney() - (spaces[newPos]->getPrice() / 10)); players[l]->setMoney( players[l]->getMoney() + (spaces[newPos]->getPrice() / 10)); } else { return PlayerLeft(); } } } } } } } NextPlayer(); }
void MainWindow::start() { cPlayer = -1; NextPlayer(); }