-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerateset.cpp
More file actions
55 lines (55 loc) · 1.5 KB
/
generateset.cpp
File metadata and controls
55 lines (55 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*#include<stdlib.h>
#include<time.h>
using namespace std*/
void generateset(long long int trainTimes) //function to generate the set of possibilities
{
long long int x,i,j,flag=1,redcheck=0,endcheck=0,validcheck=0;
int tic[n]; //using linear array as it would be easier.array stores the moves done sequentially
for(i=0;i<trainTimes;i++)
{
reset:
for(j=0;j<n;j++) //loop to reset the values of the array to 0
{
tic[j]=0;
}
for(j=0;j<n;j++)
{
notvalid:
x=rand()%n;
if(flag==1) //flag checks whose move it is and assigns the respective value to it
{ //flag==1 means it is player 1's move
validcheck=valid(tic,x);
if(validcheck==1)
{
goto notvalid;
}
tic[j]=x;
flag=2; //setting flag to other player
}
else
{
validcheck=valid(tic,x);
if(validcheck==1)
{
goto notvalid;
}
tic[j]=x; //player 2's move
flag=1;
}
redcheck=check(tic); //check for redundancies in the current state of the game
if(redcheck==1)
{
i++;
//goto reset; //if redundancy is detected reset to start again i++ is to not let redundancies to let it go in infinite loop
}
store(tic);
endcheck=end(tic); //check if the game has ended
if(endcheck==1)
{
i++;
store(tic); //if game has ended then store it and break out of the loop
break;
}
}
}
}