/* This function will search any winner move */ int is_finish(struct game *myGame, struct move *currMove){ /* this flag will holds the result of every checks */ int winner_flag; winner_flag = 0; winner_flag += check_down(myGame, currMove); winner_flag += check_same_line(myGame, currMove); winner_flag += check_diagonal(myGame, currMove); /* at this point the flag can have a value in [0...3] if it is > 0 it means that one of the check function returns 1 thus there is a winner */ if (winner_flag > 0) { /* set the winner */ myGame->winner = currMove->player; printf("The winner is: %c \n", myGame->winner); return 1; } /* check if it is tie */ else if (check_last_row(myGame)){ puts("Tie !"); return 1; }; /* no winner, the match can continue */ return 0; }
void simply_LU_fatoration(Matrix *A, Matrix *x, Matrix *b){ /*Resolvemos * Ax = B * * fazendo A = LU * Ax = LUx = b * definimos Ux = c * e portanto * basta resolver * - Lc = b * - Ux = c * * aplica-se substituição direta no primeiro * e inversa no segundo * **PARA CASO ACHE 0 NA DIAGONAL PRINCIPAL** * */ Matrix *L, *U, *c; if(A && x && b) { if(A->columns != A->rows) { printf("solve_by_LU_fatoration recebeu A não quadrado!\n"); } else { get_simply_LU_fatoration(A, &L, &U); c = new_M(x->rows, x->columns); if(check_diagonal(U)) { printf("A matriz A é:\n"); print_M(A); printf("A matriz b é:\n"); print_M(b); printf("A fatoração L é:\n"); print_M(L); printf("A fatoração U é:\n"); print_M(U); ForwardSubstitution(L, c, b); BackSubstitution(U, x, c); printf("A solução x é:\n"); print_M(x); }//end if check else { printf("Falha na fatoração LU! U apresenta 0's na diagonal!\n"); } kill_M(&L); kill_M(&U); kill_M(&c); }//end else A quadrado }//end if existe else printf("solve_by_LU_fatoration recebeu alguma matriz que n existe!\n"); }
bool BingoGame::check_carton(const char* game_mode, std::ifstream& index_file, Singing_square &square) { if (strcmp(game_mode, "four-corners") == 0) return check_four_corners(index_file, square); else if (strcmp(game_mode, "straight-line") == 0) return check_straight_line(index_file, square); else if (strcmp(game_mode, "diagonal") == 0) return check_diagonal(index_file, square); else if (strcmp(game_mode, "any-line") == 0) return check_any_line(index_file, square); else if (strcmp(game_mode, "roving-L") == 0) return check_roving_L(index_file, square); else return check_blackout(index_file, square); }
void Permuted_LU_fatoration(Matrix *A, Matrix *x, Matrix *b){ /*Resolvemos * Ax = B * * fazendo PA = LU * PAx = LUx = Pb = B * definimos Ux = c * e portanto * basta resolver * - Lc = B * - Ux = c * * aplica-se substituição direta no primeiro * e inversa no segundo * **TENTA CORRIGIR CASO ACHE 0 NA DIAGONAL PRINCIPAL** * */ Matrix *L, *U,*P, *B, *c; //L:matriz trang inferior especial //U:matriz triang superior com diagonal não nula //P:matriz das permutações //B: permutação aplicada em b //c: para o sistema auxlia Lc = B if(A && x && b) { if(A->columns != A->rows) { printf("solve_by_LU_fatoration recebeu A não quadrado!\n"); } else { get_Permuted_LU_fatoration(A, &L, &U, &P); B = M_cross_N(P, b); c = new_M(x->rows, x->columns); if(check_diagonal(U)) { printf("A matriz A é:\n"); print_M(A); printf("A matriz b é:\n"); print_M(b); printf("A matriz P é:\n"); print_M(P); printf("A matriz B é:\n"); print_M(B); printf("A fatoração L é:\n"); print_M(L); printf("A fatoração U é:\n"); print_M(U); ForwardSubstitution(L, c, B); printf(" c é:\n"); print_M(c); BackSubstitution(U, x, c); printf("A solução x é:\n"); print_M(x); }//end if check else { printf("Falha na fatoração LU! U apresenta 0's na diagonal!\n"); } kill_M(&L); kill_M(&U); kill_M(&c); kill_M(&P); kill_M(&B); }//end else A quadrado }//end if existe else printf("solve_by_LU_fatoration recebeu alguma matriz que n existe!\n"); }
/** \brief Find the maximum around the pixel. \param img The pointer to gradient image. \param yx The pixel coordinate (yx = y*w + x) \param w The image width. \param in1 The previous maximum direction. \retval The direction of of local max. */ static inline int dir(uint8 *con, int16 *grad, int *dr, int yx, int in1, int w) { uint8 max = 0, i; int in = 0, tmp[3]; /* if(yx == 812-1 + (542+1)*w) { printf("befor dir3: x = %d y = %d in1 = %d\n", yx%w, yx/w, in1); print_around(con, yx, w); print_around(grad, yx, w); print_con_grad(grad, con, yx, w); }*/ //x = 1077 y = 1174 if(in1 == 0){ if(grad[yx+dr[0]] > max) { max = grad[yx+dr[0]]; in = dr[0]; } if(grad[yx+dr[1]] > max) { max = grad[yx+dr[1]]; in = dr[1]; } if(grad[yx+dr[2]] > max) { max = grad[yx+dr[2]]; in = dr[2]; } if(grad[yx+dr[3]] > max) { max = grad[yx+dr[3]]; in = dr[3]; } if(grad[yx+dr[4]] > max) { max = grad[yx+dr[4]]; in = dr[4]; } if(grad[yx+dr[5]] > max) { max = grad[yx+dr[5]]; in = dr[5]; } if(grad[yx+dr[6]] > max) { max = grad[yx+dr[6]]; in = dr[6]; } if(grad[yx+dr[7]] > max) { max = grad[yx+dr[7]]; in = dr[7]; } return in; } if (in1 == dr[0]){ tmp[0] = dr[3]; tmp[1] = dr[4]; tmp[2] = dr[5]; } else if (in1 == dr[1]){ tmp[0] = dr[4]; tmp[1] = dr[5]; tmp[2] = dr[6]; } else if (in1 == dr[2]){ tmp[0] = dr[5]; tmp[1] = dr[6]; tmp[2] = dr[7]; } else if (in1 == dr[3]){ tmp[0] = dr[6]; tmp[1] = dr[7]; tmp[2] = dr[0]; } else if (in1 == dr[4]){ tmp[0] = dr[7]; tmp[1] = dr[0]; tmp[2] = dr[1]; } else if (in1 == dr[5]){ tmp[0] = dr[0]; tmp[1] = dr[1]; tmp[2] = dr[2]; } else if (in1 == dr[6]){ tmp[0] = dr[1]; tmp[1] = dr[2]; tmp[2] = dr[3]; } else if (in1 == dr[7]){ tmp[0] = dr[2]; tmp[1] = dr[3]; tmp[2] = dr[4]; } //printf("tmp0 = %d tmp1 = %d tmp2 = %d\n", tmp[0], tmp[1], tmp[2]); max = 0; if(grad[yx+tmp[0]] > max) { max = grad[yx+tmp[0]]; in = tmp[0]; } if(grad[yx+tmp[1]] > max) { max = grad[yx+tmp[1]]; in = tmp[1]; } if(grad[yx+tmp[2]] > max) { max = grad[yx+tmp[2]]; in = tmp[2]; } //printf("max = %d in = %d\n", max, in); if(con[yx+in]){ if(check_diagonal(con, dr, yx, find_dir(dr, in)) ){ if(in == tmp[0]) tmp[0] = tmp[2]; else if(in == tmp[1]) tmp[1] = tmp[2]; //printf("Remove diagonal 1 \n "); //print_con_grad(grad, con, yx, w); //printf("First "); } else if(check_max(grad, dr, yx+in, 255) ){ if(in == tmp[0]) tmp[0] = tmp[2]; else if(in == tmp[1]) tmp[1] = tmp[2]; } else return in; } else { return in; } if(grad[yx+tmp[0]] > grad[yx+tmp[1]]) in = tmp[0]; else in = tmp[1]; if(!check_diagonal(con, dr, yx, find_dir(dr, in))) { if(con[yx+in]){ //if(max == 255) return in; if(check_max(grad, dr, yx+in, 255)){ if(in == tmp[0]) in = tmp[1]; else in = tmp[0]; //printf("Second "); } else return in; } else { return in; } } else { if(in == tmp[0]) in = tmp[1]; else in = tmp[0]; } if(!check_diagonal(con, dr, yx, find_dir(dr, in))) { if(con[yx+in]){ //if(max == 255) return in; if(check_max(grad, dr, yx+in, 255)){ return 0; //printf("Second "); } else return in; } else { return in; } } else return 0; }