[quote name=\'JamesVipond\' date=\'Jan 25 2006, 01:57 PM\']Earlier this month I downloaded a copy of TNT Basic for Mac OS X, and have decided to start with a simple project: the Secret "X" game from
The Price Is Right. I have already created some graphics and laid out the logic of the program, but I haven't written any code yet. Is there an efficient way to check for three in a row after the computer hides its X and the player places two or three more X's?
[snapback]108645[/snapback]
[/quote]
There's probably a way to do it more efficiently, but it seems that far and away the easiest way to code it would simply be to check the five possible lines on a Secret X board ('cuz you don't have to deal with the three verticals, right?) and see if one of them has all X's. Anything you write is gonna be some flavor of that anyhow, so I doubt from an efficiency standpoint it's going to make a difference.
That said, you know where the Secret X is, right? So if you know that, there are only at most three lines you have to check, and that only if the X is in the center. If it's on the top or bottom, you only have to check that horizontal line, because the rest of the board is irrelevant.
I'd guess you want to code the board as a 3 by 3 array, and you would just do something like:
XRow = RowWhereXIs
If ((([XRow, 1] = "X") and ([XRow, 3] = "X")) Or (((XRow = 2) And (([1, 1] = "X") and ([3, 3] = "X")) Or (([1, 3] = "X") and ([3, 1] = "X")))) Then
AWinnarIsYou
Else
PlayLoserHorns