10-07-2014 01:42 PM
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.
10-07-2014 03:32 PM - edited 10-07-2014 03:33 PM
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.
10-07-2014 04:30 PM
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?
10-07-2014 05:31 PM
Games are an EXCELLENT way to learn a new programming language!
10-07-2014 11:19 PM
I'll try not do that again
10-07-2014 11:23 PM
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.
10-07-2014 11:29 PM
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.
10-08-2014 04:12 AM
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
10-08-2014 09:43 AM
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?