int Game::setField(int x,int y){ int tmp = player; int err = world->set_field(x,y,player); if(err == -1){ return 0; } if(world->player_win(player)){ return -1*player; } else { player = switch_player(player); return tmp; } }
/* last player is hungry and cannot be served ? */ gboolean diedOfHunger(AWALE *aw) { gint begin = (aw->player == HUMAN) ? 6 : 0; gint k; if (isOpponentHungry(switch_player(aw->player), aw)){ for (k=0; k <6; k++){ if ( aw->board[begin+k] > 6 - k) return FALSE; } g_warning("%s is died of hunger", (aw->player == HUMAN) ? "HUMAN" : "COMPUTER"); return TRUE; } else return FALSE; }
/** * Handles selection of a tile on the board. * Performs corresponding move according to stated by * current game rules. */ int on_select_tile(Control* btn_tile) { if (game->game_over) { return 0; } Control* current; int rc = handle_move(game, btn_tile->i, btn_tile->j); if (game->won_game(game)) { return !show_game_arena(get_root(btn_tile), game, empty_select, game_menu_handles, on_select_difficulty, 4); } if ((rc == 0) && switch_player(game)) { current = get_root(btn_tile); if (show_game_arena(current, game, empty_select, game_menu_handles, on_select_difficulty, 4)) { return on_select_tile(current); } } return !show_game_arena(get_root(btn_tile), game, on_select_tile, game_menu_handles, on_select_difficulty, 4); }
/** * Fonction de test si case non vide * Test si la case choisie n'est pas vide * @param hole entier designant la case du plateau choisie * @param aw pointeur sur la structure AWALE courante. */ AWALE *moveAwale(short int hole, AWALE * aw) { AWALE *tempAw, *tempAwGs; gboolean has_capture = FALSE; if (!aw->board[hole]){ return NULL; } short int nbBeans, j, last; tempAw = g_malloc(sizeof(AWALE)); memcpy(tempAw, aw, sizeof(AWALE)); tempAw->last_play = hole; nbBeans = tempAw->board[hole]; tempAw->board[hole] = 0; // Déplacement des graines for (j = 1, last = (hole+1)%12 ; j <= nbBeans; j++) { tempAw->board[last] += 1; last = (last + 1) % 12; if (last == hole) last = (last +1)% 12; } last = (last +11) %12; /* Grand Slam (play and no capture because this let other player hungry */ tempAwGs = g_malloc(sizeof(AWALE)); memcpy(tempAwGs, tempAw, sizeof(AWALE)); // capture while ((last >= ((tempAw->player == HUMAN)? 0 : 6)) && (last < ((tempAw->player == HUMAN)? 6 : 12))){ if ((tempAw->board[last] == 2) || (tempAw->board[last] == 3)){ has_capture = TRUE; tempAw->CapturedBeans[switch_player(tempAw->player)] += tempAw->board[last]; tempAw->board[last] = 0; last = (last+11)%12; continue; } break; } if (isOpponentHungry(tempAw->player, tempAw)){ if (has_capture){ /* Grand Slam case */ //g_warning("Grand Slam: no capture"); g_free(tempAw); return tempAwGs; } else{ /* No capture and opponent hungry -> forbidden */ //g_warning("isOpponentHungry %s TRUE",(tempAw->player == HUMAN)? "HUMAN" : "COMPUTER" ); g_free(tempAw); g_free(tempAwGs); return NULL; } } else { tempAw->player = switch_player(tempAw->player); return tempAw; } }
void interrupt isr(void) { //UART receiver interrupt if (PIR1bits.RCIF) { if (RCSTAbits.FERR) { RCSTAbits.SPEN = 0; RCSTAbits.SPEN = 1; return; } /***************************** * Put action below * **************************/ uart_putc(uart_getc()); return; /***************************** * Stop of action * **************************/ } //Timer 1 interrupt if (TMR1IF) { /*char string [8]; TMR1IF = 0; set_tick_period_timer1_us(1000); timer1_tick_nbr ++; if (timer1_tick_nbr== 1000){ timer1_tick_nbr = 0; elapsed_time++; RC2 = 1- RC2; utoa (string, elapsed_time, 10); Lcd4_Set_Cursor(0,0); Lcd4_Write_String(string); }*/ return; } //Prefer to use the timer 2 for a periodic time because we don't //have to reinitialize the counter every time it is done by hardware if (TMR2IF) { char string [9]; TMR2IF = 0; timer2_tick_nbr ++; //The timer 2 ticks every 0.010 second => *100 = 1s //The time had to be adjusted. if (timer2_tick_nbr== 80){ timer2_tick_nbr = 0; elapsed_time++; RC2 = 1- RC2; game_phase(); } return; } if(RABIF != 0x00) { if (RA0 == 1) { switch_player(); __delay_ms(500); } RABIF = 0x00; return; } }