LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Struggling with Tic-Tac-Toe Game in LabVIEW for a Week Now

Solved!
Go to solution

20230905_081510.png
Thank you for the feedback, especially about file naming and handling. I understand how the current method can cause confusion, and I'll make sure to be more careful moving forward. I appreciate your insights about using shift registers instead of locals; I'll look into that and see if I can make the switch. I've saved a previous version and attached it again for your review. I'll be sure to closely examine and apply your suggestions to improve the code.

 
0 Kudos
Message 11 of 20
(729 Views)

Be very careful with wiring, for example your shift register on the left is not even connected!

 

altenbach_0-1693868926575.png

 

Before "save for previous", you should make sure that your files are near each other. Your toplevel VI ls located on onedrive, but is currently using a scoreboard vi that is very for away in a long relative path (your downloads folder!), so "save for previous will create deep hierarchies to keep the relative paths correct.

 

0 Kudos
Message 12 of 20
(716 Views)

See if this can give you some ideas....

 

(Probably needs a few tweaks.)

Message 13 of 20
(703 Views)

I don't know how to express my gratitude any further! There are so many features that I don't know about,

 

so I will take my time to learn and study them carefully. Thank you

 
0 Kudos
Message 14 of 20
(651 Views)

Note that this is just a quick draft and should be cleaned up. For example you want a proper state machine to allow flexibility on what side is a user and/or AI (User vs User, User vi AI, AI vs User, AI vs. AI).

there is also a bug that it currently does not count tied games. Maybe you want to double the scores in the shift register (and divide by two for display) and give each player half a point if the game is tied. Alternatively, you could use an array with three elements, one for the game #.

 

You can easily take the subVI that makes the computer move and implement more intelligences so it plays smarter. It can of course be made so it never loses.

0 Kudos
Message 15 of 20
(645 Views)

I am satisfied with the current random actions of the computer.
I have three things left to implement:

 

1.Random First Player for 2,3,4,5 round:

- I'm currently working on randomly choosing who goes first. I plan to add a case structure and another shift register for this.

 

2.Win Line: When someone wins, a line should be drawn across the icons in one of the 8 -

winning cases.

- Should I add 18 other picture rings for the 8 winning cases with two different users (x, o)? But this could mess up the array data.
-Is there a way to change the transparency of an object after a certain trigger? That seems easier, I think.

 

3.Top Score: I need to maintain a "TopScore" data file to record the highest score and user name. The top score and name will be displayed when the program starts. If a user beats the top score, they will be prompted to enter their name, and the "TopScore" file will be updated. 

-I need to figure out how to save the value into a file, open it at the start, and rewrite it whenever someone achieves a higher score.

 
0 Kudos
Message 16 of 20
(632 Views)

20230908_110538.png

 

I attempted to introduce a random player for the second round by adding a new state. However, the current setup always starts with the user as 'X' on a mouse click. I tried reordering the computer's moves and adjusting the conditions within the case structure, but something went off. The game's behavior is now erratic and doesn't function as expected....😥

 
0 Kudos
Message 17 of 20
(599 Views)

20230908_134100.png

 

After the game ends and when I press the start button, I tried to let the computer randomly make the first move before transitioning to a new board for the next game. But it doesn't seem to fit the structure.

I attempted to have the computer make its move before the player during the mouse down event when the game status is at 2. However, this results in the computer moving twice in one turn.

It seems impossible when both the computer and the user are within the same event. To make it work, I might need to completely separate the user and computer turns within the event case. It's challenging.

 
0 Kudos
Message 18 of 20
(589 Views)

20230908_154222.png

 

When the score is 2 or higher, I tried to detect the start button through the event structure to have the computer make a move at the beginning of the board setup. However, if no event occurs, the process doesn't proceed, so this approach also doesn't work.

 
0 Kudos
Message 19 of 20
(576 Views)

Hi zubat,

 


zubat18@gmail.com wrote:

When the score is 2 or higher, I tried to detect the start button through the event structure to have the computer make a move at the beginning of the board setup. However, if no event occurs, the process doesn't proceed, so this approach also doesn't work.


Did you read the LabVIEW help for event structures?

(Strong) recommendations

  • Use only one event structure per VI!
  • Don't hide event structures inside case structures. The one event structure in your VI should live in a loop being able to iterate all the time…
  • Why don't you place the code of that upper-left case structure in the event shown in that bigger event structure???

Other items:

  • Use less/no locals. Why is "Game" a local when you can branch the wire to the Game indicator??? And why do you need a DBL indicator to display an I32 value?
  • Straighten your wires! Why are all wires into the big event structure bended?
  • What about strict left-to-right wiring? That case structure in the upper left clearly violates that recommendation several times…
  • There is no "score" visible in your image. The case structure depends on value of "Game"…
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 20 of 20
(568 Views)