But I like to begin my log entries with a catchy title, nonetheless. So, in any case, maybe it is time to look at some code. For Lotto-type games, I created a source file called lotto.cpp, which does all of the heavy lifting, insofar as looking at a bunch of stuff that involves examining pair histories, looking for triplets containing particular pairs, and so on. So the C++ class for "draw" that is going to be rewritten for that part of the model starts out looking like this:
class draw
{
int score;
int number;
int x [6];
char str [32];
public:
draw ()
{
memset (this,0,sizeof (draw));
};
void sort ();
draw (int a, int b, int c, int d, int e, int g = 0)
{
memset (this,0,sizeof (draw));
x[0]=a; x[1]=b; x[2]=c; x[3]=d;
x[4]=e; x[5]=g; sort ();
}
draw (char*);
bool operator > (draw &d);
int &operator [] (int arg)
{
return x[arg];
}
void test (char *, size_t max);
bool increment (int limit = _G::MAX_NUMBER);
bool match_copair (int p, int q, int r, int s);
void dump (char *buff, size_t max);
void calc_pairs ();
void calc_trips ();
};class draw
{
int score;
int number;
int x [6];
char str [32];
public:
draw ()
{
memset (this,0,sizeof (draw));
};
void sort ();
draw (int a, int b, int c, int d, int e, int g = 0)
{
memset (this,0,sizeof (draw));
x[0]=a; x[1]=b; x[2]=c; x[3]=d;
x[4]=e; x[5]=g; sort ();
}
draw (char*);
bool operator > (draw &d);
int &operator [] (int arg)
{
return x[arg];
}
void test (char *, size_t max);
bool increment (int limit = _G::MAX_NUMBER);
bool match_copair (int p, int q, int r, int s);
void dump (char *buff, size_t max);
void calc_pairs ();
void calc_trips ();
};
There is, of course, a lot of room for improvement, and a lot of things that need to be changed, since clearly it is nowhere nearly as simple as using find and replace to change the word "game" to "context" and "draw" to "reading frame" as one might want it to be. One of the first things that I want to get rid of, therefore, is the reliance on the use of sscanf to parse a line from a Lottery history file into an entry into a game history database. That needs to go badly! Especially if we are going to be "tokenizing" things like the Federalist Papers, or articles from Wikipedia, or whatever else we might encounter. So, this is going to present an interesting challenge, in that respect, i.e., make improvements to the original code so that it will work with more history files for more types of games. At the same time, enabling the algorithms that we are using to try to make "predictions" about what pairs with whatever, to work with other types of tokens, that is according to a more robust probability model.
void CLottoProDoc::find_copairs (int p, int q, int SEARCH_DEPTH)
{
_int8 copairs1 [64][64];
_int8 copairs2 [64][64];
int i,j,k,l,N,p1,q1;
char str [DEFAULT_BUFFER_SIZE];
sprintf_s (str,DEFAULT_BUFFER_SIZE,"searching for copairs %02d-%02d ... \r\n\r\n",p,q);
strcat_s (outbuff,OUTPUT_BUFFER_SIZE,str);
for (i=0;i<_G::MAX_NUMBER+1;i++)
for (j=i;j<_G::MAX_NUMBER+1;j++) {
copairs1 [i][j]=0;
copairs2 [i][j]=0;
}
for (N=SEARCH_DEPTH;N>=0;N--)
for (j=0;j<DRAW_SIZE;j++)
if (history[N][j]==p) // found first number
{
for (k=0;k<DRAW_SIZE-1;k++)
for (l=k+1;l<DRAW_SIZE;l++)
{
p1 = history[N][k];
q1 = history[N][l];
copairs1 [p1][q1]++;
if (p1!=q1)
copairs1 [q1][p1]++;
}
}
// OK BUIlT A LIST OF PAIRS THAT HAVE OCCURED WITH THIS NUMBER
for (N=SEARCH_DEPTH;N>=0;N--)
for (j=0;j<DRAW_SIZE;j++)
if (history[N][j]==q) // found second number
{
for (k=0;k<DRAW_SIZE-1;k++)
for (l=k+1;l<DRAW_SIZE;l++)
{
p1 = history[N][k];
q1 = history[N][l];
copairs2 [p1][q1]++;
if (p1!=q1)
copairs2 [q1][p1]++;
}
}
// ALRIGHT NOW HAVE A LIST OF COPAIRS FOR THE SECOND NUMBER
int found;
for (i=1;i<_G::MAX_NUMBER;i++)
if ((i!=p)&&(i!=q))
for (j=i;j<_G::MAX_NUMBER+1;j++)
{
if ((j!=p)&&(j!=q))
{
found = 0;
if ((copairs1 [i][j]>1)&&(copairs2 [i][j]>0)||
((copairs1 [i][j]>0)&&(copairs2 [i][j]>1))
)
for (k=SEARCH_DEPTH;k>=0;k--) {
if (found==0)
{
sprintf_s (str,DEFAULT_BUFFER_SIZE,"FOUND COPAIR %02d-%02d\r\n",i,j);
strcat_s (outbuff,OUTPUT_BUFFER_SIZE,str);
found = k;
}
if (history [k].match_copair (i,j,p,q))
history[k].dump (outbuff,OUTPUT_BUFFER_SIZE);
}
}
if (found!=0)
strcat_s (outbuff,OUTPUT_BUFFER_SIZE,"\r\n");
}
// now search for rings.
for (i=1;i<_G::MAX_NUMBER+1;i++)
if ((i!=p)&&(i!=q))
for (j=i+1;j<_G::MAX_NUMBER+1;j++)
if ((j!=p)&&(j!=q))
if ((copairs1 [i][j]>0)&&(copairs2 [i][j]>0))
for (k=j+1;k<_G::MAX_NUMBER+1;k++)
if ((k!=p)&&(k!=q))
if ((copairs1 [i][k]>0)&&(copairs2 [i][k]>0)&&
(copairs1 [j][k]>0)&&(copairs2 [j][k]>0))
{
sprintf_s (str,DEFAULT_BUFFER_SIZE,"Found ring %02d-%02d-%02d",i,j,k);
strcat_s (outbuff,OUTPUT_BUFFER_SIZE,str);
if (history.check(draw(p,q,i,j,k))==true) {
strcat_s (outbuff,OUTPUT_BUFFER_SIZE," ***");
}
strcat_s (outbuff,OUTPUT_BUFFER_SIZE,"\r\n");
}
}
And to be quite honest, I have no idea what will happen if I rewrite this so as to be able to chow down on "Alice In Wonderland" or "The Adventures of Tom Sawyer." Lots of things will need to be parallelized. Lots of things need to have neuronal weights calculated based on relative probabilities, and of course, a lot of loops need to be replaced with some other kind of iterator that works with ordered or unordered sets, and so on. Yet this is at the heart of at least one type of method for trying to find the best "co-pair" to match with a given pair of tokens, so as to then try to make a "forward prediction" within a reading frame, as if to also enable "predicting the next word in a sentence."
Maybe. Right now this is VERY messy.
glgorman
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.