LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Games in labview

I have recently been starting to try to learn more about programming and I saw a few example of games made with labview.

 

I wanted to try my hand at doing a game like battleship, but I get kind of stuck on the function I would use to compare the 2d array of the two boards to confirm a hit.

 

Any help is welcome for this side project.

0 Kudos
Message 1 of 9
(7,895 Views)

This is not an idea on how to improve FPGA modules in LabVIEW.  Actually, it seems like it doesn't have anything to do with FPGA.  This is a general LabVIEW question.  I'll ask to have it moved to the LabVIEW forum.

0 Kudos
Message 2 of 9
(7,884 Views)

Neroh wrote:

I wanted to try my hand at doing a game like battleship, but I get kind of stuck on the function I would use to compare the 2d array of the two boards to confirm a hit.


Array operations are a core skill of any experienced LabVIEW programmer, so this is a good exercise.

It is also a very simple one, the code would probably fit on a postage stamp. 😄

What have you tried so far? Where did you get stuck?

 

 

0 Kudos
Message 3 of 9
(7,865 Views)

Games are an EXCELLENT way to learn a new programming language!

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 4 of 9
(7,844 Views)

I'll try not do that again

 

0 Kudos
Message 5 of 9
(7,806 Views)

At first I was a bit stuck, but then I got going and made the 4 arrays (2 for each player; one radar & one to place the ships) Then I compared them with an and function  and got a sub array  but I was stuck on what function I would use to get the matches in both arrays to work in an event function so that it would incremente the score if one was hit.

0 Kudos
Message 6 of 9
(7,800 Views)

Once you have the 2 arrays ANDed together, you now have another 2-D array (not a sub-array).  You can then use Boolean to 0,1 to convert the Trues to 1's.  Then use Add Array Elements.  Now you'll have the total number of 1's in the 2-D array (and thus the total number of Trues in the 2-D boolean array.

Message 7 of 9
(7,793 Views)

that does sound a bit simpler than using the index array and comparing them that way by row like I had thought to do in the first place

 

0 Kudos
Message 8 of 9
(7,758 Views)

If you use an event structure, you can find the hit point by comparing the old vs the new array state (both from the event data node) using "not equal". This will result in a boolean array with exactly one TRUE value. You can find its 2D indices using "boolean to 0,1" and "array min&max". Now use the indices to index into the battelship array and see what's there (water or ship). (see also this discussion)

 

What is the datatype of your various arrays?

0 Kudos
Message 9 of 9
(7,721 Views)