0
\$\begingroup\$

I am creating a circuit in Logisim which allows two players to play a game of Tic Tac Toe. The game begins when the "Begin Game" button is pressed. When it is pressed, a random player is selected to make the first move. I have used D Flip-Flops throughout my circuit.

Here is my D Flip-Flop circuit on the top left, as well as what the game looks like on the exterior after the "Begin Game" button has been pressed:

enter image description here

Here it is on the interior (I have removed the rest of the circuit to focus on the area my question is relating to), and below is the circuit for the Random Player Generator (Including a D Flip-Flop and a Random Number Generator which, in this case, outputs either 1 or 2):

enter image description here

As you can see, my Random Player Generator is functioning as it should. However, my problem is now with switching players. Once a player takes their turn, they press their "End of Turn" button and then the "Player X's Turn" lights should swap. I have been struggling to figure this out for quite a long time and have made no progress. I would appreciate any help on how I would achieve this or any suggestions as to how I can implement this changing player function as well as the initial Random Player Generator into my circuit in a better way.

\$\endgroup\$
0
\$\begingroup\$

Use a 'proper' D-type flip flop and a high-speed clock source.

By 'proper' I mean one that has all the elements available; S, R, Qbar and ENABLE. A T-type flip flop IC usually only offers CLK, T and Q, as do some D-type ICs. A 4013 will do the job nicely.

tictactoe

Holding Begin Game enables the flip flop and Q switches on each rising edge of CLK. If the clock source is very high (KHz+) then the result should be random; the output will toggle hundreds of times in the short period that Begin Game is held down for.

The End of Turn buttons plug directly to the S and R inputs of the flip flop - these change the output asynchronously and force it to either high or low, depending on which button is pressed. In the circuit above, pressing End of Turn for Player A will SET the flip flop to 1, thus activating Player B's turn. Pressing End of Turn for Player B will RESET the flip flop to 0, this activating Player A's turn. Pressing either button repeatedly will have no effect if it's the other players turn.

CAVEAT: This circuit provides no protection for mult-button activation. If either of the End of Turn buttons is held down, Begin Game will have no effect as the S and R inputs override all others. The R input takes priority in an S-R flipflop, thus if both End of Turn buttons are pressed together then the output will be constantly held at 0, i.e. Player A's turn.

If either of those conditions must be eliminated, you'll need to design some circuitry to prevent them from having an effect. If you are just designing a simple version then it can be omitted.

\$\endgroup\$
  • \$\begingroup\$ Actually SR will be worse than T because of the problem you mentioned, you should be using a JKFF to fix this problem. And a TFF is just a JKFF with the inputs connected togheter. I don't see any limitation in that, it just simplifies your circuit, but you can work this out in a bunch of different ways. \$\endgroup\$ – BloodOnMyBlade Oct 30 '15 at 10:06
  • \$\begingroup\$ The point of using the S and R elements is to remove the need for a clock pulse to trigger the state change. \$\endgroup\$ – CharlieHanson Oct 30 '15 at 12:13
  • \$\begingroup\$ But you gonna use that anyway in the S and R inputs of your FF. The problem here is not which FF you use, it is how to use it. \$\endgroup\$ – BloodOnMyBlade Oct 30 '15 at 20:53
  • \$\begingroup\$ I'm going to use what in the S and R inputs? \$\endgroup\$ – CharlieHanson Oct 30 '15 at 21:02
  • \$\begingroup\$ Each player end turn button. \$\endgroup\$ – BloodOnMyBlade Oct 30 '15 at 21:27
1
\$\begingroup\$

You could use a TFF(Toggle Flip Flop).

TFF

From wikipedia: https://en.wikipedia.org/wiki/Flip-flop_(electronics)

If the T input is high, the T flip-flop changes state ("toggles") whenever the clock input is strobed. If the T input is low, the flip-flop holds the previous value.

This is how i would implement, there may be better implementations.

The TFF gonna hold the information about players turn, if you connect "player A LED" to Q and "player B LED" to Qnot, one will always be the oposite of the other, so only one is on at time, which tells you which player turn is. Then to change between turns, you should toggle the flip flop. To achieve this you should hold the T input HIGH and make a single pulse in the clock input, that will invert the logic state of Q and Qnot, making each "player turn LED" switch its state.

To achieve the random player turn generator, you can hold the T input HIGH, while the game is off, and put a clock signal in the clock input. The higher the clock frequency the better randomness you'll get, but be aware of your circuit limitations. That will make your Q and Qnot switch fast when the game if off. When the "begin game button" is pressed, the clock signal should stop pulsing, stoping in a "quite random" logic state, indicating which player turn it is. I say quite random cause it is quite difficulty, if not impossible, to achive real randomness in eletronics, but if you use a high frequency clock it should be pretty hard to control, through a mechanical switch, which player turn it will output.

If you still have some dificulty implementing this i suggest you doing some reaserch on T-Flip Flop, im sure there is a lot in the internet about. Also trying to implement a discrete TFF on a simulator should make it easier to understand it.

\$\endgroup\$
  • \$\begingroup\$ Thank you for your answer, I didn't think about using a TFF. However, I'm still struggling figure out how to implement this solution into my circuit, as well as having the Random Player Generator shown above in my second image. In this image the Begin Game button has just been pressed and has chosen Player B to make a move. Now when Player B has taken their turn, they press "End of Turn" and the wire going to "Player B's Turn should turn off and the wire going to "Player A's Turn" should turn on. \$\endgroup\$ – KOB Oct 28 '15 at 10:36
  • \$\begingroup\$ I've edit my anwser, see if it get easier to understand. \$\endgroup\$ – BloodOnMyBlade Oct 28 '15 at 12:53
  • \$\begingroup\$ Thanks for that, I understand all of your explanation and both of your suggestions work perfectly if I implement one or the other into my circuit, but now the last problem I seem to have is having both of them working together in my circuit. \$\endgroup\$ – KOB Oct 28 '15 at 14:13
  • \$\begingroup\$ Then the problem goes down to knowing how to plan your implementation I think, you already have the knowledge but you don't know how to use. What i would suggest for you is to maybe plan a logic flow diagram and a circuit block diagram. If you plan your logic flow correcly you can pick the components to make that logic happen by creating a circuit diagram. That is normally what I would do in this situation. A tool that I would recommend is lucidchart.com. It has a free version that will problaby suit your needs. Also, its kind bad to ask for implementation here, people get mad. xD \$\endgroup\$ – BloodOnMyBlade Oct 28 '15 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.