PDA

View Full Version : Tic Tac Toe!



theplustwo
02-14-2005, 09:45 PM
The exclamation point belongs in the title. It's that exciting a game!

Anyhow, it requires the .NET Framework, available at Windows Update (http://windowsupdate.microsoft.com/).

Here is a screenshot:

http://www.theplustwo.com/stuff/tictactoe.png

Tic Tac Toe! (http://www.theplustwo.com/stuff/TicTacToe.exe)

Edit: Updated! Now there are difficulty levels!

ShadowTiger
02-14-2005, 10:04 PM
Can you provide a more solid link to the ".NET Framework?" I can't seem to find it. (Tried earlier, .. couldn't find it then either.) Thanks man. I can't wait to try your creation. :highfive: Many socks may it rock.

theplustwo
02-14-2005, 10:26 PM
Can you provide a more solid link to the ".NET Framework?" I can't seem to find it. (Tried earlier, .. couldn't find it then either.) Thanks man. I can't wait to try your creation. :highfive: Many socks may it rock.
Try this: http://download.microsoft.com/download/a/a/c/aac39226-8825-44ce-90e3-bf8203e74006/dotnetfx.exe
Also, the game is really easy to win right now, the AI is just random... but if I actually coded it to be unbeatable, what would be the point in playing?

Cloral
02-14-2005, 10:35 PM
Something I've found works well for difficulty with simplistic games: the AI can either pick the best move, or pick randomly. It decides between these 2 with some set probability. Changing this probability changes the difficulty of the game (0% best choice = very easy, 100% best choice = very hard).

This is how I implemented AI levels in Mancala for my CS10 class, and it worked very well. In that case, the 'best move' was found by looking just 2 ply ahead, which didn't guarantee the best move, but it still tended to pick very good moves on the high difficulty.

theplustwo
02-14-2005, 10:42 PM
Something I've found works well for difficulty with simplistic games: the AI can either pick the best move, or pick randomly. It decides between these 2 with some set probability. Changing this probability changes the difficulty of the game (0% best choice = very easy, 100% best choice = very hard).

This is how I implemented AI levels in Mancala for my CS10 class, and it worked very well. In that case, the 'best move' was found by looking just 2 ply ahead, which didn't guarantee the best move, but it still tended to pick very good moves on the high difficulty.
Sweet, I might implement something like that. Thanks, Cloral. :)

The other thing I want to do is make it so you can drag the window around using a MouseDown event on the label, but I can't seem to find any articles on how that would be done (I guess you're just supposed to use the default windows interface, bah).

Lutraphobiac
02-15-2005, 11:46 AM
Damn you keep on turning out neat little programs. I want to learn programming, but since I am kind of in college to do so, I don't want to learn things that I have to unlearn. Right now I am just programming little Matlab programs for class.

Cloral
02-15-2005, 02:27 PM
Well I've never done dragging like that, but it seems that what you might want to do is when you get the mouse down, record where the mouse is. Then whenever the mouse moves, figure out where it moved in relation to where it was at the last check and move the window that much. I.e. if it was at (5, 7), and now it is at (3, 10), the difference is (-2, 3), so that's how much you'd want to move.

I'm not totally sure how you handle the mouse moving outside of the window though...

theplustwo
02-15-2005, 02:36 PM
Well I've never done dragging like that, but it seems that what you might want to do is when you get the mouse down, record where the mouse is. Then whenever the mouse moves, figure out where it moved in relation to where it was at the last check and move the window that much. I.e. if it was at (5, 7), and now it is at (3, 10), the difference is (-2, 3), so that's how much you'd want to move.

I'm not totally sure how you handle the mouse moving outside of the window though...Yeah, I just thought it would be neat, but it's probably more work than I'd be willing to do on this little program. :P

But I did implement your difficulty level suggestion! There is now a difficulty selector. You can still beat it on hard though. :)

Toolie
02-15-2005, 02:52 PM
Damn you keep on turning out neat little programs. I want to learn programming, but since I am kind of in college to do so, I don't want to learn things that I have to unlearn. Right now I am just programming little Matlab programs for class.

Matlab? Thanks for reminding me. I have three assignments with that due tommorow for an engineering class here at Wilkes. If you had a copy of that by chance on your computer, you should hook me up. I hate going to the lab to use it and I'm too poor to buy it.

Lutraphobiac
02-15-2005, 03:00 PM
I just installed it so I still have the installation files. Programs have a habit of "showing up" at dorm rooms for engineering students to use at their leisure.


I'm actually coding a "craps" game for an assignment for class. I can't wait until we move to C for the next half of the semester.

AtmaWeapon
02-15-2005, 09:13 PM
I'm thinking you need to open source it and share it, bro ;)

Actually, I'm just interested in the UI, I haven't done much with borderless forms. If you give me a while, I can post the code you would need to make the window draggable by its drawn caption bar.

So far the best the hard difficulty can do is tie me, it's too wily for my traps. I thought I was undefeatable if I had the first move, but apparently there are ways around my strategy.

theplustwo
02-16-2005, 12:35 AM
I'll tell you the secret: Go in the bottom-right corner. The computer will take the center. Then go in the upper left. The computer may take one of the remaining two corners. If so, you're in luck. Take the final corner and you have two possible win moves, ensuring that the computer will only be able to block one of them. However, if the computer moves in a non-corner space after you take your 2nd corner, you're screwed.

Also, I guess I could post the source, but I didn't think anyone would care. I just made the form borderless by setting it's BorderStyle property to None, and then made labels and buttons for the title bar and control boxes, respectively.