0

Well I'm new to iOS development so I decide to start with a simple game: the tic tac toe

I added some difficulty which is to let the user freely draw their marks: a circle or a cross instead of picking them from, say, a slot containing these marks, just like in the real world we play this game using a pen and a piece of paper.

Now the problem is how can I know if a user draws a circle or a cross on the board? Any advice or reference links are appreciated.

NSF
  • 2,499
  • 6
  • 31
  • 55
  • 1
    This isn't an answer to your question, but in tic tac toe, players generally take turns. Wouldn't the turn number determine whether the player was able to draw a circle or a cross? – jonmorgan Jul 27 '12 at 22:16
  • @jonmorgan you are right. So if a player draws a circle while he should draw a cross then the circle should be deleted and a warning shows that the last movement was illegal – NSF Jul 27 '12 at 22:22
  • What if the player draws a circle with a cross through it? Like the letter O in Diablo font. – jbranchaud Jul 27 '12 at 22:29
  • 1
    Actually, the user just needs to tap - since their 'sign' and the initial player would likely be progamatically defined. – spring Jul 27 '12 at 23:46
  • Check this out: http://stackoverflow.com/questions/4600690/how-to-detect-circular-gesture-via-gesture-recognizer Hope this helps! – tams Jul 28 '12 at 02:37

1 Answers1

2

Circle can be drawn without lifting finger. If the start (touch down) end (touch up) are fairly close to each other and you have a fair amount of in between points you have a circle. You can improve this by computing major and minor radius and see how the points fit around an oval with those radii.

Cross it's composed of two drawing operations if you consider touch down and up an operation. Check if the distance between the start and end is fairly larger. When he draws the second line check if they intersect. If they intersect its most likely a cross. You could further improve by checking how well the points fit along a line that goes from first point to last point (touch down touch up)

This is a simple way to check. Of course there are situations where this method could fail miserably. But unless you want to get into more complicated stuff this should work fairly well.

thealch3m1st
  • 106
  • 4