Update : improving code visualization

This commit is contained in:
Carlos 2021-02-18 03:00:14 -03:00
parent ef10b322a2
commit 9fd686b619

View File

@ -26,7 +26,9 @@ int validEntryLineColumn(int line, char column)
} }
else else
{
return 0; return 0;
}
} }
/** /**
* @brief Function validatePosition * @brief Function validatePosition
@ -44,23 +46,34 @@ int validatePosition(int mat[10][10], int boat, int line, int column,
int i, j; int i, j;
if (boat < 1 || boat > 3) if (boat < 1 || boat > 3)
{
return 0; return 0;
}
if (guide != 'H' && guide != 'V') if (guide != 'H' && guide != 'V')
{
return 0; return 0;
}
if ((line < 0 || line > 9) || (column < 0 || column > 9)) if ((line < 0 || line > 9) || (column < 0 || column > 9))
{
return 0; return 0;
}
if (guide == 'H') if (guide == 'H')
{ {
if ((10 - column) < boat) if ((10 - column) < boat)
{
return 0; return 0;
}
else else
{ {
for (j = column; j < (column + boat); j++) for (j = column; j < (column + boat); j++)
{ {
if (mat[line][j] == 0) if (mat[line][j] == 0)
{
cont++; cont++;
}
} }
} }
} }
@ -68,14 +81,18 @@ int validatePosition(int mat[10][10], int boat, int line, int column,
if (guide == 'V') if (guide == 'V')
{ {
if ((10 - line) < boat) if ((10 - line) < boat)
{
return 0; return 0;
}
else else
{ {
for (i = line; i < (line + boat); i++) for (i = line; i < (line + boat); i++)
{ {
if (mat[i][column] == 0) if (mat[i][column] == 0)
{
cont++; cont++;
}
} }
} }
} }
@ -201,7 +218,9 @@ void positionBoat(int mat[10][10], int boat)
if (a >= 0 && a <= 9 && b >= 0 && b <= 9) if (a >= 0 && a <= 9 && b >= 0 && b <= 9)
{ {
if (mat[a][b] != boat) if (mat[a][b] != boat)
{
mat[a][b] = -1; mat[a][b] = -1;
}
} }
} }
} }
@ -223,7 +242,9 @@ void positionBoat(int mat[10][10], int boat)
if (a >= 0 && a <= 9 && b >= 0 && b <= 9) if (a >= 0 && a <= 9 && b >= 0 && b <= 9)
{ {
if (mat[a][b] != boat) if (mat[a][b] != boat)
{
mat[a][b] = -1; mat[a][b] = -1;
}
} }
} }
} }
@ -238,7 +259,9 @@ void positionBoat(int mat[10][10], int boat)
if (a >= 0 && a <= 9 && b >= 0 && b <= 9) if (a >= 0 && a <= 9 && b >= 0 && b <= 9)
{ {
if (mat[a][b] != boat) if (mat[a][b] != boat)
{
mat[a][b] = -1; mat[a][b] = -1;
}
} }
} }
} }
@ -248,7 +271,7 @@ void positionBoat(int mat[10][10], int boat)
/** /**
* @brief Function printMessage * @brief Function printMessage
* Responsible for printing the auxiliary message * Responsible for printing the auxiliary message
* @param msg prints msg with board * @param msg msg with board
*/ */
void printMessage(char *msg) void printMessage(char *msg)
{ {
@ -285,34 +308,52 @@ char printTable(int logic, int stage)
if (stage == 0) if (stage == 0)
{ {
if (logic == 0) if (logic == 0)
{
return '.'; return '.';
}
else if (logic == -1) else if (logic == -1)
{
return '*'; return '*';
}
else if (logic == 1) else if (logic == 1)
{
return '1'; return '1';
}
else if (logic == 2) else if (logic == 2)
{
return '2'; return '2';
}
else else
{
return '3'; return '3';
}
} }
else else
{ {
if (logic == 0 || logic == -1 || logic == 1 || logic == 2 || logic == 3) if (logic == 0 || logic == -1 || logic == 1 || logic == 2 || logic == 3)
{
return '.'; return '.';
}
else if (logic == -2) else if (logic == -2)
{
return 'x'; return 'x';
}
else if (logic == 10 || logic == 20 || logic == 30) else if (logic == 10 || logic == 20 || logic == 30)
{
return 'N'; return 'N';
}
else else
{
return 'A'; return 'A';
}
} }
} }
/** /**
@ -331,16 +372,24 @@ void printsTray(int mat[10][10], int stage)
{ {
printf("%c", i); printf("%c", i);
if (i < 74) if (i < 74)
{
printf(" "); printf(" ");
}
} }
printf("\n"); printf("\n");
for (int i = 0; i < 12; i++) for (int i = 0; i < 12; i++)
{ {
if (i > 0 && i < 11) if (i > 0 && i < 11)
{
printf("%02d ", i); printf("%02d ", i);
}
else else
{
printf(" "); printf(" ");
}
for (int j = 0; j < 12; j++) for (int j = 0; j < 12; j++)
{ {
if ((i > 0 && i < 11) && (j > 0 && j < 11)) if ((i > 0 && i < 11) && (j > 0 && j < 11))
@ -350,9 +399,14 @@ void printsTray(int mat[10][10], int stage)
printf("%c", imp); printf("%c", imp);
} }
else else
{
printf("#"); printf("#");
}
if (j < 11) if (j < 11)
{
printf(" "); printf(" ");
}
} }
printf("\n"); printf("\n");
} }
@ -367,16 +421,24 @@ void printsTray(int mat[10][10], int stage)
void shoot(int mat[10][10], int line, int column) void shoot(int mat[10][10], int line, int column)
{ {
if (mat[line][column] == 0 || mat[line][column] == -1) if (mat[line][column] == 0 || mat[line][column] == -1)
{
mat[line][column] = -2; mat[line][column] = -2;
}
if (mat[line][column] == 1) else if (mat[line][column] == 1)
{
mat[line][column] = 10; mat[line][column] = 10;
}
if (mat[line][column] == 2) else if (mat[line][column] == 2)
{
mat[line][column] = 20; mat[line][column] = 20;
}
if (mat[line][column] == 3) else if (mat[line][column] == 3)
{
mat[line][column] = 30; mat[line][column] = 30;
}
} }
/** /**
* @brief Function calculateScore * @brief Function calculateScore
@ -401,13 +463,24 @@ int calculateScore(int mat[10][10], int line, int column)
else if (mat[line][column] == 20) else if (mat[line][column] == 20)
{ {
if (mat[line + 1][column] == 20) if (mat[line + 1][column] == 20)
{
b = 1; b = 1;
}
if (mat[line - 1][column] == 20) if (mat[line - 1][column] == 20)
{
c = 1; c = 1;
}
if (mat[line][column + 1] == 20) if (mat[line][column + 1] == 20)
{
d = 1; d = 1;
}
if (mat[line][column - 1] == 20) if (mat[line][column - 1] == 20)
{
e = 1; e = 1;
}
if (b == 1) if (b == 1)
{ {
@ -418,7 +491,9 @@ int calculateScore(int mat[10][10], int line, int column)
return 4; return 4;
} }
else else
{
return 0; return 0;
}
} }
if (c == 1) if (c == 1)
@ -430,7 +505,9 @@ int calculateScore(int mat[10][10], int line, int column)
return 4; return 4;
} }
else else
{
return 0; return 0;
}
} }
if (d == 1) if (d == 1)
@ -442,7 +519,9 @@ int calculateScore(int mat[10][10], int line, int column)
return 4; return 4;
} }
else else
{
return 0; return 0;
}
} }
if (e == 1) if (e == 1)
@ -454,20 +533,32 @@ int calculateScore(int mat[10][10], int line, int column)
return 4; return 4;
} }
else else
{
return 0; return 0;
}
} }
} }
else if (mat[line][column] == 30) else if (mat[line][column] == 30)
{ {
if (mat[line + 1][column] == 30) if (mat[line + 1][column] == 30)
{
b = 1; b = 1;
}
if (mat[line - 1][column] == 30) if (mat[line - 1][column] == 30)
{
c = 1; c = 1;
}
if (mat[line][column + 1] == 30) if (mat[line][column + 1] == 30)
{
d = 1; d = 1;
}
if (mat[line][column - 1] == 30) if (mat[line][column - 1] == 30)
{
e = 1; e = 1;
}
if (b == 1 && c == 1) if (b == 1 && c == 1)
{ {
@ -479,7 +570,9 @@ int calculateScore(int mat[10][10], int line, int column)
return 7; return 7;
} }
else else
{
return 0; return 0;
}
} }
else if (d == 1 && e == 1) else if (d == 1 && e == 1)
@ -492,7 +585,9 @@ int calculateScore(int mat[10][10], int line, int column)
return 7; return 7;
} }
else else
{
return 0; return 0;
}
} }
else if (d == 1) else if (d == 1)
@ -505,7 +600,9 @@ int calculateScore(int mat[10][10], int line, int column)
return 7; return 7;
} }
else else
{
return 0; return 0;
}
} }
else if (e == 1) else if (e == 1)
@ -518,7 +615,9 @@ int calculateScore(int mat[10][10], int line, int column)
return 7; return 7;
} }
else else
{
return 0; return 0;
}
} }
else if (c == 1) else if (c == 1)
@ -531,7 +630,9 @@ int calculateScore(int mat[10][10], int line, int column)
return 7; return 7;
} }
else else
{
return 0; return 0;
}
} }
else if (b == 1) else if (b == 1)
@ -544,7 +645,9 @@ int calculateScore(int mat[10][10], int line, int column)
return 7; return 7;
} }
else else
{
return 0; return 0;
}
} }
} }
return 0; return 0;
@ -580,26 +683,26 @@ void printPositioning(int Player, int boat, int nm)
{ {
if (nm == 1) if (nm == 1)
printMessage(msg1); printMessage(msg1);
if (nm == 2) else if (nm == 2)
printMessage(msg2); printMessage(msg2);
if (nm == 3) else if (nm == 3)
printMessage(msg3); printMessage(msg3);
if (nm == 4) else if (nm == 4)
printMessage(msg4); printMessage(msg4);
if (nm == 5) else if (nm == 5)
printMessage(msg5); printMessage(msg5);
if (nm == 6) else if (nm == 6)
printMessage(msg6); printMessage(msg6);
} }
else if (boat == 2) else if (boat == 2)
{ {
if (nm == 1) if (nm == 1)
printMessage(msg7); printMessage(msg7);
if (nm == 2) else if (nm == 2)
printMessage(msg8); printMessage(msg8);
if (nm == 3) else if (nm == 3)
printMessage(msg9); printMessage(msg9);
if (nm == 4) else if (nm == 4)
printMessage(msg10); printMessage(msg10);
} }
else if (boat == 3) else if (boat == 3)
@ -632,33 +735,33 @@ void printPositioning(int Player, int boat, int nm)
{ {
if (nm == 1) if (nm == 1)
printMessage(msg1); printMessage(msg1);
if (nm == 2) else if (nm == 2)
printMessage(msg2); printMessage(msg2);
if (nm == 3) else if (nm == 3)
printMessage(msg3); printMessage(msg3);
if (nm == 4) else if (nm == 4)
printMessage(msg4); printMessage(msg4);
if (nm == 5) else if (nm == 5)
printMessage(msg5); printMessage(msg5);
if (nm == 6) else if (nm == 6)
printMessage(msg6); printMessage(msg6);
} }
if (boat == 2) else if (boat == 2)
{ {
if (nm == 1) if (nm == 1)
printMessage(msg7); printMessage(msg7);
if (nm == 2) else if (nm == 2)
printMessage(msg8); printMessage(msg8);
if (nm == 3) else if (nm == 3)
printMessage(msg9); printMessage(msg9);
if (nm == 4) else if (nm == 4)
printMessage(msg10); printMessage(msg10);
} }
if (boat == 3) else if (boat == 3)
{ {
if (nm == 1) if (nm == 1)
printMessage(msg11); printMessage(msg11);
if (nm == 2) else if (nm == 2)
printMessage(msg12); printMessage(msg12);
} }
} }