General Discussion

Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

Forum Contest: Tic-Tac-Toe App for iOS

It's time for another Treehouse Forum contest! This one is for all the iOS students:

After you've watched the video, please read the details below carefully. We're looking forward to your entries!

Game Rules:
This is a simple Tic-Tac-Toe app also known as Noughts & Crosses. Imagine you are playing this on a piece of paper with a friend. Where each of you gets to add an X or a 0 on a 3x3 grid. The player who succeeds in placing three consecutive Xs or 0s in a horizontal, vertical, or diagonal row wins the game.

How to Enter:
Create your app as a native app iOS app. Then post a link as an answer to this post. It can be a link to downloadable project files, a GitHub repo. Be creative with the design and user experience! If you want to learn iOS then checkout the iOS Development Track.

Due Date:
All entries must be submitted by March 23th at 11:45pm ET. Here's a timezone chart so you can see what time that is for your locale.

Prize:
The entries will be judged by Treehouse teachers based on both design and code. One winner will receive a free month of Treehouse Pro (formerly called "Gold") on us! We'll announce the winner on March 24th and reveal the next contest.

aawwwww. I'd accept but I don't have an apple computer so I cant get xcode. but I have made a few simple games in html (A Little Bit Too Simple!)

Jo Albright
Jo Albright
5,199 Points

Hey Amit, what do you think about making a contest where multiple people come together to work on a project through GitHub. I would love to see how well group projects workout with people who have never met each other and in a short amount of time.

Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

There were so many amazing entries. You should all be proud but there can be only one winner and this week it is Jo Albright! Who went above and beyond what was required. I also want to mention that I loved Tom Bakker's design. Great job!

I would encourage everyone to upload their entry to Github if you haven't already done so. Github is like having a resume for a developer. It shows potential employers your capabilities.

Jon Kroeker
Jon Kroeker
24,649 Points

Congrats [Jo Albright](teamtreehouse.com/joalbright)! Great designs from everyone! Thanks Amit for the contest, it's great to get this practice building our own apps outside of the learning modules. I look forward to more contests!

Jo Albright
Jo Albright
5,199 Points

I am very humbled and appreciative of this experience, especially from being surrounded by everyone's amazing ideas and designs. This is how I feel.

Thank you very much Amit! This really does mean a lot to me. And I want to congratulate Jo Albright on winning, you really knocked this one out of the park! Also everyone else that contributed to this contest, it's amazing to see what people can come up with in such a short period of time.

Hope there will be another iOS contest soon!

Enara L. Otaegi
Enara L. Otaegi
13,107 Points

I should say congrats Jo Albright, even after you made me lose concentration for five minutes with those gifs :D You deserve it. Great job!

Jo Albright
Jo Albright
5,199 Points

Thank you. And yes, I wasted about that amount of time on that site as well.

Enara L. Otaegi and others on here that don't have social or web links on your profiles. I would love to see what things you all are doing now and in the future.

Enara L. Otaegi
Enara L. Otaegi
13,107 Points

You're right! Profile updated. Not a lot to show yet. But I added my Twitter username and Linkedin profile (not in English, sorry I have to update that) just in case anyone wants to make a treehouse study group or something like that.

agreatdaytocode
agreatdaytocode
Treehouse Moderator 24,242 Points

Congrats Jo! I hope you push this one into the app store! :)

Jo Albright
Jo Albright
5,199 Points

Thanks Aaron! I have it submitted... currently waiting for review :)

Thanks Enara. I put up links to force myself to do more public code and projects... it gives me the drive to finish side/personal projects to show off. Keep it up! Study group is a great idea.

Study group? I am in. Paired Programming or group projects would be an amazing experience too. Tons to learn from that. LinkedIn and Twitter (although it really gets not much use) will be added to my profile.

agreatdaytocode
agreatdaytocode
Treehouse Moderator 24,242 Points

Group + Code = Sign this guy up! I'll add you guys on twitter if thats the road we are going to take.

Naomi Freeman
Naomi Freeman
Treehouse Guest Teacher

Jo Albright Congrats :) May I please ask how you started? In terms of this app. What was the first thing that you approached? I'm still pretty new to this and am just trying to wrap my head around it. With a calculator, I understand: you need to make stuff do math. Cool.

But with a game, where did you begin?

I made an in-road, but it looks like this: https://github.com/summerspirit/Matchy-matchy Aha * this is not the animation you're looking for *

Jo Albright
Jo Albright
5,199 Points

@Naomi Freeman - Great question. You have inspired me to write a blog post about why I did what I did and how I went about it. I will add an update on here when I have finished it.

