I was asked in my C# class to write a simulation of a Tic-Tac-Toe game, and although the assignment does not request what I'm asking about, I'm a little curious about something. It just wants us to use an array to hold a random 0 or 1, and then 0 = O and 1 = X on the board. We had to use labels to create the game board, so I did, but in running the simulation multiple times, I find an odd result. 75% of the time, the board looks believable and legit. But every so often I get a weird one, like the following examples.
O O O
X O O
O O O
or
O X O
O O X
O O O
Clearly, you couldn't play Tic-Tac-Toe like that unless you're playing against someone who doesn't know the rules and cheating. My question is, is there any way besides using a variable for a "coin toss" to decide a starting player, and then alternating the turns that way, to get a more normal board? (By that I mean, X goes, then O goes or vice versa.) I'm using a 2D Array to store the random numbers, and then a series of if statements to set each label to the array values and populate the board.
I'm not posting any code because 1)this is homework, 2)it is complete, and 3)I don't want to encourage any cheating off my work, but I don't mind sharing it to get some input if there is a better way than what I've done. This isn't required, and I'm 100% sure I'm going to get full points on this, since it didn't say to forbid this scenario, but I'm curious to see if there is another way to do it without setting up another loop or two to try and use a coin toss variable/turn-by-turn method, or nesting EVERY loop to check for a winner and not let the entire game be played. I'm probably just thinking into this too much, since I'm sure the way it asked us to create this simulator is inherently troublesome for turn by turn with random values in an array.
I'm not asking anyone to do my homework, I'm asking if anyone knows of a way to limit the number of X's and O's without doing too much work. If not, I'll just live with it.