int main(int argc, char** argv) { char board[26][26]; int n; int numberOfMoves = 0; int *moves = &numberOfMoves; char computerColour, currentColour; printf("Enter the board dimension: "); scanf("%d", &n); makeBoard(board, n); printf("Computer plays (B/W) : "); scanf(" %c", &computerColour); currentColour = 'B'; char nextColour = 'W'; char tempColour; bool gameOver = 0; char rowMove, colMove; printBoard(board, n); while(!gameOver){ if(movesAvailable(board, n, currentColour)){ if(currentColour == computerColour){ decideMove(board, n, computerColour, moves); numberOfMoves++; } else{ printf("Enter move for colour %c (RowCol): ", currentColour); scanf(" %c%c", &rowMove, &colMove); if(checkLegalInPosition(board, n, rowMove - 'a', colMove - 'a', currentColour)){ makeMove(board, n, rowMove - 'a', colMove - 'a', currentColour); numberOfMoves++; } else{ printf("Invalid move.\n"); printf("%c player wins.\n", findWinner(board, n)); return 0; } } printBoard(board, n); } else{ printf("%c player has no valid move.\n", currentColour); } tempColour = currentColour; currentColour = nextColour; nextColour = tempColour; if(!movesAvailable(board, n, 'B') && !movesAvailable(board, n, 'W')){ printf("%c player wins.\n", findWinner(board, n)); gameOver = true; } } return (EXIT_SUCCESS); }
int main() { int i,a,b,ans=0,tmp; #ifndef ONLINE_JUDGE freopen("P1706.in","r",stdin); freopen("P1706.out","w",stdout); #endif scanf("%d%d",&n,&m); for (i=1; i<=m; ++i) { scanf("%d%d",&a,&b); addEdge(b,a); addEdgeR(a,b); } for (i=1; i<=n; ++i) { tmp=visited=0; FILLCHAR(vst,false); findWinner(i); tmp+=visited; visited=0; FILLCHAR(vst,false); findLoser(i); tmp+=visited; if (tmp-1==n) ++ans; } printf("%d\n",ans); return 0; }
/************************************************************ C's program execution always begins here, at main(). */ main() { int numCards; /* Equals 52 at the beginning of each game. */ int cards[52], playerPoints[2], dealerPoints[2], total[2]; char ans; /* for user's Hit/Stand or Yes/No response. */ do { initCardsScreen(cards, playerPoints, dealerPoints, total, &numCards); dealerGetsCard(&numCards, cards, dealerPoints); printf("\n"); /* Prints a blank line */ playerGetsCard(&numCards, cards, playerPoints); playerGetsCard(&numCards, cards, playerPoints); do { ans = getAns("Hit or stand (H/S)? "); if (ans == 'H') { playerGetsCard(&numCards, cards, playerPoints); } } while (ans != 'S'); /* Generate player's total score once the player stands. */ totalIt(playerPoints, total, PLAYER); do { dealerGetsCard(&numCards, cards, dealerPoints); } while (dealerPoints[ACEHIGH] < 17); /* Dealer has to stand at 17. */ totalIt(dealerPoints, total, DEALER); /* Calculate the dealer's hand total. */ findWinner(total); ans = getAns("\nPlay again (Y/N)? "); } while (ans == 'Y'); return; }
//return true if we need to continue training, false - otherwise bool KohonenNN::trainOneEpoch(const std::vector<std::shared_ptr<wv::Point>>& points, double epsilon) { //Erase offset vector for (uint32_t i = 0; i < m_NumClusters; i++) m_Neurons.at(i).getWv()->eraseOffset(); alr::AdaptLearnRateKohonenSchema alrks(m_IterNumber, m_Kp); //make iteration for (const auto p: points) { findWinner(p.get()); updateWeights(p.get(), &alrks); } //check offset value double summary_offset_value = 0; for (uint32_t i = 0; i < m_NumClusters; i++) { summary_offset_value += m_Neurons.at(i).getWv()->getOffsetValue(); } log_netw->info(" --------------------------------------------------------------------"); log_netw->info((boost::format("After %d iteration") % m_IterNumber).str()); log_netw->info((boost::format("Summary offset value = %g") % summary_offset_value).str()); for (uint32_t i = 0; i < m_NumClusters; i++) { for (uint32_t j = 0; j < m_NumDimensions; j++) log_netw->info((boost::format("%g,") % m_Neurons.at(i).getWv()->getConcreteCoord(j)).str(), true); log_netw->info("\n", true); } m_IterNumber++; return (summary_offset_value / m_NumClusters > epsilon); }
void findWinner(const int now) { if (!vst[now]) { ++visited; vst[now]=true; for (int p=head[now]; p; p=edges[p].next) findWinner(edges[p].endv); } }
void TicTacToe::results() const { char winning_symbol = findWinner(); //findWinner returns default symbol if there is no winner if(winning_symbol == game_board_.getDefaultSymbol()) std::cout << "Game over. Game was a draw\n"; else for(unsigned int i = 0; i < player_list_.size(); ++i) { if (player_list_[i].getSymbol() == winning_symbol) std::cout << "Game Over. Player " << i + 1 << " wins!\n"; } }
int main(int argc, char* argv[]){ int check = 0; DeckOfCards deck; Player player(0); Player dealer(1); deck.shuffle(); // deck.printDeck(); for (int i = 0; i < 5; ++i){ player.addCard(deck.dealCard()); dealer.addCard(deck.dealCard()); } player.sortHand(); dealer.sortHand(); player.printHand(); findWinner(player, dealer); return 0; }
int main(){ float result; char userName [40]; int i, count, choice, betMarker, pLeft; double bet, pot; Player newPlayers [PLAYERS]; /*Intro for the game*/ setup(newPlayers, userName); Deck newDeck; srand(time(NULL)); /*MAIN GAME LOOP, BASED ON GALLEONS*/ while (newPlayers[0].galleons >= 5){ printf("\n\n======== NEW ROUND ========\n\n\n"); pot = bet = 0; /*Always update each player to be in the game initially, unless they have less than 5 galleons*/ for(i = 0; i<PLAYERS; i++){ newPlayers[i].inGame = 1; if (newPlayers[i].galleons < 5){ newPlayers[i].galleons = 0; newPlayers[i].inGame = 0; newPlayers[i].checkBet = 0; } newPlayers[i].checkBet = 0; newPlayers[i].galleons = newPlayers[i].galleons - 5; if(newPlayers[i].inGame == 1){ pot = pot + 5; } } /*if the three computers are out of the game, user has won, so end the game!*/ pLeft = 0; for (i = 1; i<PLAYERS; i++){ if (newPlayers[i].inGame == 0){ pLeft++; } if (pLeft == 3){ printf("\n\nCONGRATULATIONS %s, you won! Harry, Voldy and Dumbly seem to have lost all their money!!!\n\n", newPlayers[0].name); return 0; } } sleep(2); /*Print out current standings, how many galleons each player has and if they are still in*/ printf("Current Standings:\n\n"); for (i = 0; i<PLAYERS; i++){ if (newPlayers[i].inGame == 1){ printf("%s has %.2f Galleons\n", newPlayers[i].name, newPlayers[i].galleons); } } for (i = 0; i<PLAYERS; i++){ if (newPlayers[i].inGame == 0){ printf("%s is out of the game\n", newPlayers[i].name); } } /*Initialize Game*/ fillDeck(&newDeck); shuffleDeck(&newDeck); dealOut(&newDeck, newPlayers); printf("\nYou are about to receive your hand!\n"); /*User specifics*/ sleep(1); displayHand(newPlayers); result = MC_rate(newPlayers, 0); sleep(1); /*Monte Carlo Advice in MC.c*/ advice(&newPlayers[0]); /*This exchange is only for the user, computers have its own function*/ exchangeCards(newPlayers, &newDeck); displayHand(newPlayers); printf("\nYou can now either: \n1) Place a Bet\n2) Pass\n3) Fold\nPlease type 1,2, or 3: "); scanf("%d", &choice); if (choice == 1){ bet = placeBet(newPlayers, &pot); } else if (choice == 3){ endPlayer(newPlayers, 0); } else if (choice == 2){ printf("You have chosen to pass.\n"); } /*run Computer exchanges and whether they decide to raise, pass or fold*/ count = 1; while (count <= 3){ if(newPlayers[count].inGame == 1){ sleep(1); /*result value is more for testing purposes, but still needs to run to fill in the correct*/ /*int array mcAdivce for Monte carlo advice for each computer*/ result = MC_rate(newPlayers, count); /*This can be found in exchange.c, just exchange based on MC advice*/ computerExchange(newPlayers, &newDeck, count); /*This can be found in display.c, determines for the computer what to do (raise, pass, fold)*/ comp_decision(newPlayers, count, &bet, &pot); /*keep track of which computer raises for later*/ if (newPlayers[count].checkBet > 0){ betMarker = count; } } count++; } /*if any computer raises, then go back to user one time to either match or fold, then each computer*/ if (betMarker > 0){ if (newPlayers[0].galleons < newPlayers[betMarker].checkBet){ printf("\nOH NOOOO, the bet is more than you can afford, and by wizarding rules, you lose the game!!!\n\n"); return 0; } if (newPlayers[0].inGame != 0){ printf("%s raised by %.2lf. Would you like to either:\n1) Match\n2) Fold \nPlease type 1 or 2: ", newPlayers[betMarker].name, newPlayers[betMarker].checkBet); scanf("%d", &choice); if (choice == 1){ newPlayers[0].galleons = newPlayers[0].galleons - newPlayers[betMarker].checkBet; pot = pot + newPlayers[betMarker].checkBet; printf("You have matched the raise\n"); } else { newPlayers[0].inGame = 0; printf("You Folded\n"); } } /*Determine whether each computer should match or fold*/ for (i = 1; i<betMarker; i++){ if (newPlayers[i].inGame == 1){ if (newPlayers[i].galleons > newPlayers[betMarker].checkBet){ result = analyze_hand(newPlayers[i]); if (result < 23){ newPlayers[i].inGame = 0; printf("%s has folded\n", newPlayers[i].name); } else{ newPlayers[i].galleons = newPlayers[i].galleons - newPlayers[betMarker].checkBet; pot = pot + newPlayers[betMarker].checkBet; printf("%s has matched the raise\n",newPlayers[i].name); } } } } } sleep(2); /*find winner of the game, give winning's to rightful winner, display winner's hand*/ findWinner(newPlayers, &pot); /*reset betMarker for next game*/ betMarker = 0; sleep(2); } /*After game loop, you have lost all your money or you have less than the 5 Galleon entrance amount*/ printf("\n\nOH NO, you lost at Wizard's poker!!!!\n"); printf("Final Galleon Count for each player:\n"); for (i = 0; i < PLAYERS; i++){ if (newPlayers[i].galleons < 0){ newPlayers[i].galleons = 0; } printf("\t%s has %.2f Galleons\n", newPlayers[i].name, newPlayers[i].galleons); } return 0; }
bool TicTacToe::isDone() const { return findWinner() != game_board_.getDefaultSymbol() || game_board_.isBoardFull(); }
uint32_t KohonenNN::getCluster(const wv::Point* p) { findWinner(p); return m_NumNeuronWinner; }