Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define COL 7
- #define LIN 6
- int jogada_jogador1(){
- int col;
- printf("Insira a coluna onde pretende inserir a jogada do jogador1: \n");
- scanf(" %d",&col);
- if(col<0 || col>7){
- jogada_jogador1();
- }
- return col;
- }
- int jogada_jogador2(){
- int col;
- printf("Insira a coluna onde pretende inserir a jogada do jogador2: \n");
- scanf(" %d", &col );
- if(col<0 || col>7){
- jogada_jogador2();
- }
- return col;
- }
- void print_tabuleiro(int matrix[LIN][COL]){
- for(int i = 0 ; i < LIN; i++){
- for (int j = 0; j <COL ; ++j) {
- printf(" %d", matrix[i][j]);
- }
- printf(" \n");
- }
- }
- int registar_jogada1(int col,int matrix[LIN][COL]){
- for(int i = LIN-1; i >= 0;i--){
- if(matrix[i][col] == 0 ){
- matrix[i][col] = 1;
- print_tabuleiro(matrix);
- return 1;
- }
- }
- printf("Jogada invalida , por favor jogue de novo\n");
- return 0;
- }
- int registar_jogada2(int col,int matrix[LIN][COL]){
- for(int i = LIN-1; i >= 0;i--){
- if(matrix[i][col] == 0 ){
- matrix[i][col] = 2;
- print_tabuleiro(matrix);
- return 1;
- }
- }
- printf("Jogada invalida , por favor jogue de novo\n");
- return 0;
- }
- int main() {
- int mat[LIN][COL];
- // INICIALIZAÇAO DA MATRIX A 0 EM TODAS AS POSIÇOES
- for(int i = 0 ; i < LIN; i++){
- for (int j = 0; j <COL ; ++j) {
- mat[i][j]=0;
- }
- }
- print_tabuleiro(mat);
- // 1 representa jogador 1 , 2 representa jogada jogador 2
- int contador=0;
- int jog1;
- int jog2;
- int val1,val2;
- while (contador != 42){
- jog1 = jogada_jogador1();
- val1 = registar_jogada1(jog1,mat);
- while(val1 == 0){
- jog1 = jogada_jogador1();
- val1 = registar_jogada1(jog1,mat);
- }
- jog2 = jogada_jogador2();
- val2 = registar_jogada2(jog2,mat);
- while(val2 == 0){
- jog2 = jogada_jogador2();
- val2 = registar_jogada2(jog2,mat);
- }
- contador++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement