I'm doing homework for UNI and I got to do a Tic-Tac-Toe without any decision taken by player, the moves are all chosen randomly. So if the character on matrix is ' ' it means it's free, while if it's 'X' or 'O' it should generate another move. This is the code (language C):
if (playerTurn == 1){
playerSymb = 'X';
}
else if (playerTurn == 2){
playerSymb = 'O';
}
if (matrix[rand1][rand2] == ' '){
matrix[rand1][rand2] = playerSymb;
} else if(matrix[rand1][rand2] == 'X' || matrix[rand1][rand2] == 'O'){
do{
randAlt1 = MINRND + rand()%(MAXRND - MINRND +1);
randAlt2 = MINRND + rand()%(MAXRND - MINRND +1);
}while (matrix[randAlt1][randAlt2] != 'X' && matrix[randAlt1][randAlt2] != 'O');
matrix[randAlt1][randAlt2] = playerSymb;
}
I did not copied the whole code because it's not finished at all, i just need help solving this. But if I try to run this, the Symbols can be overwritten, like if I have a 'X' at matrix[1][2], it's possible that it will be a 'O' after some turns. So how can I make moves do not overwrite? (sorry for bad english).
Just put correct condition:
while (matrix[randAlt1][randAlt2] == 'X' || matrix[randAlt1][randAlt2] == 'O')
(i.e. try again if this cell is not empty)
Also it is easy to simplify your code without loosing of anything:
randAlt1 = rand1;
randAlt2 = rand2;
while (matrix[randAlt1][randAlt2] != ' ') {
randAlt1 = MINRND + rand()%(MAXRND - MINRND +1);
randAlt2 = MINRND + rand()%(MAXRND - MINRND +1);
}
matrix[randAlt1][randAlt2] = (playerTurn == 1) ? 'X' : 'O';
And it is better to add loop guard to prevent infinite loop (or to add special checks for this case):
randAlt1 = rand1;
randAlt2 = rand2;
int nbAttempts = 0;
while (matrix[randAlt1][randAlt2] != ' ' && nbAttempts < 100) {
randAlt1 = MINRND + rand()%(MAXRND - MINRND +1);
randAlt2 = MINRND + rand()%(MAXRND - MINRND +1);
nbAttempts++;
}
if (matrix[randAlt1][randAlt2] != ' ') {
// show error message and stop the game
}
matrix[randAlt1][randAlt2] = (playerTurn == 1) ? 'X' : 'O';
You choose an arbitrary position and then test if it is free – possibly multiple times. But you can also choose a number of a free position and then find it.
First set up a turn counter
int turnNo = 0;
then make a loop for alternate moves, which chooses one of 9-turnNo unused positions, finds it, marks is with a player mark and tests if the move made a line of three:
while(turnNo < 9)
{
char currPlayerMark = ...choose 'X' or 'O';
int freePos = 9 - turnNo;
int currPos = rand() % freePos; // 0 .. freePos-1
for(x=0; x<3; x++)
{
for(y=0; y<3; y++)
{
if(matrix[x][y] == ' ') // a free position
if(--currPos < 0) // the sought one
break; // break the inner loop
}
if(currPos < 0)
break; // break the outer loop
}
matrix[x][y] = currPlayerMark;
if(test_for_win_position(x,y))
{
message_a_win_of_player(currPlayerMark);
break; // turnNo < 9 here
}
turnNo ++;
}
Finally test if the loop terminated with no 'win':
if(turnNo == 9)
message_its_a_draw(); // no-one wins
A function to test the win position might look like this:
int test_for_win_position(int x, int y)
{
char mark = matrix[x][y];
// check a column
if(matrix[x][0] == mark && matrix[x][1] == mark && matrix[x][2] == mark)
return 1;
// check a row
if(matrix[0][y] == mark && matrix[1][y] == mark && matrix[2][y] == mark)
return 1;
// check one diagonal
if(x==y)
if(matrix[0][0] == mark && matrix[1][1] == mark && matrix[2][2] == mark)
return 1;
// check another diagonal
if(x+y==2)
if(matrix[0][2] == mark && matrix[1][1] == mark && matrix[2][0] == mark)
return 1;
// current player has not won (yet)
return 0;
}
Related
I'm trying to create a 3D Game Using C.
but I have a problem in The following Code
explain The Code
I have a file named 1.cub (lock down the code), this file has The map.
using The function read_cf_color I read The color of The floor and The sky from The 1.cub file and store The floor color in var named mlx->floor_color, and The ceiling in var named mlx->sky_color.
P.S: using some other functions I read all The data from 1.cub and store it in var named mlx->lines.
parse_parameters : scan all The data in mlx->lines (1.cub file) and send every line to choose_param.
choose_param: get The line from parse_parameters and tey to match every c with the right function.
read_cf_color: This function gets the color of the floor/ceiling. and cast it from char * to long int.
ft_isfloor: get the color from the previous function and give it to the right var (mlx->floor_color/mlx->sky->color).
for example:
parse_parameters pass this line F 100 , 100 , 214 to choose_param.
Then choose_param pass The F To char c in read_cf_color and the rest 100 , 100 , 214 to char *s.
the function try to make this 100 , 100 , 214 look like this 100100214 and store it in long int color
int choose_param(char c, char *str, t_mlx *mlx)
{
while (*str == ' ')
str++;
if (c == 'R' && *(str + 1) == ' ')
read_resolution(str + 1, mlx);
else if (c == 'N' && *(str + 1) == 'O' && *(str + 2) == ' ')
read_txt(1, str + 2, mlx);
else if (c == 'S' && *(str + 1) == 'O' && *(str + 2) == ' ')
read_txt(2, str + 2, mlx);
else if (c == 'W' && *(str + 1) == 'E' && *(str + 2) == ' ')
read_txt(4, str + 2, mlx);
else if (c == 'E' && *(str + 1) == 'A' && *(str + 2) == ' ')
read_txt(3, str + 2, mlx);
else if (c == 'F' && *(str + 1) == ' ')
read_cf_color(str + 1, mlx, 'f');
else if (c == 'C' && *(str + 1) == ' ')
read_cf_color(str + 1, mlx, 'c');
else if (c == 'S' && *(str + 1) == ' ')
read_txt(5, str + 1, mlx);
else if (c == '1' || c == '0' || c == '2')
return (0);
else if (c)
ft_put_error("NON-EMPTY LINE WITH WRONG IDENTIFIER\n", mlx);
return (1);
}
char **parse_parameters(t_mlx *mlx, char **lines)
{
int i;
int j;
int map;
i = 0;
map = 0;
while (lines[i])
{
j = 0;
while (lines[i][j] == ' ')
j++;
if (!choose_param(lines[i][j], lines[i], mlx))
{
return (&lines[i]);
}
i++;
}
ft_put_error("NO MAP FOUND\n", mlx);
return (lines);
}
void ft_isfloor(char *s, t_mlx *mlx, char type, char *stor)
{
if (type == 'f')
{
ft_printf("The rest of The floor:\t|%s|\n",s);
extra_param(s, mlx, "Too many Floor rgb inputs");
mlx->floor_color = ft_atoi(stor);
ft_printf("The floor Value: |%d|\n",mlx->floor_color);
if (mlx->floor_color < 0)
ft_put_error("Wrong values for floor color\n", mlx);
mlx->floor_done = 1;
}
else if (type == 'c')
{
ft_printf("The rest of The ceiling\t\n|%s|\n",s);
extra_param(s, mlx, "Too many ceiling rgb inputs");
mlx->sky_color = ft_atoi(stor);
ft_printf("The ceiling Value: |%d|\n",mlx->sky_color);
if (mlx->floor_color < 0)
ft_put_error("Wrong values for ceiling color\n", mlx);
mlx->sky_done = 1;
}
}
void read_cf_color(char *s, t_mlx *mlx, char type)
{
long int color;
char *stor;
int i;
i = 3;
color = 0;
if (mlx->floor_done && type == 'f')
ft_put_error("Multiple floor color inputs\n", mlx);
if (mlx->sky_done && type == 'c')
ft_put_error("Multiple ceiling color inputs\n", mlx);
stor = (char *)malloc(sizeof(char) * 10);
while (i > 0)
{
ft_printf("s = |%s|\n",s);
while (*s == ' ')
s++;
ft_printf("s = |%s|\n",s);
color = ft_atoi(s);
s += ft_intsize(color);
stor = ft_strjoin(stor, ft_itoa(color));
ft_printf("color = |%d|\nstor = |%s|\n---------\n",color, stor);
while (*s == ' ')
s++;
ft_printf("s = |%s|\n",s);
if (*(s++) != ',' && i > 1)
ft_put_error("Wrong floor color input\n", mlx);
i--;
}
ft_printf("\tThe final color |%s|\n",stor);
ft_isfloor(s, mlx, type, stor);
free(stor);
}
file 1.cub:
R 1000 750
F 100 , 100 , 214
C 135, 197 ,214
EA ./textures/cat4.xpm
NO ./textures/cat1.xpm
SO ./textures/cat2.xpm
WE ./textures/cat3.xpm
S ./textures/barrel.xpm
1000000001
11111111111 100000000100000010111
10000000010000
1111101111
1111101111111111111111111111111111111111111
010000000100000110000000000000000000000001
01000000010000011000000000000000001001000111111111111111111111111111111
1111110100000001100000000000000000110000000000000000000000010000001
1000000000000001100000000001111110101111111111111111111110000111101
1111110000000001100000010000000000100001100000100000000000000000001
10000010000000011000000000000100001011000000001111111111111111111111
10000000000 0000000000010000000000010110000000001
100000100000000110000000000000000010110000000111
111111000000000110000000000000010010000000001
100011100000W00000000001111110000010000000001
1000000000000001100000000 000000000100000000001
1000000000000001100000000000000000100000000001
100000000000000110000000002000000010010000001
10000000000000011000000000000000001000000001
10000000000000011000000000000000001000000001
1111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111
when I compile all this I get this:
In The image :
--> after the floor color is stored and free(stor) when starting store the ceiling color the old value in var stor stays and add the new data :
--> after store all the data in s and s = || it's get a new data like in the image:
I hope you understand what I'm trying to say
The problem was in the Last if statement:
if (*(s++) != ',' && i > 1)
ft_put_error("Wrong floor color input\n", mlx);
I was reading beyond \0, so That way all This happened.
for stor I was allocated it 2 time:
The first time in stor = (char *)malloc(sizeof(char) * 10);
The second time when I call ft_strjoin.
I have created an array full of letters and I'm stuck on implementing the function for the cell to randomly move in one of 8 directions (N, NE, E, SE, S, SW, W, NW). I've used a switch statement for the basic 4 direction but couldn't figure out the other 4 directions.
void randomStep()
{
if ((island[ro][co + 1] != ('B'||'L') || co == NUMROWS - 1 )&& (island[ro + 1][co] != ('B'||'L') || ro == NUMCOLS -1) && (island[ro - 1][co] != ('B'||'L') || ro == 0)
&& (island[ro][co - 1] != ('B'||'L') || co == 0))
break;
int direction = rand() % 8;
switch (direction) {
case 0: if (co < NUMROWS - 1 && island[ro][co + 1] == 'B'||'L'){ //move right
co++;
break;
}
case 1: if (ro < NUMCOLS -1 && island[co + 1][ro] == 'B'||'L') { //move down
ro++;
break;
}
case 2: if (ro > 0 && island[ro - 1][co] == 'B'||'L'){ //move up
ro--;
break;
}
case 3: if (co > 0 && island[ro][co - 1] == 'B'||'L') { //move left
co--;
break;
}
You can simply combine the conditions and results of two other cases. Here is an example for NW (left and up)
case 4: if (ro > 0 && co > 0 && island[ro - 1][co - 1] == 'B'||'L') { //move up & left
ro--;
co--;
}
break;
Note that I have moved the position of the break; to be outside the if code block.
I think you may also have an error with
... island[ro - 1][co - 1] == 'B'||'L' ...
which I guess should be
... island[ro - 1][co - 1] == 'B' || island[ro - 1][co - 1] == 'L' ...
and similarly in the other cases.
You can move parts of your code into functions:
bool mayGoUp(int ro, int co)
{
return ro > 0;
}
bool mayGoDown(int ro, int co)
{
return ro < NUMROWS - 1;
}
bool mayGoLeft(int ro, int co)
{
return co > 0;
}
bool mayGoRight(int ro, int co)
{
return co < NUMCOLS - 1;
}
Note: I changed the logic a bit: from co < NUMROWS - 1 to co < NUMCOLS - 1; not sure which one is the correct one.
Then you can combine them in a straightforward way:
bool mayGoUpLeft(int ro, int co)
{
return mayGoUp(ro, co) && mayGoLeft(ro, co);
}
Then, using them in your code will make your code clearer:
switch (direction) {
case 0:
if (MayGoRight(ro, co) && island[ro][co + 1] == ...
{ //move right
co++;
break;
}
...
case 99:
if (MayGoUpRight(ro, co) && ...
{ // move up and right
ro--;
co++;
break;
}
This is the verification from a connect four game prototype, but it seems I've done something wrong.
I want that everytime the player is making a move, the function will verify if there he won or not, by verifying vertically, horizontally, and eventually, on the diagonal.
But it seems that it does not verify correctly, because in some cases, even though there are only 2 moves made, the functions returns 1.
int verifyGame(int gamePosition, int gameVariable, char gameArray[HEIGTH][WIDTH])
{
if(gameArray[gamePosition][gameVariable] == gameArray[gamePosition + 1][gameVariable] == gameArray[gamePosition + 2][gameVariable] == gameArray[gamePosition + 3][gameVariable]) //verify vertically
return 1;
else
if(gameArray[gamePosition][gameVariable] == gameArray[gamePosition][gameVariable - 3] == gameArray[gamePosition][gameVariable - 2] == gameArray[gamePosition][gameVariable - 1]) //verify horizontally
return 1;
else
if(gameArray[gamePosition][gameVariable] == gameArray[gamePosition][gameVariable - 2] == gameArray[gamePosition][gameVariable - 1] == gameArray[gamePosition][gameVariable + 1])
return 1;
else
if(gameArray[gamePosition][gameVariable] == gameArray[gamePosition][gameVariable - 1] == gameArray[gamePosition][gameVariable + 1] == gameArray[gamePosition][gameVariable + 2])
return 1;
else
if(gameArray[gamePosition][gameVariable] == gameArray[gamePosition][gameVariable + 1] == gameArray[gamePosition][gameVariable+ 2] == gameArray[gamePosition][gameVariable + 3])
return 1;
//verify diagonally
else return 0;
};
This is where the function is called. The switch verifies the users input, and then it places the value in the matrix, and then verifies for won
printf("playerPick is : %d\n", playerPick);
fflush(stdout);
switch(playerPick)
{
case 1:
if(gameVariables[0] >0 && gameVariables[0] < 7)
{
--gameVariables[0];
gameArray[gameVariables[0]][0] = (char) 82;
ifWon = verifyGame(gameVariables[0], 0, gameArray);
}
printArray(gameArray);
break;
case 2:
if(gameVariables[1] >0 && gameVariables[1] < 7)
{
--gameVariables[1];
gameArray[gameVariables[1]][1] = (char) 82;
ifWon = verifyGame(gameVariables[1], 1, gameArray);
}
printArray(gameArray);
break;
case 3:
if(gameVariables[2] >0 && gameVariables[2] < 7)
{
--gameVariables[2];
gameArray[gameVariables[2]][2] = (char) 82;
ifWon = verifyGame(gameVariables[2], 2, gameArray);
}
printArray(gameArray);
break;
case 4:
if(gameVariables[3] >0 && gameVariables[3] < 7)
{
--gameVariables[3];
gameArray[gameVariables[3]][3] = (char) 82;
ifWon = verifyGame(gameVariables[3], 3, gameArray);
}
printArray(gameArray);
break;
case 5:
if(gameVariables[4] >0 && gameVariables[4] < 7)
{
--gameVariables[4];
gameArray[gameVariables[4]][4] = (char) 82;
ifWon = verifyGame(gameVariables[4], 4, gameArray);
}
printArray(gameArray);
break;
case 6:
if(gameVariables[5] >0 && gameVariables[5] < 7)
{
--gameVariables[5];
gameArray[gameVariables[5]][5] = (char) 82;
ifWon = verifyGame(gameVariables[5], 5, gameArray);
}
printArray(gameArray);
break;
case 7:
if(gameVariables[6] >0 && gameVariables[6] < 7)
{
--gameVariables[6];
gameArray[gameVariables[6]][6] = (char) 82;
ifWon = verifyGame(gameVariables[6], 6, gameArray);
}
printArray(gameArray);
break;
}
printf("%d %d %d %d %d %d %d\n", gameVariables[0], gameVariables[1], gameVariables[2], gameVariables[3], gameVariables[4], gameVariables[5], gameVariables[6]);
printf("ifwon : %d\n", ifWon);
#Weather Vane's answer is correct. The logic used in your original post is not correct for a verification.
One reason you may not have caught it yourself may be the complicated way it was written. Try simplifying the user input verification code: (Range checking the user input values is all that is necessary.)
//User input range checking:
if((gamePosition >= x)&& //where `x` is minimum for gamePosition
(gamePosition <= y)&& //where `y` is maximum for gamePosition
(gameVariable >= z)&& //where `z` is minimum for gameVariable
(gameVariable <= w)) //where `w` is maximum for gameVariable
{//continue }
else
{
printf("Invalid value. Please re-enter");
return -1;
}
Another opportunity for simplification is to note that each of your case statements contain identical code, with the exception of the value of the case. Because of this the entire switch(...){...} can be replaced with a single if statement:
//assuming playerPick >= 1
if(gameVariables[playerPick-1] >0 && gameVariables[playerPick-1] < 7)
{
--gameVariables[playerPick-1];
gameArray[gameVariables[playerPick-1]][playerPick-1] = (char) 82;
ifWon = verifyGame(gameVariables[playerPick-1], playerPick-1, gameArray);
}
printArray(gameArray);
Also note that although the statement:
gameArray[gameVariables[0][0] = (char) 82; //what is 82?
is perfectly legal, the variable gameArray[0][0] is just a char, so casting the value 82 is not necessary. Also, C syntax provides a way to pull out the ASCII decimal value of the character by surrounding it with the graves symbol, allowing the following form, which is more readable:
gameArray[gameVariables[0]][0] = `R`; //intuitive
You cannot chain equality testing as you are attempting. The code will execute, but not as you suppose. Your code
if(gameArray[gamePosition][gameVariable] ==
gameArray[gamePosition + 1][gameVariable] ==
gameArray[gamePosition + 2][gameVariable] ==
gameArray[gamePosition + 3][gameVariable])
must be split up into individual tests, such as:
if(gameArray[gamePosition][gameVariable] == gameArray[gamePosition + 1][gameVariable] &&
gameArray[gamePosition][gameVariable] == gameArray[gamePosition + 2][gameVariable] &&
gameArray[gamePosition][gameVariable] == gameArray[gamePosition + 3][gameVariable])
and on the other lines too.
I've a matrix with size 7x7 that represents a game board. When a player makes a move, the program has to check the positions around the coordinates where the piece is, in order to detect another piece aside.
I use this function:
int check_position(COORDINATES coordinates, char board[7][7]) {
int result = -1;
if (board[coordinates.x][coordinates.y] != 'O' && board[coordinates.x-1][coordinates.y] != 'O' && board[coordinates.x][coordinates.y-1] != 'O' && board[coordinates.x+1][coordinates.y] != 'O' && board[coordinates.x][coordinates.y+1] != 'O' && board[coordinates.x-1][coordinates.y-1] != 'O' && board[coordinates.x+1][coordinates.y+1] != 'O' && board[coordinates.x-1][coordinates.y+1] != 'O' && board[coordinates.x+1][coordinates.y-1] != 'O') {
result = 1;
}
return result;
}
The first parameter are the coordinates of the player's piece as a struct, with members x and y. The second parameter is the board array.
The if statement doesn't work to well, and I don't know which alternative can I take.
Can you help me? Thanks!
You forgot about your coordinates overflowing at the borders. You can either test for this, or:
Hint: Make the array two rows and columns larger than the board and fill the border with "empty" marker. The active board will the have coordinates 1...7 This way your coordinates cannot wrap (1 - 1 and 7 + 1 are still within the array) and you do not have to care about the borders.
Note: If you just want to return a boolean value, it would be better to use stdbool.h and return a bool result. That way, the caller can directly use that function as a condition:
#include <stdbool.h>
...
bool check_position(COORDINATES coordinates, const char board[9][9]) {
int x = coordinates.x - 1
for ( int xc = 0 ; xc < 3 ; xc++ ) {
int y = coodinates.y - 1;
for ( int yc = 0 ; yc < 3 ; yc++ ) {
if ( board[x][y] != '0' )
return true;
y++;
}
x++;
}
return false;
}
Note: as you only need one one non-empty field, you can terminate instantly if you found one. That is identical to the multiple conditions. Of course, that also works for your original int result.
Note2: I modified the type of board to being const, as it is not changed inside the function.
You could also solve the edge overflow like this. Edit improved after discussion with #Olaf
#define BOARD 7
int check_position(COORDINATES coordinates, char board[BOARD][BOARD]) {
int result = -1;
int left = coordinates.x == 0 ? 0 : coordinates.x - 1;
int top = coordinates.y == 0 ? 0 : coordinates.y - 1;
int right = coordinates.x == BOARD-1 ? coordinates.x : coordinates.x + 1;
int bottom = coordinates.y == BOARD-1 ? coordinates.y : coordinates.y + 1;
if (board[left] [top] != 'O' &&
board[coordinates.x][top] != 'O' &&
board[right] [top] != 'O' &&
board[left] [coordinates.y] != 'O' &&
board[coordinates.x][coordinates.y] != 'O' &&
board[right] [coordinates.y] != 'O' &&
board[left] [bottom] != 'O' &&
board[coordinates.x][bottom] != 'O' &&
board[right] [bottom] != 'O' && )
{
result = 1;
}
return result;
}
I have made this data.txt file and imported it into matlab using import wizard.
this is the result :
This table is my data base and I want to search into it column wise (each variable). I used strread as this lets me to search columns, for example :
var1=strread(VarName12(1,1),'%d',"delimiter','|')
I wrote several lines of code using strread in a script and then run it. when I check the workspace var1 and other variables that included strread result are missing and typing them in command window gives me this : Undefined function or variable 'End'. I typed sttread in command window and used variables in data.txt and got the result but it doesn't work when I run my script. I can't understand what's the problem? ( I'm using matlab R2013a and there is warning that says : using strread is not recommende. use TEXTSCAN instead. I can't do the same with textscan also strread works properly when written in workspace ). I don't know what is the problem. can give a clue?
EDIT :
this is the code
(Note: I'm writing a "biometric recognition system based on ear" and the database is data extracted from images1 to 5). This is the classification section of the code:
Nbcoordinates = vertcat(BEcell{:,1});
Necoordinates = vertcat(BEcell{:,2});
import DATA.txt.*; % import our data set
for i=1:5
token1 = 0; token2 = 0; token3 = 0; token4 = 0; token5 = 0; token6 = 0; token7 = 0;
if(VarName1(i, 1) == V{1,1}(1,2) && VarName3(i, 1) == V{1,2}(1,2) && VarName5(i,1) == V{1,3}(1,2) && VarName2(i,1) == V{1,1}(1,3) && VarName4(i,1) == V{1,2}(1,3) && VarName6(i,1) == V{1,3}(1,3))
% Check number of endings for each component
numberofendings = strread(VarName10{i,1}, '%d', 'delimiter', '|');
for j=1:size(Ne,1)
if(numberofendings(j,1)~=Ne(j,1))
break;
end
end
if(j >= size(Ne,1))
token1 = 1;
end
% check number of bifurcations for each components
numberofbifurcations = strread(VarName11{i,1}, '%d', 'delimiter', '|');
for j=1:size(Nb,1)
if(numberofbifurcations(j,1) ~= Nb(j,1))
break;
end
end
if(j >= Nb)
token2 = 1;
end
% Check Intersections1,2,3 Cordinates
Intercoordinate1 = strread(VarName7{i,1}, '%f', 'delimiter', '|');
m = 1;
for j=1:NI1
if((Intersection1(j, 1) ~= Intercoordinate1(m,1)) || (Intersection1(j, 2) ~= Intercoordinate1(m+1,1)))
break;
end
m = m + 2;
end
if(j >= NI1)
token3 = 1;
end
Intercoordinate2 = strread(VarName8{i,1}, '%f', 'delimiter', '|');
m = 1;
for j=1:NI2
if((Intersection2(j, 1) ~= Intercoordinate2(m,1)) || (Intersection2(j, 2) ~= Intercoordinate2(m+1,1)))
break;
end
m = m + 2;
end
if(j >= NI2)
token4 = 1;
end
Intercoordinate3 = strread(VarName9{i,1}, '%s', 'delimiter', '|');
m = 1;
for j=1:NI3
bi1 = cell2mat(Intercoordinate3(m, 1));
bi2 = cell2mat(Intercoordinate3(m + 1, 1));
if((Intersection3(j, 1) ~= str2num(bi2)) || (Intersection3(j, 2) ~= str2num(bi2)))
break;
end
m = m + 2;
end
if(j >= NI3)
token5 = 1;
end
% Check endings coordinate of each component
Endcoor = strread(VarName12{i,1}, '%d', 'delimiter', '|');
m = 1;
for j=1:sum(Ne)
en1 = Endcoor(m, 1);
en2 = Endcoor(m + 1, 1);
if((Necoordinates(j, 1) ~= en1) || (Necoordinates(j, 2) ~= en2))
break;
end
m = m + 2;
end
if(j >= sum(Ne))
token6 = 1;
end
% check bifurcation coordinates of each component
Bifcoor = strread(VarName13{i,1}, '%d', 'delimiter', '|');
m = 1;
for j=1:sum(Nb)
en1 = Bifcoor(m, 1);
en2 = Bifcoor(m + 1, 1);
if((Nbcoordinates(j, 1) ~= en1) || (Nbcoordinates(j, 2) ~= en2))
break;
end
m = m + 2;
end
if(j >= sum(Nb))
token7 = 1;
end
if(token1 ==1 && token2 == 1 && token3== 1 && token4 == 1 && token5 == 1 && token6== 1 && token7==1 )
disp(['This image is a member of Class ',num2str(i)]);
break;
end
end
end
if(token1 == 0 || token2 == 0 || token3 == 0 || token4 == 0 || token5 == 0 || token6== 0 || token7==0)
disp('Doesn;t exist in the data base ');
end
end