Holger Liesegang
Holger Liesegang
50,592 Points

Hi Naomi Freeman ,

I hope your MAMP is running ok now? There where some forum problems while answering your question then and I just wanted to be sure :)

Jo Albright
Jo Albright
5,199 Points

Naomi Freeman - Here is my blog post on game creation. Hopefully you will get something out of my explanation, that will help you gain a vision for your own games. Also, I hope to find time to better document my public app code.

39 Answers

Henry Moran
Henry Moran
7,520 Points

This is really cool. I hope that by next time when an iOS contest takes place I'll be ready. Good luck everyone! Please continue to do these contest for iOS – maybe once a month?

Matthew Mascioni
Matthew Mascioni
15,005 Points

Awesome! Good luck to everyone!

If you please clear me about where i should put my project zip file link . i will be very happy . good luck everyone .

Jorge Bucaran
Jorge Bucaran
8,080 Points

"...Then post a link as an answer to this post. It can be a link to downloadable project file..."

thanks jorge . it's very kind of you . :)

Jorge Bucaran
Jorge Bucaran
8,080 Points

Cheers. Let's do our best!

Can't wait to get started! :-)

Thomas Nilsen
Thomas Nilsen
14,922 Points

I got a working version. Now comes the hard part. Clean up the code and make a cool design :)

I absolutely hate the latter, but I love adding effects.

Enara L. Otaegi
Enara L. Otaegi
13,107 Points

Here is my entry. Good luck everybody!

Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

I like that you can play against the system. Great work!

Same implementation I was going to use - user vs. computer. Great stuff!

Jo Albright
Jo Albright
5,199 Points

Here is my Tic Tac Toe rendition.

Game Play Win Stats

Options

  • Game Mode : tap the top right button to change the game mode
    • Play against a person or robot (robot has semi-decent AI to give you a challenge)
    • The robot will always be green
  • View Stats : tap the top left button to view stats
  • View Past Games : swipe up and down to view all games played

Features

  • First player color switches each game allowing a fair advantage to winning.
  • A label stating which color's turn it is.
  • A label stating who won on past games.
  • Turning on a robot when it is green's turn to play, automatically starts the robot playing.
  • Built-in delay for robot to make it look like it is thinking of a move.
  • Big banner to congratulate the winner.
  • New button appears after a win (or if you swipe up and back again) to play a new game.
  • Fun animations for new game transitions (also when swiping up and down between past games).
Anthony Lockett
Anthony Lockett
24,266 Points

MOVE.h, MOVE.m files not found :( I would love to give this a try

Jo Albright
Jo Albright
5,199 Points

Hi Anthony, I apologize for not including that (it is a class I use in all of my projects and forgot to put it in the project folder).

  • Added MOVE.h and MOVE.m to project in GitHub

Thanks Matthew! I submitted it to the App Store last night because it turned out much better than I thought it would.

Anthony Lockett
Anthony Lockett
24,266 Points

I am so impressed by this. Amazing job!

Jo Albright
Jo Albright
5,199 Points

Thanks Anthony & Aaron!

Enara L. Otaegi
Enara L. Otaegi
13,107 Points

I can't wait to see this on the App Store. It's really really good Jo!

Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

You blew this out of the water! Amazing!

Jo Albright
Jo Albright
5,199 Points

Thank you very much Amit, your words are too kind!

These concepts in your game are above and beyond any online teaching courses dude. Yikes. Great stuff. How in the hell did you implement AI into your app?

Jo Albright
Jo Albright
5,199 Points

Thanks Stephen. Yea I didn't stop at learning online only, part self-taught and also have taken an iOS class as well. I don't think you are ever too advanced to participate in challenges... and I still have a lot to learn. So, I love joining competitions like this to drive me to learn non-traditional techniques and push my creativeness.

As for the AI... basically a static AI is just a bunch of conditions and randomness to make it feel intelligent. Right now the bot looks for a winning spot, then a blocking spot, then a random spot (this is key as it allows for every game to be different and keeps it interesting). I do have a plan to collect past game information and allow the bot to learn how to play better, making it harder and harder to beat... but that will probably take awhile to implement.

Thomas Nilsen
Thomas Nilsen
14,922 Points

Absolutely stunning design. Also, I really liked you're code. Lot's of stuff to learn from!

Jo Albright
Jo Albright
5,199 Points

Thank you Thomas! It is always great to hear people appreciating code. Honestly I wrote that very fast, so there is a few spots where I could have made code reusable. I will be making updates to it this week. :)

