//thanks to logan miles

//why does this code not count 42 unique products?

#include <stdio.h>

#include <winbgim.h>

struct move

{

int marker; // this will always be 0 or 1, depending on which of the two markers is being moved

int digit; // this will be a number, 0-11, indicating which of the 12 binomials the marker is being move to

};

struct gamestate

{

int movenumber; //this will be 0 for the first move, 1 for the second, and so on

int board[7][6]; //each entry contains 0 for X, 1 for 0, 2 for vacant

int markers[2];//markers[0] contains the number of the binomial the first marker is on; markers[1] has the other

};

struct binomial

{

int a, b;

};

struct polynomial

{

int a, b, c;

};

void populate(struct binomial array[]);

void populatePoly(struct polynomial parray[7][6], struct binomial barray[]);

void setBoard(struct binomial barray[], struct polynomial parray[7][6]);

struct polynomial multiply(struct binomial x, struct binomial y);

int polyEquals(struct polynomial x, struct polynomial y);

int in(struct polynomial x, struct polynomial array[7][6]);

void printPoly(int x, int y, struct polynomial z);

void printBi(int x, int y, struct binomial z);

int main()

{

struct binomial bi[12];

struct polynomial poly[7][6];

populate(bi);

populatePoly(poly, bi);

setBoard(bi, poly);

//outtextxy(100,100,"does this work?");

getch();

return 0;

}

void setBoard(struct binomial barray[], struct polynomial parray[7][6])

{

initwindow(600,800);

int i, j, x=5, y=50;

setcolor(WHITE);

for (i = 1; i <= 7; i++)

line(0,100*i,600,100*i);

for (i = 1; i < 6; i++)

line(100*i,0,100*i,800);

line(0,750,600,750);

for (i = 0; i < 7; i++)

for (j = 0; j < 6; j++)

{

printPoly(x, y, parray[i][j]);

if ( x < 500 )

x = x+100;

else

{

x = 5;

y = y+100;

}

}

for (i = 0; i < 6; i++)

printBi((100*i)+30,720, barray[i]);

for (i=0; i < 6; i++)

printBi((100*i)+30,770, barray[i+6]);

}

void printPoly(int x, int y, struct polynomial z)

{

char string[10];

sprintf(string,"%dx2 + %dx + %d",z.a, z.b, z.c);

outtextxy(x,y,string);

}

void printBi(int x, int y, struct binomial z)

{

char string[10];

sprintf(string,"%dx + %d",z.a, z.b);

outtextxy(x,y,string);

}

struct polynomial multiply(struct binomial x, struct binomial y)

{

struct polynomial temp;

temp.a = x.a*y.a;

temp.b = x.a*y.b + x.b*y.a;

temp.c = x.b*y.b;

return temp;

}

int polyEquals(struct polynomial x, struct polynomial y)

{

return (x.a == y.a && x.b == y.b && x.c == y.c);

}

void populate(struct binomial array[])

{

array[0].a= -2;

array[0].b= -1;

array[1].a= -2;

array[1].b= 1;

array[2].a= -1;

array[2].b= -2;

array[3].a= -1;

array[3].b= -1;

array[4].a= -1;

array[4].b= 1;

array[5].a= -1;

array[5].b= 2;

array[6].a= 1;

array[6].b= -2;

array[7].a= 1;

array[7].b= -1;

array[8].a= 1;

array[8].b= 1;

array[9].a= 1;

array[9].b= 2;

array[10].a= 2;

array[10].b= -1;

array[11].a= 2;

array[11].b= 1;

}

void populatePoly(struct polynomial parray[7][6], struct binomial barray[])

{

int i, j,m=0,n=0;

struct polynomial k;

int count=0;

for (i = 0; i < 12; i++)

for (j = i; j < 12; j++)

{

k = multiply(barray[i],barray[j]);

if (!in(k, parray))

{

count++;

printf("count is %d\n",count);

parray[m][n] = k;

if (n < 6)

n++;

else

{

n = 0;

m++;

}

}

}

printf("count at end is %d\n",count);

parray[6][4].a = parray[6][4].b = parray[6][4].c = 0;

parray[6][5].a = parray[6][5].b = parray[6][5].c = 0;

}

int in(struct polynomial x, struct polynomial array[7][6])

{

int i, j;

printf("checking %dx2+%dx+%d\n",x.a,x.b,x.c);

for (i = 0; i < 7; i++)

for (j = 0; j < 6; j++)

if (polyEquals(x, array[i][j]))

{