My first Cocoa Game: MacTacToe 0.1!

Apprentice
Posts: 14
Joined: 2008.10
Post: #1
Hey everybody,

Here's the first version of MacTacToe. I've made small games using Coldstone, Director, Flash and TADS, but I've never made anything from scratch. It is a stupid little "game," but it is also the first game I have ever written in Cocoa, so I'm somewhat proud of it. I figured out all of the logic on my own, and learned a few things about Cocoa, Project Builder & the Debugger to boot.

Now I hope you'll download the source, check it out, and tell me what's wrong with it. I'm sure it's got memory leaks, but I don't know where. The project is located here: http://www.msu.edu/~brinkma1/MacTacToe.sitx

Here are the things I want to do to complete it:
  • Create a sheet which will drop down when the game is over and tell you the result. You can decide to play again, not play again, or quit the game.
  • Keep track of your overall record (-; ala "Free Cell ;-)
  • Create a preference panel which allows you to set the difficulty level. Right now the game A.I. is really weak. I know it could have been better, but I didn't see a point in making a game you couldn't beat.
  • Allow the game to alternate X's & O's turns every other game.

When the game is complete, I'd like to write a "Getting Started" tutorial with it. I will make sure to credit anybody who has helped contribute to it.
Quote this message in a reply
Member
Posts: 196
Joined: 2003.10
Post: #2
it's incredible how different an approach you took from mine! cool, though. problem:

it doesn't compile. there's an error somewhere in your view class. it tells me:

GameView.m:22: parse error before `int'
GameView.m:28: parse error before `*'
GameView.m:32: `i' undeclared (first use in this function)
GameView.m:32: (Each undeclared identifier is reported only once
GameView.m:32: for each function it appears in.)
GameView.m:33: `square' undeclared (first use in this function)
GameView.m:36: `x' undeclared (first use in this function)
GameView.m:44: `y' undeclared (first use in this function)

too bad, looks fun Smile

your ai does what exactly? checks for 2 of a kind in a row?

neat though. pong is coming nicely for me. the paddle moves now, and the ball bounces, now if only i could get both to go without bogging each other down. soemthing about threads or something...
Quote this message in a reply
Apprentice
Posts: 14
Joined: 2008.10
Post: #3
blobbo Wrote:it's incredible how different an approach you took from mine! cool, though. problem:

it doesn't compile. there's an error somewhere in your view class. it tells me:

GameView.m:22: parse error before `int'
GameView.m:28: parse error before `*'
GameView.m:32: `i' undeclared (first use in this function)
GameView.m:32: (Each undeclared identifier is reported only once
GameView.m:32: for each function it appears in.)
GameView.m:33: `square' undeclared (first use in this function)
GameView.m:36: `x' undeclared (first use in this function)
GameView.m:44: `y' undeclared (first use in this function)

too bad, looks fun Smile

your ai does what exactly? checks for 2 of a kind in a row?

neat though. pong is coming nicely for me. the paddle moves now, and the ball bounces, now if only i could get both to go without bogging each other down. soemthing about threads or something...

You must have accidentally deleted a semicolon, as mine just compiled fine. I'll post both the compiled app & the code seperately.

Yes, right now the A.I. just checks two in a row but only like this:

0 1 2
3 4 5
6 7 8

it checks for 0 & 1, 1 & 4, 2 & 4, 2 & 5, 3 & 4, 6 & 7. If I did all pairs, including non-sequential like 0 & 2 or 1 & 7, the game would be unbeatable. Right now it is prone to error, but I plan on adding a few more pairs for "A.I."

I've been busy today, so I didn't get it updated. I tried without success to get a sheet to drop down after the game is over.
Quote this message in a reply
Apprentice
Posts: 14
Joined: 2008.10
Post: #4
Quote this message in a reply
Apprentice
Posts: 14
Joined: 2008.10
Post: #5
blobbo Wrote:it's incredible how different an approach you took from mine! cool, though.

I'm sure that mine is not the way it should be implemented. But I did want to try to figure it out on my own before I asked anybody else for help. I'd like to see how your version was coded. You should post a link to the source so we can compare!

After I finish this, I'm going to move on to "Pong" as well. I think it is advantageous for the community to have multiple people working on the same problem separately. Yours for the right way to do things, mine for the "how not to do it" section :-)
Quote this message in a reply
Member
Posts: 196
Joined: 2003.10
Post: #6
as if! i gave up on tic tac toe after getting it to play randomly. i can post that code if you're still interested. let me know.
Quote this message in a reply
Apprentice
Posts: 14
Joined: 2008.10
Post: #7
blobbo Wrote:as if! i gave up on tic tac toe after getting it to play randomly. i can post that code if you're still interested. let me know.

Yes, please post it! I'd like to see how you implemented your solution. There may be a few concepts that I can glean from your approach. I am always eager to learn & share what I have learned!

By the way, did you get a chance to download my code/app? Did it compile this time?
Quote this message in a reply
Apprentice
Posts: 14
Joined: 2008.10
Post: #8
Yes, it is in fact 2:30 a.m. where I'm at.

Just plugging away my Tic Tac Toe game. Things are going along smoothly.

I have implemented most of the things I wanted to do in this game:
  • It has an A.I.
  • It has a preference panel for selecting the difficulty level
  • It plays sounds at the end of a match
  • It drops down a sheet telling you the result of the match
  • It has an info panel for displaying game stats
  • Game stats are updated live
  • It keeps track of the difficulty level & game stats via stored user preferences
  • It has it's own icon & about box, with props to those of you on iDevGames who have so kindly answered my questions


Last things to do:
  • Make A.I. match difficulty level (a matter of a few switch statements).
  • Fix sound delay (still working on it)
  • Alternate X & O turns (a matter of adding a global & checking it)
  • Check for memory leaks

Alas, these things will have to wait until the morning, as it is now going on 2:50!
Quote this message in a reply
menace690
Unregistered
 
Post: #9
Quote:Yes, right now the A.I. just checks two in a row but only like this:

0 1 2
3 4 5
6 7 8

it checks for 0 & 1, 1 & 4, 2 & 4, 2 & 5, 3 & 4, 6 & 7. If I did all pairs, including non-sequential like 0 & 2 or 1 & 7, the game would be unbeatable.


Not true, but their would not be many ways to win.

Example

| |
x|o|o
| | <- go here

Now the game won't have a chance to win at all. (assuming you are o's)
It can't block both places.
(Yes I know these are sequential, however it was said that the game COULD not be beaten. Thats just not true.
Quote this message in a reply
Apprentice
Posts: 14
Joined: 2008.10
Post: #10
menace690 Wrote:Not true, but their would not be many ways to win.

Example

0|1|2
x|o|o
6|7|8 <- go here

Now the game won't have a chance to win at all. (assuming you are o's)
It can't block both places.
(Yes I know these are sequential, however it was said that the game COULD not be beaten. Thats just not true.

If I am o's, x's turn is next. The game should be a draw, unless x chooses for whatever reason to select positions 1 or 7. As my game A.I. is written right now, that could happen because it will select a random square under certain circumstances.

By unbeatable though, I don't mean the computer will win, but rather the computer will never lose: There will always be a draw. This is entirely possible to do.
Quote this message in a reply
Post Reply