Anthony Lockett
Anthony Lockett
24,266 Points

Did you go to The Iron yard for the iOS class?

Jo Albright
Jo Albright
5,199 Points

I went to the Big Nerd Ranch back in 2012. I teach at The Iron Yard. I send all of my students to Treehouse both for pre-work and for continuing practice as well. I think to become awesome you need a certain amount of group and self-teaching.

Anthony Lockett
Anthony Lockett
24,266 Points

I agree, I want to go to the Iron Yard, but can't leave for the amount of time needed

Anthony Lockett
Anthony Lockett
24,266 Points

Do you recommend any books to read other than Big Nerd Ranch?

Brayden Kness
Brayden Kness
11,703 Points

Wow great UI and I love the robot element

Jo Albright
Jo Albright
5,199 Points

Thanks Kirk. Glad you like the robot. Was the one element that wanted to make happen in this app.

Jo Albright
Jo Albright
5,199 Points

Anthony Lockett - Books I own that I have found helpful.

Although I don't learn best from books, I have enjoyed having them as a good exercise for me to pursue parts of the language I normally would not.

Also, to anyone who really feels it is hard to pursue any language, I would encourage you to find a passion project (an itch to scratch). I have found that most people build amazing things from something they wanted or felt wasn't done right by others. I personally built an app for vector illustration which pushed me to learn Core Graphics very intensely. You also tend to remember code better when you are learning it through an app you are invested in. That is why any app I build for a contest like this has to be something I would submit to the app store... or I will forget what I learned while building it.

Jo Albright
Jo Albright
5,199 Points

Thank you Enara :)

I really I like how you built yours to play against the computer as well! And your ability to choose which type you want to play as.

agreatdaytocode
MOD
agreatdaytocode
Treehouse Moderator 24,242 Points

My "very simple" Tic Tac Toe App.

alt text

You can download it here at GitHub

Here is my entry: Viking XO

I had some great ideas for this app, which I couldn't implement for the app due to some scheduling errors. I expected to have way more free time this week then I actually had, haha.

So here is really the bare minimum version of the app. You can expect an update with a more expanded feature set in the near future. BTW, please don't judge this app on a 3.5-inch screen: it's terribly broken.

Viking XO screenshot

Download link

Hope there are going to be more of these iOS contest in the future!

Nicholas Fox
Nicholas Fox
5,520 Points

Here is what I was able to whip up this week.

FoxTicTacToe

I'd love to hear your feedback!

FoxTicTacToe

Holger Liesegang
Holger Liesegang
50,592 Points

Here's my version of the Tic-Tac-Toe App for iOS:

You can download it at GitHub

agreatdaytocode
MOD
agreatdaytocode
Treehouse Moderator 24,242 Points

I did learn how to display the launch image longer. Here is the Code: "Sleep(number of seconds)"

Appdelegate.M

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    sleep(5); 
    // Override point for customization after application launch.
    return YES;
}
agreatdaytocode
agreatdaytocode
Treehouse Moderator 24,242 Points

Thanks Jo, I actually got the idea after seeing your app. I searched stack Overflow for some example code and found that someone posted this as a comment to a thread. I was shocked that it was so easy lol.

Jose Colella
Jose Colella
3,526 Points

My version of the TicTacToe app can be found in the in Github.

Here are some images.

"Game screen" "Winner screen"

Matthew Mascioni
Matthew Mascioni
15,005 Points

Brilliant job, everyone! You're making this really hard on the team ;) So many collective great ideas going on in here. This is what it's all about!

Holger Liesegang
Holger Liesegang
50,592 Points

Yup, I like to second Aaron's opinion concerning Jo's fantastic work :)

Jo Albright
Jo Albright
5,199 Points

Thanks Aaron, but I agree with Matthew. There are multiple ideas here that I am now wanting to implement in my app, as I did not thing of them before.

Aaron :

  • I love the movement in and out of your game with a home screen
  • The exit button to leave a game is also very kind to a user
  • Plus your personal logo is awesome

Enara :

  • Great idea of allowing the user to choose a player type
  • Good implementation of playing against the computer
  • Fun play on the logo and the "T"

Tom :

  • Dude that viking design is amazing... colored shields and the banners denoting whose turn it is rocks

And everyone else who has submitted have figured out how to get this game to work in different ways. It is really cool to see how different brains come to different conclusions. The two main reasons I love Treehouse 1) their content is very creative and constantly keeps me interested 2) the community they are building is very diverse and brilliant.

Good luck to everyone!

Jose Colella
Jose Colella
3,526 Points

