You the man Neo!
Happy New Year
Another Tick Tack Toe Question!?
Re: Another Tick Tack Toe Question!?
Wish you the same and thanks for the complements
Re: Another Tick Tack Toe Question!?
Hi Neo,
Sorry to be a pain, but I need some more help with the TickTackToe game... I know you love it really!
The problem I am having is calculating the winners on a diagonal, as it only recognises a diagonal win when on the center diagonals i.e. anywhere on the corner to corner(s)... nowhere else!
I have been looking through the code this morning but am going round in circles!
Ive just pasted the diagonal check code here, think ive already pasted the the rest previously. lol
Sorry to be a pain, but I need some more help with the TickTackToe game... I know you love it really!
The problem I am having is calculating the winners on a diagonal, as it only recognises a diagonal win when on the center diagonals i.e. anywhere on the corner to corner(s)... nowhere else!
I have been looking through the code this morning but am going round in circles!
Ive just pasted the diagonal check code here, think ive already pasted the the rest previously. lol
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);
}
}
Re: Another Tick Tack Toe Question!?
Had a quick look at that. I don't have much time today so you need to check this code.
- Define these new variables.
Code: Select all
int len_comb, N1; string str3, str4;
- Fine following code.
Add following code after that.
Code: Select all
comb_O = arr_comb_O[gridSizeComboBox.SelectedIndex];
Code: Select all
len_comb = comb_X.Length;
- This code needs to come after the diagonal check code.
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; } } } }
Re: Another Tick Tack Toe Question!?
Works sweat as a nut...!
I have been looking at Connect 4 source code trying to tackle it myself, but its very hard to try to unpick someone elses code, especially at my level!
When im working i'll have to put you on my pay roll..
Thanks "again" Neo.
I have been looking at Connect 4 source code trying to tackle it myself, but its very hard to try to unpick someone elses code, especially at my level!
When im working i'll have to put you on my pay roll..
Thanks "again" Neo.
Re: Another Tick Tack Toe Question!?
You are welcome....
Always try to group things and find a combination. This is the way to simply coding...
Always try to group things and find a combination. This is the way to simply coding...