Ok, now i have found the general area that the problem is coming from. What i think is happening is that the variables are not being defined (compc and compr) If anyone has the time to sift through the deeply nested if statements please do so Id appreciate it. You can also see the AI behind my game. Whether it will work or not well as of now its not but i feel as if it will once i find what statements still need to be fixed/ added in to make it work. So if someone could take a look at it and see if they can find the problem without reprimanding me for using too many if statements or other things like that I dont know why im so psyched about this, maybe its just cause i have spent literally all day doing this, lol. So here she is the heart of my program that must be in cardiac arrest as of now :P
Oh and alot of this isnt finished yet. There will be even more if statements (though not many) and some of the if statements are empty cause i havent gotten around to filling them yet
Code:
void evaluateboard(char testboard[3][3], int compc, int compr, char player, char computer)
{
//evaluates a board in order to find the best move
// init vars
int rowi=0;
int rowii=0;
int rowiii=0;
int coli=0;
int colii=0;
int coliii=0;
int diagi=0;
int diagii=0;
int randrow=0;
int randcol=0;
//begin evaluation
// if empty board
if(testboard[0][0] == testboard[0][1] == testboard[0][2] == testboard[1][0] == testboard[1][1]
== testboard[1][2] == testboard[2][0] == testboard[2][1] == testboard[2][2] == '\0')
{
//randomly pick
srand((unsigned)time(NULL));
randrow=(rand()%3);
randcol=(rand()%3);
compr=randrow;
compc=randcol;
}
// columns and rows
for(int i=0; i<3; i++)
{
//columns
// 2 in a row
if((testboard[i][0] || testboard[i][1] || testboard[i][2])=='\0')
{
if(((testboard[i][0]==testboard[i][1]) ||
(testboard[i][1]==testboard[i][2]) ||
(testboard[i][0]==testboard[i][2])) &&
((testboard[i][0] && testboard[i][2]) != '\0'))
{
if(testboard[i][0]==computer || testboard[i][2]==computer)
{
if(i==0)
{
coli+=50;
}
else if(i==1)
{
colii+=50;
}
else if(i==2)
{
coliii+=50;
}
}
else if(testboard[i][0]==player || testboard[i][2]==player)
{
if(i==0)
{
coli+=20;
}
else if(i==1)
{
colii+=20;
}
else if(i==2)
{
coliii+=20;
}
}
}
//rows
// 2 in a row
if(((testboard[0][i]==testboard[0][i]) ||
(testboard[1][i]==testboard[2][i]) ||
(testboard[0][i]==testboard[2][i])) &&
((testboard[0][i] && testboard[2][i]) != '\0'))
{
if(testboard[0][i]==computer || testboard[2][i]==computer)
{
if(i==0)
{
rowi+=50;
}
else if(i==1)
{
rowii+=50;
}
else if(i==2)
{
rowiii+=50;
}
}
else if(testboard[0][i]==player || testboard[2][i]==player)
{
if(i==0)
{
rowi+=20;
}
else if(i==1)
{
rowii+=20;
}
else if(i==2)
{
rowiii+=20;
}
}
}
}
}
//test for single places
// rows and columns
//diagonals LR=1 RL=2
// testing for 2 in a row
if((testboard[0][0] || testboard[1][1] || testboard[2][2])=='\0')
{
if((testboard[0][0]==testboard[1][1] ||
testboard[1][1]==testboard[2][2] ||
testboard[0][0]==testboard[2][2]) &&
(testboard[0][0] && testboard[2][2]) != '\0')
{
if(testboard[0][0]==computer || testboard[2][2]==computer)
{
diagi+=50;
}
else if(testboard[0][0]==player || testboard[2][2]==player)
{
diagi+=20;
}
}
if((testboard[2][0]==testboard[1][1] ||
testboard[1][1]==testboard[0][2] ||
testboard[2][0]==testboard[0][2]) &&
(testboard[2][0] && testboard[0][2]) != '\0')
{
if(testboard[2][0]==computer || testboard[0][2]==computer)
{
diagi+=50;
}
else if(testboard[2][0]==player || testboard[0][2]==player)
{
diagi+=20;
}
}
}
//find best location
int drow=0;
int pospositions;
int poscolone;
int poscoltwo;
int posrowone;
int posrowtwo;
int dcol=0;
if((rowi || rowii || rowiii) > ((coli && colii && coliii) && (diagi && diagii)))
{
//rows are the priority
if(rowi > (rowii && rowiii))
{
//row one is the priority
compr=0;
drow=0;
}
else if(rowii > (rowi && rowiii))
{
//row two is the priority
compr=1;
drow=1;
}
else if(rowiii > (rowi && rowii))
{
//row three is the priority
compr=2;
drow=2;
}
pospositions=0;
poscolone=0;
poscoltwo=0;
for(int c=0; c<3; c++)
{
if(testboard[c][drow]=='\0')
{
pospositions++;
if(pospositions==1)
{
poscolone=c;
}
else if(pospositions==2)
{
poscoltwo=c;
}
}
}
if(pospositions==1)
{
compc=poscolone;
}
else if(pospositions==2)
{
if(poscolone==1 && poscoltwo==2)
{
if(coli > colii)
{
compc=0;
}
else if(coli < colii)
{
compc=1;
}
}
else if(poscolone==2 && poscoltwo==3)
{
if(colii > coliii)
{
compc=1;
}
else if(colii < coliii)
{
compc=2;
}
}
else if(poscolone==1 && poscoltwo==3)
{
if(coli > coliii)
{
compc=0;
}
else if(coli < coliii)
{
compc==2;
}
}
}
}
else if((coli || colii || coliii) > ((rowi && rowii && rowiii) && (diagi && diagii)))
{
//columns are the priority
if(coli > (colii && coliii))
{
//col 1 is priority
compc=0;
dcol=0;
}
else if(colii > (coli && coliii))
{
//col 2 is priority
compc=1;
dcol=1;
}
else if(coliii > (coli && colii))
{
//col 3 is priority
compc=2;
dcol=2;
}
posrowone=0;
posrowtwo=0;
pospositions=0;
for(int r=0; r<3; r++)
{
if(testboard[dcol][r]=='\0')
{
pospositions++;
}
if(pospositions==1)
{
posrowone=r;
}
else if(pospositions==2)
{
posrowtwo=r;
}
}
if(pospositions==1)
{
compr=posrowone;
}
else if(pospositions==2)
{
if(posrowone==1 && posrowtwo==2)
{
if(rowi > rowii)
{
compr=0;
}
else if(rowi < rowii)
{
compr=1;
}
}
else if(posrowone==2 && posrowtwo==3)
{
if(rowii > rowiii)
{
compr=1;
}
else if(rowii < rowiii)
{
compr=2;
}
}
else if(posrowone=1 && posrowtwo==3)
{
if(rowi > rowiii)
{
compr=0;
}
else if(rowi < rowiii)
{
compr=2;
}
}
}
}
else if((diagi || diagii) > ((rowi && rowii && rowiii) && (coli && colii && coliii)))
{
//diagonals are the priority
if(diagi > diagii)
{
//diag one is priority
}
else if(diagii > diagi)
{
//diag two is priority
}
}
}
Thanks for anyone who has gotten this far (and read the code) or anyone else who can help me, its greatly appreciated. I started off thinking that i would be able to work my way to chess, now i dont think so lol
Thanks again everyone!