Me too. Jo Albright's app is amazing. Innovation,and simplicity in one app..

Jo Albright
Jo Albright
5,199 Points

Dude. Too kind. I got really excited when the iOS 7 design was released, because that style is my jam!

Thomas Nilsen
Thomas Nilsen
14,922 Points

Jo Albright I particularly liked the way you used delegates. I always use them just to pass data from viewController B to A. But you used it for a lot more as well.

Ah! I hate turning in an incomplete project, but I've run out of time. Here's an introduction to my app: Entry

Jo Albright
Jo Albright
5,199 Points

Dude... cool animations and smart way of showing whose turn it is. Very cool ideas coming out of your brain. I hope you finish this out in the future.

I agree with Jo Albright on this one, very sweet prompt for the current turn. Nice work!

Thanks, guys - I appreciate your comments! I do plan on finishing this one up; it will be my first complete app.

All of your apps are looking well too - excellent work around this forum.

agreatdaytocode
MOD
agreatdaytocode
Treehouse Moderator 24,242 Points

I've noticed that some of the seasoned developers here don't use storyboards. Can I ask why?

Jo Albright
Jo Albright
5,199 Points

I use storyboards in some projects. 2 personal projects that I am currently building rely on storyboards. But, I think they can be overkill for some projects and other projects they just feel like they are in the way.

For this project... I could have done a storyboard, but I work faster with code. I have set it up so that I can add a storyboard later when I choose to add features like color themes, p2p games, etc.

For other projects I do a lot of CoreGraphics drawing which I currently have not figured out a way to visualize in storyboards (if there even is a way).

In the end, I believe you should know how to build an app only with code (so you know what is going on behind the scenes of storyboard). Once you understand how it works, then you should choose whether an app really needs it or if you do it as a practice that makes you build apps faster.

agreatdaytocode
agreatdaytocode
Treehouse Moderator 24,242 Points

That's some good advice. I'll need to work on creating apps with the storyboards. I've never done it that way.

Matthew Mascioni
Matthew Mascioni
15,005 Points

I started learning iOS development using storyboards-- they are quite useful to get to learn visually how the view hierarchy works. It also spares you from writing a lot of redundant code during development with managing said view hierarchy with smaller apps. However, I find that I'm a lot more efficient with code and having everything in code in front of me helps me to diagnose problems faster. A lot of it is preference and use case.

Thomas Nilsen
Thomas Nilsen
14,922 Points

I truly comes down to perference. Read this :) http://codewithchris.com/xcode-using-storyboards-and-xibs-versus-creating-views-programmatically/

Also. The new IOS course that gets released tomorrow (at least in my timezone), Amit has said that everything will be done programmatically ;)

Btw - You said nice job Thomas - I think you meant Hans Yelek? ;)

https://www.dropbox.com/s/bqahgfs1rdf5w9x/Tic%20Tac%20Toe.zip

Here is my code if you want to have a look :) Really liked your design btw!

Jorge Bucaran
Jorge Bucaran
8,080 Points

A bit late, but still on time! Here is my link. TicTacToe

Jo Albright
Jo Albright
5,199 Points

Very fun design! And I like the ? for stalemate.

Jo Albright
Jo Albright
5,199 Points

That "?" was supposed to be the infinity symbol. Looked right in the input field. :)

Jorge Bucaran
Jorge Bucaran
8,080 Points

I left the 2P and Options screen unimplemented, but will follow up with that tomorrow. Great work everyone and hoping for more iOS contests from TeamTreeHouse here as well.

Jon Kroeker
Jon Kroeker
24,649 Points

Greetings everyone,

First iOS project of my own after completing the three in the iOS track, and first entry into a Treehouse forum contest. I went with the paper and pencil design, and the basic two player game functionality with a reset. I'm still learning what I can about coding applications having only started in January, but I got to start somewhere. You'll find it on GitHub @ GitHub Link

Jo Albright
Jo Albright
5,199 Points

Great job for a first app on your own. Keep it up!

agreatdaytocode
agreatdaytocode
Treehouse Moderator 24,242 Points

Well done. You should add Ninja icons for O and Pirate icons for X. And Then you can call the app Pirates vs Ninjas lol.

Here is my submission. I am a Java and front end web developer taking my first steps into iOS development.

I hope to learn quite a bit and am excited with the submissions that I have already seen.

Best of luck to you all.

Thomas Nilsen
Thomas Nilsen
14,922 Points

Amit Bijlani This was a great contest. Congrats to the winner, Jo Albright. Also I was just wondering when the new IOS course will be released. It says today, so I'm waiting eagerly! :)

Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

