Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* ************************************************************************** */
- /* */
- /* ::: :::::::: */
- /* comp.c :+: :+: :+: */
- /* +:+ +:+ +:+ */
- /* By: gmuoz-ji <gmuoz-ji@student.42.fr> +#+ +:+ +#+ */
- /* +#+#+#+#+#+ +#+ */
- /* Created: 2020/02/16 17:33:41 by gmuoz-ji #+# #+# */
- /* Updated: 2020/02/16 23:33:55 by gmuoz-ji ### ########.fr */
- /* */
- /* ************************************************************************** */
- #include <unistd.h>
- #include <stdio.h>
- int check_all(void);
- int comprobar_filas(int x, int y);
- int comprobar_columnas(int x, int y);
- int comprobar_rowleft(void);
- int comprobar_rowright(void);
- int comprobar_colup(void);
- int comprobar_coldown(void);
- int g_grid[6][6]= {0, 4, 3, 2, 1, 0,
- 4, 0, 0, 0, 0, 1,
- 3, 0 ,0 ,0, 0, 2,
- 2, 0, 0, 0, 0, 2,
- 1, 0, 0, 0, 0, 2,
- 0, 1, 2, 2, 2, 0};
- int check_all(void)
- {
- int ok1;
- int ok2;
- int ok3;
- int ok4;
- int ok5;
- int ok6;
- int ok7;
- ok1 = comprobar_filas(0,0));
- ok2 = comprobar_columnas(0,0));
- ok3 = comprobar_columnas(0,0));
- ok4 = comprobar_rowleft());
- ok5 = comprobar_rowright());
- ok6 = comprobar_colup());
- ok7 = comprobar_coldown());
- if (ok1 != 0 || ok2 != 0 || ok3 !=0 || ok4 != 0 || ok5 != 0 || ok6 != 0 || ok7 != 0)
- return (1)
- else
- return (0);
- }
- int comprobar_rowleft()
- {
- int s1 =0;
- int s2 =0;
- int s3 = 0;
- int s4 = 0;
- int j;
- j = 1;
- while(j <= 4)
- {
- if (g_grid[j][0]== 1)
- s1 = s1 + 1;
- if (g_grid[j][0]== 2)
- s2 = s2 + 1;
- if (g_grid[j][0]== 3)
- s3 = s3 + 1;
- if (g_grid[j][0]== 4)
- s4 = s4 + 1;
- j++;
- }
- if((s1 != 1) || (s2 >3) || (s3 >2) || (s4 > 1))
- return (5);
- return (0);
- }
- int comprobar_rowright()
- {
- int s1 =0;
- int s2 =0;
- int s3 = 0;
- int s4 = 0;
- int j;
- j = 1;
- while(j <= 4)
- {
- if (g_grid[j][5]== 1)
- s1 = s1 + 1;
- if (g_grid[j][5]== 2)
- s2 = s2 + 1;
- if (g_grid[j][5]== 3)
- s3 = s3 + 1;
- if (g_grid[j][5]== 4)
- s4 = s4 + 1;
- j++;
- }
- if((s1 != 1) || (s2 >3) || (s3 >2) || (s4 > 1))
- return (5);
- return (0);
- }
- int comprobar_colup()
- {
- int s1 =0;
- int s2 =0;
- int s3 = 0;
- int s4 = 0;
- int i;
- i = 1;
- {
- while(i <= 4)
- {
- if (g_grid[0][i]== 1)
- s1 = s1 + 1;
- if (g_grid[0][i]== 2)
- s2 = s2 + 1;
- if (g_grid[0][i]== 3)
- s3 = s3 + 1;
- if (g_grid[0][i]== 4)
- s4 = s4 + 1;
- i++;
- }
- }
- if((s1 != 1) || (s2 >3) || (s3 >2) || (s4 > 1))
- return (5);
- return (0);
- }
- int comprobar_coldown()
- {
- int s1 =0;
- int s2 =0;
- int s3 = 0;
- int s4 = 0;
- int i;
- i = 1;
- {
- while(i <= 4)
- {
- if (g_grid[5][i]== 1)
- s1 = s1 + 1;
- if (g_grid[5][i]== 2)
- s2 = s2 + 1;
- if (g_grid[5][i]== 3)
- s3 = s3 + 1;
- if (g_grid[5][i]== 4)
- s4 = s4 + 1;
- i++;
- }
- }
- if((s1 != 1) || (s2 >3) || (s3 >2) || (s4 > 1))
- return (5);
- return (0);
- }
- int comprobar_filas(int x, int y)
- {
- int i;
- int s;
- i = 1;
- while(i <= 4)
- {
- s = g_grid[0][i]+g_grid[5][i];
- if (s == 3 || s == 4 || s == 5)
- {
- x = x + g_grid[0][i];
- y = y + g_grid[5][i];
- i++;
- }
- else
- {
- return(1);
- break;
- }
- }
- if ((x < 7 || x > 10) || (x < 7 || x > 10))
- return (2);
- else
- return (0);
- }
- int comprobar_columnas(int x, int y)
- {
- int j;
- int s;
- j = 1;
- while(j <= 4)
- {
- s = g_grid[j][0]+g_grid[j][5];
- if (s == 3 || s == 4 || s == 5)
- {
- x = x + g_grid[j][0];
- y = y + g_grid[j][5];
- j++;
- }
- else
- {
- return(1);
- break;
- }
- }
- if ((x < 7 || x > 10) || (x < 7 || x > 10))
- return (2);
- else
- return (0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement