The AI thinks quite a lot. I think you put in a sleep command? It surely doesn't need to think at all..
Have you tried to abuse the symmetry of the game in writing the rules or was it all just hard coded.

Kudo's for finishing something you started - I follow a similar pattern when I am bored, just create something simple.
arithma wroteThe AI thinks quite a lot. I think you put in a sleep command? It surely doesn't need to think at all..
Have you tried to abuse the symmetry of the game in writing the rules or was it all just hard coded.

Kudo's for finishing something you started - I follow a similar pattern when I am bored, just create something simple.
Nice Guess ;) you obviously understand its concept without looking @ its code, there is sleep time indeed, so that it would look more human like ;), you know the core never take time to think for such an algorithm.

now concerning the algorithm it self, i had one function that is hard-coded for the oblique-win check, but then i made the rest scalable to apply on a variable grid size, so it only requires one - two modifications to make it totally scalable and read to support any grid size ;).
Hey Nader.Sleiman

I downloaded your game and played it couple of times. And that was interesting. The AI is smart :P

but i found a bug in the game. It's the reset button. Once i reset the scores, the displayed score is 0 | 0. and when you play again, and lose/win, the displayed score in the previous one that i already reset.

I didn't have time to check the code, but i'll do so later on this day.

Good Job again.
Yorgi wroteHey Nader.Sleiman

I downloaded your game and played it couple of times. And that was interesting. The AI is smart :P

but i found a bug in the game. It's the reset button. Once i reset the scores, the displayed score is 0 | 0. and when you play again, and lose/win, the displayed score in the previous one that i already reset.

I didn't have time to check the code, but i'll do so later on this day.

Good Job again.
you are absolutely right, thank you for the notice =],i just set it to reset the labels but didn't actually reset the counters =]
Hi Nader,

There's a much simpler way (which reduces your code alot) to check whether someone won.

You have a 3x3 grid with 8 possible ways of winning. We mark each cell in the grid with 2^[index] and thus we will have:

1 2 4
8 16 32
64 128 256

The winning combination are:

1 + 2 + 4 = 7
8 + 16 + 32 = 56
1 + 8 + 64 = 73
4 + 16 + 64 = 84
2 + 16 + 128 = 146
1 + 16 + 256 = 273
4 + 32 + 256 = 292
64 + 128 + 256 = 448

Thus the winning array is: int win[8] = {7,56,73,84,146,273,292,448}

Everytime X makes a move, add the value in the grid to an xcounter
Everytime Y makes a move, add the value in the grid to an ocounter
Everytime a move takes place check for every entry in the win array, whether xcounter & entry == entry

If so, X won.
xterm wroteHi Nader,

There's a much simpler way (which reduces your code alot) to check whether someone won.

You have a 3x3 grid with 8 possible ways of winning. We mark each cell in the grid with 2^[index] and thus we will have:

1 2 4
8 16 32
64 128 256

The winning combination are:

1 + 2 + 4 = 7
8 + 16 + 32 = 56
1 + 8 + 64 = 73
4 + 16 + 64 = 84
2 + 16 + 128 = 146
1 + 16 + 256 = 273
4 + 32 + 256 = 292
64 + 128 + 256 = 448

Thus the winning array is: int win[8] = {7,56,73,84,146,273,292,448}

Everytime X makes a move, add the value in the grid to an xcounter
Everytime Y makes a move, add the value in the grid to an ocounter
Everytime a move takes place check for every entry in the win array, whether xcounter & entry == entry

If so, X won.
Hey Xterm

well infact that is a more complicated way with calculations( 0.001% delay =P ) , since i just used a Player Enum that is either a Human or Bot , so i just check those in a row/column of any size , and that is more creative to check the winning entity, human or bot, well but @ the end i believe that each or every bunch of coders have their own style ;)

Note: Updated score bug and a repaint bug when PC wins it paints out the cross -line for sure.
click event:
gridLoc = findGridLocationClicked(e);
xcounter += Math.pow(2,gridLoc);
checkWin(xcounter)

static boolean checkWin(int counter){
int win[8] = {7,56,73,84,146,273,292,448}
for(int entry: win)
if(counter & entry == entry)
return true;
return false;
}
That should do it, nevertheless, well done.
xterm wrote
click event:
gridLoc = findGridLocationClicked(e);
xcounter += Math.pow(2,gridLoc);
checkWin(xcounter)

static boolean checkWin(int counter){
int win[8] = {7,56,73,84,146,273,292,448}
for(int entry: win)
if(counter & entry == entry)
return true;
return false;
}
That should do it, nevertheless, well done.
well Thanks =], i'd stick to the array of Enums though =p , but i also like your suggestion ;) !
Taybe la sleiman ;)
jadberro wroteTaybe la sleiman ;)
Hehe 7obbi, you told me to post it last time, so i did now xD, im nerdy again woohoo <3 it, well but this game is ridiculous i guess =p, i should post one of ma 3d ones, but then again it will require the JME (Jmonkey Engine) and phys3d Libraries , so it'll be huge in size =/
@xterm: Your technique may be concise but as a coding style may be very non-scalable for larger problems, and is unusable for defining the AI itself. Not that nader is doing a better job though with the enum technique.
A simple solution to a simple problem. It's merely win check technique.
indeed i was looking forward for scalability , however that calculation based win - check is perfect for non scalable grids, but now who cares? its a stoopid game that works , and i enjoy coding =p.