We will release it by 5pm EST today. Just conducting some final checks before release. Meanwhile, checkout the short CocoaPods course we released over the weekend, which helps you install third party libraries.

What new iOS course?

Thomas Nilsen
Thomas Nilsen
14,922 Points

Amit Bijlani Already done that. But thanks. Nice to have a time to look to ; )

Ohhhhh... YAY!

Brayden Kness
Brayden Kness
11,703 Points

Jo Albright what did you use to make the robot work?

Jo Albright
Jo Albright
5,199 Points

What the robot does :

I have three formulas to choose a spot :

  • Check for a winning spot : which looks through every set of three to find 2 spots owned by the robot and the third spot is free.

  • Check for a blocking spot : if no winning spot, then do the same loop but looking for the users 2 owned and 1 free set.

  • Random spot : if neither of the above are found, take all of the available spots and choose a random spot to select.

The random spot allows for gameplay to be different each time. And I change who starts each game to give advantage to both sides.

I also added a time delay and spinner at the top to make it look like the robot is thinking when choosing a spot... giving it a humanistic quality (and the thought of fallibility). Normally the choice would be instantaneous and feel like you are playing against an unbeatable machine.

Enara L. Otaegi
Enara L. Otaegi
13,107 Points

Jo Albright, I've been watching the WWDC 2013 Session Videos and they were talking about this blurry effect they do in the control center and so on. And I thought about your app, (I liked that blurry effect soooo much). So, I don't know if you were aware of this but maybe you could use it to save some code drawViewHierarchyInRect:afterScreenUpdates:. "Use this method when you want to apply a graphical effect, such as a blur, to a view snapshot."

<3! I was curious about this too. Thanks Enara.

Jo Albright
Jo Albright
5,199 Points

So there are implications to using special methods that do things under the hood for you. Yes it simplifies parts of your code, but you lose speed a lot of times. In this case, that blur method in the Tic Tac Toe app (which is partly found code that I have modified and simplified it even more), so far is the fastest blur render I have tested. I use it in my app Liltool, which is a vector drawing app. I do a live render blur for the top and bottom bars and it needs to render as fast as possible as you drag things around.

So short answer, yes there are simpler ways of doing them... but I am one of the last people to use simple methods, as I enjoy as close to total control over my environment as possible. For my drawing app, everything is done with CGContext and methods like CGContextAddCurveToPoint, CGContextSetBlendMode, etc.

Enara L. Otaegi
Enara L. Otaegi
13,107 Points

I guess I was assuming that Apple provides us better methods for all cases, but it depends on our needs really. Thank you for sharing your experience, this is very useful.

Thomas Nilsen
Thomas Nilsen
14,922 Points

Jo Albright I was just wondering. In your code, when you implement the protocols and delegates. Why does yours say:

@property (nonatomic, assign) id <TTTGameCellDelegate> delegate;

and not

@property (nonatomic, weak) id <TTTGameCellDelegate> delegate;
agreatdaytocode
agreatdaytocode
Treehouse Moderator 24,242 Points

Hi Thomas, great question! After searching via google and a few other sites like stack overflow here is what I found.

I'm sure Jo will have a better answer for you but I hope that helps.

Strong is the same as retain in a property declaration, so for ARC projects use strong instead of retain.
Use assign for C primitive properties and weak for weak references to Objective-C objects.

//Link below to stack overflow answer:
//http://stackoverflow.com/questions/8927727/objective-c-arc-strong-vs-retain-and-weak-vs-assign
Jo Albright
Jo Albright
5,199 Points

Thanks Aaron Ackerman for answering very quickly. And yes, that is basically the answer (under normal conditions).

Note : Apple documentation does write weak when describing how to create a delegate. But it does not explain why weak instead of assign, only that you should not use strong.

Like every other convention known to man, this is debated because of different view points. Most people just debate based on partial information (I am not immune to this).

Some people build delegates that will deallocate before the class that is accessing it. Since this happens they want it to be weak so that when the delegate is sent a message, the delegate will be nil instead of a dangling pointer. This seems to have happened with people running multi-threaded actions that make timing an unsure thing. I honestly don't know what use case would warrant that situation. And I would first question is what they are doing correct.

In this app, I have no items that will call a delegate after it was deallocated. So I write assign for delegates, mostly to keep myself inline when building apps. No, I am not against writing weak, this is just a convention I have learned from someone smarter than me.

Basically, you should never do something because one person says that is the way you should do it. You need to understand the situation and the consequences from your actions.

Hopefully this is helpful information.