Re: Another Tick Tack Toe Question!?
Posted: Fri Dec 31, 2010 8:09 pm
You the man Neo!
Happy New Year
Happy New Year
Code: Select all
// diag check
if (P == 0){
str1 = "";
str2 = "";
for (x = 0; x < N; x++){
str1 += tickTackButton[x, x].Text; // forward
str2 += tickTackButton[x, N - 1 - x].Text; // backward
}
if (str1.IndexOf(comb_X) != -1 || str2.IndexOf(comb_X) != -1)
{
P = 1;
PlayerWins(P);
}
else if (str1.IndexOf(comb_O) != -1 || str2.IndexOf(comb_O) != -1)
{
P = 2;
PlayerWins(P);
}
}
Code: Select all
int len_comb, N1;
string str3, str4;
Code: Select all
comb_O = arr_comb_O[gridSizeComboBox.SelectedIndex];
Code: Select all
len_comb = comb_X.Length;
Code: Select all
// other cross dir check
if (P == 0)
{
N1 = 1;
for (y = 1; y < N; y++)
{
for (x = N1; x < N; x++)
{
str1 += tickTackButton[x, x - N1].Text; // forward upper
str2 += tickTackButton[x - N1, x].Text; // forward lower
str3 += tickTackButton[x - N1, (N - 1) - x].Text; // backward upper
str4 += tickTackButton[x, (N - 1) - (x - N1)].Text; // backward lower
}
if (str1.IndexOf(comb_X) != -1 || str2.IndexOf(comb_X) != -1 || str3.IndexOf(comb_X) != -1 || str4.IndexOf(comb_X) != -1)
{
P = 1;
PlayerWins(P);
break;
}
else if (str1.IndexOf(comb_O) != -1 || str2.IndexOf(comb_O) != -1 || str3.IndexOf(comb_O) != -1 || str4.IndexOf(comb_O) != -1)
{
P = 2;
PlayerWins(P);
break;
}
else
{
N1++;
if ((N - N1) < len_comb)
{ // Not enough length to match
break;
}
}
}
}