void Multi_DM::update(unsigned int ticks) { if (delay1) { if (ticks>delay1) delay1=0; else delay1-=ticks; } if (delay2) { if (ticks>delay2) delay2=0; else delay2-=ticks; } if (end_game()) { if (!ended) { ended=true; if (get_winner().friendly(player->team())) { sf::Text new_text; new_text.setString(fdx::menu::Language::getText(fdx::menu::Language::WON)); new_text.setColor(teams.get_friendly()); texts.push_back(new_text); sf::Text new_text2; new_text2.setString(fdx::menu::Language::getText(fdx::menu::Language::LOSE)); new_text2.setColor(teams.get_enemy()); texts2.push_back(new_text2); } else { sf::Text new_text; new_text.setString(fdx::menu::Language::getText(fdx::menu::Language::LOSE)); new_text.setColor(teams.get_enemy()); texts.push_back(new_text); sf::Text new_text2; new_text2.setString(fdx::menu::Language::getText(fdx::menu::Language::WON)); new_text2.setColor(teams.get_friendly()); texts2.push_back(new_text2); } } } al.mov(ticks); rev_ships(); }
void do_gameover() { int winner, i, cities = 0, pop = 0; /* return to terminal */ current_turn = 0; queued_screen = GAME_SCREEN_TERMINAL; ai_clear_messages(); init_telegraph(); /* message */ winner = get_winner(); if (winner < 0) telegram("\nNo one wins!\n"); else { /* count cities and population */ for (i = 0; i < NUM_CITIES; i++) { if (GET_WORLD(winner, i)) { cities++; pop += GET_WORLD(winner, i); } } telegram("\n%s wins with\n%d cities and %d million\ncitizens!\n", GET_NAME(winner), cities, pop); } }
void schedule(void) { pid_t pid = current->p_pid; int lowest_priority = 0x7fffffff; //INT_MAX if (scheduling_algorithm == 0){ while(1){ pid = (pid + 1) % NPROCS; // Run the selected process, but skip // non-runnable processes. // Note that the 'run' function does not return. if (proc_array[pid].p_state == P_RUNNABLE) run(&proc_array[pid]); } } else if (scheduling_algorithm == 1){ while(1){ if (proc_array[pid].p_state != P_RUNNABLE) pid++; run(&proc_array[pid]); } } else if (scheduling_algorithm == 2){ while(1){ int i; for (i = 0; i < NPROCS; i++) { if(proc_array[i].p_priority < lowest_priority && proc_array[i].p_state == P_RUNNABLE) lowest_priority = proc_array[i].p_priority; } pid = (pid+1)%NPROCS; if(proc_array[pid].p_priority == lowest_priority && proc_array[pid].p_state == P_RUNNABLE) run(&proc_array[pid]); } } else if (scheduling_algorithm == 3){ while(1){ if(proc_array[pid].p_state == P_RUNNABLE){ if (proc_array[pid].p_time_passed >= proc_array[pid].p_share){ proc_array[pid].p_time_passed = 0; } else{ proc_array[pid].p_time_passed++; run(&proc_array[pid]); } } pid = (pid+1)%NPROCS; } } else if (scheduling_algorithm == 4){ pid_t winner; if(num_tickets < NPROCS-1){ while (1) { pid = (pid + 1) % NPROCS; // Run the selected process, but skip // non-runnable processes. // Note that the 'run' function does not return. if (proc_array[pid].p_state == P_RUNNABLE) run(&proc_array[pid]); } } else{ winner = get_winner(); while(proc_array[winner].p_state != P_RUNNABLE){ winner = get_winner(); } } run(&proc_array[winner]); } // If we get here, we are running an unknown scheduling algorithm. cursorpos = console_printf(cursorpos, 0x100, "\nUnknown scheduling algorithm %d\n", scheduling_algorithm); while (1) /* do nothing */; }
int main(int argc, char** argv){ printf("**********************************************************\n"); printf("* Runbai Ma *\n"); printf("* Final Project *\n"); printf("* Five draw Card Game *\n"); printf("* *\n"); printf("* *\n"); printf("**********************************************************\n"); printf("1.start game \n"); printf("2.quit\n"); char input = getchar(); char play_again = '1'; if(input == '1'){ while(play_again == '1'){ putchar('\n'); srand((unsigned int)time(NULL)); Deck* deck = (Deck*) malloc(sizeof(Deck)); Card* card_arr = malloc (sizeof(Card)*52); int* ret_value = malloc(sizeof(int)); card_arr = shuffle_card(); deck_init(deck,card_arr); /* initial the four player*/ char* name2 = malloc(sizeof(char)*15); name2 = "Computer 1"; Player* p2 = malloc(sizeof(Player)); player_init(p2,name2); deal_card(p2->hand,deck,5); printf("computer 1 hand: "); hand_print(p2->hand); char* name3 = malloc(sizeof(char)*15); name3 = "Computer 2"; Player* p3 = malloc(sizeof(Player)); player_init(p3,name3); deal_card(p3->hand,deck,5); printf("computer 2 hand: "); hand_print(p3->hand); char* name4 = malloc(sizeof(char)*15); name4 = "Computer 3"; Player* p4 = malloc(sizeof(Player)); player_init(p4,name4); deal_card(p4->hand,deck,5); printf("computer 3 hand: "); hand_print(p4->hand); char* name = malloc(sizeof(char)*15); name = "Poker King"; Player* p1 = malloc(sizeof(Player)); player_init(p1,name); deal_card(p1->hand,deck,5); printf("your hand: "); hand_print(p1->hand); printf("----------------------------------------------------------\n"); putchar('\n'); ret_value = monte_carlo_advisor(p2->hand); change_card_by_montecarlo(ret_value,p2->hand,deck); compute_hand_afterchange(p2->hand); ret_value = monte_carlo_advisor(p3->hand); change_card_by_montecarlo(ret_value,p3->hand,deck); compute_hand_afterchange(p3->hand); ret_value = monte_carlo_advisor(p4->hand); change_card_by_montecarlo(ret_value,p4->hand,deck); compute_hand_afterchange(p4->hand); printf("Monte Carlor suggestion for u: \n"); putchar('\n'); ret_value= monte_carlo_advisor(p1->hand); print_montecarlo_result(ret_value); printf("----------------------------------------------------------\n"); putchar('\n'); printf("Your hand: "); hand_print(p1->hand); putchar('\n'); char c; c = getchar(); printf("Enter the card index you want to change: \n"); while((c = getchar()) != '\n'){ //int i = atoi(&c); //printf("oh god: %d\n", i); if(c == '1') change_card(p1->hand, deck, 1); else if(c == '2') change_card(p1->hand, deck, 2); else if(c == '3') change_card(p1->hand, deck, 3); else if(c == '4') change_card(p1->hand, deck, 4); else if(c == '5') change_card(p1->hand, deck, 5); } compute_hand_afterchange(p1->hand); printf("----------------------------------------------------------\n"); putchar('\n'); printf("computer 1 after change is: "); hand_print(p2->hand); printf("computer 2 after change is: "); hand_print(p3->hand); printf("computer 3 after change is: "); hand_print(p4->hand); printf("your hand after change is : "); hand_print(p1->hand); printf("----------------------------------------------------------\n"); putchar('\n'); printf("the game result is: \n"); Player* p[4] = {p1,p2,p3,p4}; int winner = get_winner(p); if(winner == 0){ printf("You won the game!\n"); } else{ printf("%s won the game!\n", p[winner]->name); } putchar('\n'); putchar('\n'); putchar('\n'); printf("1.play again\n"); printf("2.quit\n"); play_again = getchar(); } } }
void Euler54::read_hands(std::string _file_name, int _number_of_hands){ int player_one_wins = 0; int player_two_wins = 0; int ties = 0; std::cout << "in read hands " << std::endl; std::cout << "file name is : " << _file_name << std::endl; std::cout << "number of hands is " << _number_of_hands << std::endl; //fill hands std::ifstream file(_file_name); std::string line; int line_count = 0; while(getline(file,line) && line_count < _number_of_hands){ std::istringstream ss(line); Euler54::Hand h1; for(int i = 0; i < 5; i++){ std::string c; if(!(ss >> c)){ std::cout << "invalid hand for player1" << std::endl; break; } Card card; card.value = get_value(c.substr(0,1)); card.symbol = c.substr(0,1); card.suit = c.substr(1,2); h1.cards.push_back(card); } Euler54::Hand h2; for(int i = 0; i < 5; i++){ std::string c; if(!(ss >> c)) { std::cout << "invalid hand for player2" << std::endl; break; } Card card; card.value = get_value(c.substr(0,1)); card.symbol = c.substr(0,1); card.suit = c.substr(1,2); h2.cards.push_back(card); } //test hands int winner = get_winner(h1, h2); if(winner == 1){ std::cout << "player 1 wins" << std::endl; player_one_wins++; }else if(winner == 2){ std::cout << "player 2 wins" << std::endl; player_two_wins++; }else ties++; std::cout << "done processing line " << line_count << std::endl; line_count++; } std::cout << "Player one wins : " << player_one_wins << std::endl; std::cout << "Player two wins : " << player_two_wins << std::endl; std::cout << "Ties : " << ties << std::endl; }