Discussion:
Tetris in Labview
(too old to reply)
xseadog
2005-09-12 19:13:11 UTC
Permalink
Upload it

as the quote goes  'learn what you can, share what you know'
chow xseadog
TiTou
2005-09-12 19:13:14 UTC
Permalink
Hi there !
 
Tetris  in LabVIEW that  sounds great, I'd  love to see the code... please up load it !
 
AnalogKid2DigitalMan
2005-09-12 20:43:47 UTC
Permalink
Sheldon:
 
You may also want to upload it to the games area:
<a href="http://www.ni.com/devzone/lvzone/games.htm" target="_blank">http://www.ni.com/devzone/lvzone/games.htm</a>
Sheldon Stokes
2005-09-13 13:13:06 UTC
Permalink
Here's the code, I'd appreciate any comments you may have.&nbsp;
&nbsp;
I couldn't think of a better way to design the app given that there two different event loops that have to be processed.&nbsp; Any good ideas to remove the only local variable would be appreciated as well.&nbsp; I didn't want to set up another communication queue for just the timing local.&nbsp;
&nbsp;
I've seen LabTris, but it wasn't working for me (after the first piece, the pieces are invisible), and rather than reverse engineering it, I thought I'd write one from scratch as a learning tool for me, and hopefully a learning tool for my co-workers.
&nbsp;
Sheldon


labview_tetris.llb:
http://forums.ni.com/attachments/ni/170/142236/1/labview_tetris.llb
altenbach
2005-09-13 16:13:25 UTC
Permalink
Sheldon,
Code looks quite nice!
I only quickly glanced at the code and I am wondering why you even use a picture control. Wouldn't it be easier to simply use a 2D array of colorboxes? This would simplify coding dramatically ('not sure about speed).
There are a few errors in the behavior:
For example notice that in the attached image the times on the left&nbsp;are floating one row up for no reason.
<img src="Loading Image...">
&nbsp;
Also, Tetris typically allows you to shift a piece left or right for one "tick" after it reached the bottom. This is important to e.g. slide a piece under an overhang. Your implementation does not allow this.
&nbsp;
&nbsp;Message Edited by altenbach on 09-13-2005 08:49 AM


tetris1.png:
http://forums.ni.com/attachments/ni/170/142292/1/tetris1.png
Sheldon Stokes
2005-09-13 13:13:06 UTC
Permalink
Here's the beginning of some external documentation (I'm always&nbsp;behind on my documentation).&nbsp;
&nbsp;
Sheldon&nbsp;


LabView Tetris.pdf:
http://forums.ni.com/attachments/ni/170/142237/1/LabView Tetris.pdf
Ben
2005-09-13 13:43:38 UTC
Permalink
Nice share Sheldon!
I have included this thread in the examples listed in the Picture Control discusion that can be found here.
<a href="http://forums.ni.com/ni/board/message?board.id=BreakPoint&amp;message.id=899" target="_blank">http://forums.ni.com/ni/board/message?board.id=BreakPoint&amp;message.id=899</a>
I appreciate your posting!
&nbsp;
Ben
Sheldon Stokes
2005-09-13 14:13:26 UTC
Permalink
I don't have imaq, and I wanted to build this game...er...tutorial using only the basic LabView elements.&nbsp; I initially started using picture controls to make a block which was faceted and was comprised of a filled rectangle for the top.&nbsp; I drew&nbsp;8 lines around this rectangle set to lighter and darker colors to simulate the lighting of the facets.&nbsp; The pieces made from these blocks looked really good.&nbsp; I created a sub-vi to create the block of a given color.&nbsp; I then drew the board by converting the block picture to a pixmap, then I unflattened the pixmap, and redrew the block at a specified position using "Draw unflattened pixmap".&nbsp; This worked, and looked quite nice.&nbsp; But the flattening and redrawing took too much time for this application.&nbsp; The board was changing (in the mathematical model) while the last state was still being drawn.&nbsp;
I couldn't find a quick way to do what I wanted to do without going through the flattening kludge.&nbsp; This method also seems quite slow in terms of performance.&nbsp; I guess that imaq provides a lot greater pallet of drawing functions that would solve my problem.&nbsp; However, LabView seems quite slow at doing these sorts of drawing tasks in general, which is unfortunate.&nbsp;
BTW, I'm working on a network based Pong game...
&nbsp;
Sheldon
&nbsp;
Ben
2005-09-13 15:13:51 UTC
Permalink
Uncle,
&nbsp;
does this help?
<a href="http://forums.ni.com/ni/board/message?board.id=170&amp;message.id=126863" target="_blank">http://forums.ni.com/ni/board/message?board.id=170&amp;message.id=126863</a>
&nbsp;
Coastal,
&nbsp;
My intension was not to lie or deceive in anyway :smileyvery-happy:
&nbsp;
Ben
unclebump
2005-09-13 15:43:28 UTC
Permalink
Thanks Ben
&nbsp;
Change the path control in this vi to point to the png file&nbsp;after unzipping the file. This should put transparent darts&nbsp;randomly on top of the dartboard picture indicator. 7.0 format.


overlay images in labview picture control.ZIP:
http://forums.ni.com/attachments/ni/170/142288/1/overlay images in labview picture control.ZIP
Sheldon Stokes
2005-09-13 15:13:44 UTC
Permalink
I actually didn't use my complex draw routine due to speed issues.&nbsp; For the sake of speed and smooth game play, I am drawing my blocks are filled rectangles which is a couple order of magnitude speed increase over my "Fancy" draw routine.
I spent a bit of time profiling my VI and seeing where the slowdown is.&nbsp; Pre-making the blocks can save some time, but the conversion from a small picture to data than replotting that data into another picture control is what was killing me time-wise.&nbsp; I'd love to hear how you can take a small picture and place it at an X,Y position in a larger picture without the flattening and such, and the speed hit that comes with it (without imaq).
I'd also love to hear what you experts think of my overall architecture, and if you have a clever way to eliminate the local I had to use.&nbsp; Basically, I'd love to hear if I've gone at it the right way, and I'd like to learn for your experience.&nbsp;
&nbsp;
I'll be glad to explain how and why I did what I did if there's interest.&nbsp;
&nbsp;
Sheldon
DFGray
2005-09-14 13:13:09 UTC
Permalink
Has anyone tried an intensity graph for this?&nbsp; If you set the
color ramp correctly, you can change the colors by simply changing the
numbers in the data sent to the graph.&nbsp; I don't know if this would
be faster than the picture control, but it may be worth a try.&nbsp; It
is also fairly easy to change the "resolution" on the fly.&nbsp; If I
have time, I may benchmark it.
unclebump
2005-09-14 14:13:40 UTC
Permalink
Could you save that as a 7.0 format. Thanks.
&nbsp;
Sheldon Stokes
2005-09-14 17:43:09 UTC
Permalink
That's a good idea with the intensity graph, I tried to make the application as modular as possible, so that the board and board draw routine can be scooped out and a new one put in it's place.&nbsp;
I've been learning Cocoa on the Mac these days.&nbsp; (it's NeXTStep evolved a bit)&nbsp; I haven't been this excited about a programming&nbsp;language (it's really a framework for objective-c)&nbsp;since LabView.&nbsp; Imagine doing graphical apps with very little coding and very quick setup.&nbsp; I can put up a hello world app with buttons in roughly the same time as labview.&nbsp; No sub-classing, and a great interface builder.&nbsp; The really cool part is that GNUstep allows Cocoa apps to run on a variety of unix-like platforms with very little application mods.&nbsp;
&nbsp;
Sheldon
altenbach
2005-09-14 19:13:25 UTC
Permalink
Sheldon,
&nbsp;
I made a quick draft using a 2D array of color boxes for the display (LabVIEW 7.1). This is what I had in mind in my earlier post.
&nbsp;
<img src="Loading Image...">
&nbsp;
&nbsp;Message Edited by altenbach on 09-14-2005 12:02 PM


FallingBlocks.png:
http://forums.ni.com/attachments/ni/170/142549/1/FallingBlocks.png


FallingBlocksColorbox01.vi:
http://forums.ni.com/attachments/ni/170/142549/2/FallingBlocksColorbox01.vi
JoeLabView
2005-09-15 12:12:57 UTC
Permalink
Very nice Altenbach!
:D
&nbsp;
Costal,
Wow... you recruit your people at a young age..&nbsp; Probably a good strategy ;)
That's a nice training project.&nbsp; Good work guys!
:DMessage Edited by JoeLabView on 09-15-2005 07:44 AM
Ben
2005-09-15 02:42:58 UTC
Permalink
"much nicer than drawing to a picture indicator."
&nbsp;
Please do not give up on the picture cotrol so quickly!
&nbsp;
Here is a rev of your posting that illustrates using an action engine to cache the static images and just update the moving stuff. See tetris2 (in LV7.1)
&nbsp;
It also features that 3-d look.
&nbsp;
What do you think? Still gonna give up on the picture control?
&nbsp;
Ben
&nbsp;
PS I'd love to see the dog version in an intensity graph.Message Edited by Ben on 09-14-2005 09:36 PM


labview_tetris.llb:
http://forums.ni.com/attachments/ni/170/142615/1/labview_tetris.llb
Ben
2005-09-15 12:12:59 UTC
Permalink
Hi Coastal and vivi,
That is a very very impresive first public release!
I will comment more latter if&nbsp;possible. There is simply to much in that example for me to do it justice this AM.
&nbsp;
vivi,
Please give me an idea of what you want me to comment on and what you do not. Otherwise I will put your code through the same&nbsp;ringer I put my trainees through. WARNING: I can be very anal retentive when it comes to code reviews :smileyvery-happy:
&nbsp;
Ben&nbsp;
Ben
2005-09-16 00:43:10 UTC
Permalink
part 2 of 3&nbsp;

&nbsp;

6) A diagram is easier to read if it flows left to right or top to bottom. I figured out that it started out at the top and went left and down. Then I realized you were getting references to decorations inside cluster. Thinking that you may be hiding and showing some type of decoration, I tried running the code again and played with the preferences. After restarting the game board disappeared. It seemed to go away after I saved all of the VI's. This makes sense if you are building a path based on a VI path... which it turns out you are.

&nbsp;

7) That adventure lead me past the preferences cluster. When I was playing with adding a user I got locked up the screen. Having recalled seeing something like "you have entered the same..." I tried entering values other than all "a" for every type of move. It eventually let me out. Most people do not review the source code before running a program. Give them a hint how to get out of any hole the climb into.

&nbsp;

8) The Preferences cluster has a bunch of strings that you trying to match up in the "key down" event. Rather than keep the users preferences as strings that force you to type casting all of the time, consider flipping this inside out and type cast the user info so it matches the data types returned by char and VKey. What is "VKey"? I never played with that one.

&nbsp;

9) If the preferences were kept as two arrays you could do a "search 1-d array" for the character returned. A non-minus one indicates one of the key was hit, the index would tell you what action. A variation on this theme is shown in the attached VI that shows how the indexes can be typecast as enums to drive self documenting cases. Remove the default and it will remind you everyplace you need to add a new case if the enum is saved as a typedef.

&nbsp;

10) Making the key down a sub-VI would definitely help with your top level's diagram.

&nbsp;

11) The bulk of what I saw was technically very sound and is consistent with how well the app performs.
&nbsp;
end of part 2
&nbsp;
Ben


typecast.vi:
http://forums.ni.com/attachments/ni/170/142843/1/typecast.vi
Ben
2005-09-16 00:43:11 UTC
Permalink
part 4 of 4

&nbsp;

17) When you create a sub-VI edit the icon connector to a standard you choose. LV's "use every terminal" philosophy complicates supporting your code in the future. If you have to choose a larger layout just to add one terminal, you have to go back and re-link all of the VI calls.

&nbsp;

&nbsp;

18) Take a look at the code Sheldon posted when he started this thread. His VI was structured such that I could take a shot at modifying it for better performance. Unless I miss my guess your structure and his structure are identical and differ only in the expression (and that yours is much more developed)!

&nbsp;

I hope this is helpful. There are tons of other things I could say but then this would be too much like work. If you structure your code and re-post I would love to see the cleaned up version. I am still curious exactly how you implemented this app.

&nbsp;

Now one more note just to contradict most of what I said above.

&nbsp;

"If you write perfect code, no one will ever have to look at it."

&nbsp;

Ben
PS NO, I am not trying to pad my posting numbers. I keep getting messages saying I am over the 5000 character limit. Molly!
Message Edited by Ben on 09-15-2005 07:30 PM
Ben
2005-09-16 00:43:11 UTC
Permalink
Part 3 of (woops) 4

&nbsp;

12) I went to the hierarchy to try and get a hint as to what you were doing early on. Your VI names seemed good but at least one sentence to spare me have to look at the diagram would be helpful when you are trying to remind yourself years from now what was going on.

&nbsp;

13) I push my co workers to take the time to do cool icons that really make it clear what the VI is doing. LV's built in icons show you a lot of good ones and some bad. The less text required the better. I once took great joy when my wife (a non-LabVIEW user by the way, argh!!!!) looked over at my machine and said "New User?" when she saw a kindergarten head with the word "New!' above it.

&nbsp;

Once you get over about 75 VI you will start to reap the benefits of cool icons. You will be able to "at a glance' spot the VI you know makes the blocks you want to edit. When I have multiple sub-systems in an application the icons are designed so the look like the widget I'm talking to. Again when you have a hierarchy screen with 500 icons you want to find the VI's for the scope so fast the customer is amazed at how easily you found it. Naming help the hierarchy screen layout by the way.

&nbsp;

14) When using shift registers in a while loop with embedded event structure, the diagram is easier to handle o f the sift registers and the wire-thru connections all at the top, or all at the bottom. The State Diagram editor is a special case were I let the SDE do what ever it wants at the bottom and I keep my stuff at the top.

&nbsp;

15) When you have values the exit nested cases through tunnels, lining up the tunnels makes it allot easier to read, and takes up less diagram space.

&nbsp;

16) Multi-frame sequence structures are now becoming bad style. They work but they require the reader of the code "poke at it to see what the animal is". Flat seq structures are easier to read.

&nbsp;

End of part 3

&nbsp;

&nbsp;

Ben
Ben
2005-09-16 00:43:10 UTC
Permalink
part 1 of 3
&nbsp;

Hi vivi,

&nbsp;

I am just going to fire away with the thoughts as I see them.

&nbsp;

0) I drive the developers I work with nuts because I harp on style a lot. Having said, let me go to say that I do not believe in hard and fast rules other than does it work!

&nbsp;

1) Nice picture is that from Hubble?

&nbsp;

2) Chase down the most recent version (and the old ones while you are at it) of the "Good, Bad and Ugly" that was presented by Greg McKaskle at NI Week this year. In that presentation he cast GUI design into different compass directions of travel. You UI 50% "Wow" and 50% well, boring (sp?). You may want consider imbedding the score in the picture control using an inset text at... Then all you have left over is some buttons you can pile at the bottom. Then the screen would be 95% wow.

&nbsp;

3) Seems to play well. I had to tear myself away from running the program.

&nbsp;

4) I flipped over to the back side and was sort of surprised to find such a large diagram. I mentioned earlier that I drive my co-workers crazy. Well we occasionally get projects were customers have already written something and we had to enhance it. When one of my buddies has a diagram open that is extremely large and they see me walk past, often, the first words out of their mouth is "I did not write this!".

&nbsp;

I urge my developers to develop diagrams that can be read "at a glance". By this I mean that a CLD would be able to look at the diagram for a couple of seconds and be able to explain what is going on in the code. I tell them (my buddies) that some day you are going to be trying to debug some code with a customer looking over your shoulder, so code for that situation. Sorry vivi but your diagram took more than "glance time" to be able to re-size the window.

&nbsp;

Some pseudo-holy document somewhere says keep you screen size at 1024X768. I usually shot for 1024X768 but will also not hesitate to break that rule, in both directions. Performance reasons are the best reason for breaking that rule. Building big clusters, arrays or strings is another. If you have to go over 1024X768 then go over in just one orientation, either up/down or left right depending on the shape of your code. So then I started looking around...

&nbsp;
End of part 1
&nbsp;
ben
CoastalMaineBird
2005-09-16 02:43:44 UTC
Permalink
Thanks for your time, Ben. Although this is his first released
program, it's actually his second version of Tetris. I had him do it
again, from scratch, and use a different core technique, just to force
him to come up with alternative ideas.I have not looked at his
code very much, but I do want to say some things about your comments. I
will allow him to address most of them.If you had trouble tearing
yourself away from playing the game, that is a very good sign. We both
know there's more to it than that, but that's a good bottom line.The
large-diagram thing is something I wholeheartedly agree with in
principle, and wholeheartedly violate myself in practice. I work on a
1920x1440 monitor, and I force myself to work to client's specs on
front-panel size, but don't on diagram size, unfortunately.What is a "CLD"?As
far as icons go, unlike you, I ask for simple text icons. I don't want
to spend time making icons (and it does take time) unless the audience
is programmer-type technical people, and I'm making some
general-purpose library for them. For a finished product, where all
they see is front panels, and maintain the one program, I see no point.
"Vivi" tends to spend even more time than I do, but he is following my
policy in that regard.The statement Multi-frame sequence structures are now becoming bad style.
is, IMHO, a gross generalization. I often use the stacked sequence for
no other reason than diagram space reduction (when performance allows).
To say that ANY tool is "bad style" is a bit extreme. I agree that the
"flat" sequence has advantages in some places, but certainly not all. I
have some 10-frame sequences that go to 20 when I insert timming stuff
between every frame. Just imagine what THAT looks like in a flat
sequence. And I have long objected to the simple fact that the flat
sequence voilates one of the basic data-flow rules that EVERY other
structure follows.
Your other points are well taken, and reasonable. I will let him
address those at his earliest opportunity. Again, thanks for your time
and your typing.Message Edited by CoastalMaineBird on 09-15-2005 09:25 PM
Ben
2005-09-16 13:13:03 UTC
Permalink
"What is a "CLD"?"
Certified LabVIEW Developer
The certification part is not important. CLAD's may not recognize the icon off-hand so "at a glance" reading is harder. Frequent LV Flyers will be able to recognize the standard icons.
&nbsp;
My comments are what I would have told my devlopers. They are no ones standards except my own.
&nbsp;
Over-all the things that freak me out the most are;
1) Hidden objects and wires.
2) Wiring right to left
3) Wiring in/out the top or bottom
&nbsp;
It is not that these things cause LV problems, it just turns the diagram into "Yoda-talk" were I have to think or poke to decide if this is an input or an output and what is being said.
If code with the above stuff drops on my desk, I will fix those things before I do anything else.
&nbsp;
Ben
JoeLabView
2005-09-29 17:10:52 UTC
Permalink
the challenge is to be better... ;)
&nbsp;
.. and there is always room for that..
&nbsp;
Concerning the icons.
&nbsp;
I decided to group the icons by functionality and assign specific colors to them.&nbsp; The image represents what it does.
So when looking for a partiular vi, I first look at the color and then the picture followed by the text (whatever fits).
&nbsp;
Nice job vivi.&nbsp;
&nbsp;
Impressive.&nbsp; People are going to steal you away from Coastal ;)
&nbsp;
:D
JLV
JoeLabView
2005-09-30 12:10:38 UTC
Permalink
Hi vivi,
I can send you some of them... I will try to remember to do that this weekend.&nbsp;
The nicer ones I created were for the visionProbe &amp; visionIce programmers.
Basically, I "borrowed" the pattern from Rohde&amp;Schwartz.&nbsp; You could download their LV drivers for their spectrum analyzers.&nbsp; It was the best example I could find.&nbsp; Basically, they created a tree which describes each of their vi's.&nbsp; I started with that and used solid colors as backgrounds for the icons and degraded colors for backgrounds of specific functions, such as Flash programming (dark to light blue), FPGA programmer (Orange to yellow), etc.&nbsp;&nbsp;
Although I try to keep a vi to a single page, the color scheme helps you to "see" its contents.&nbsp; And less brain CPU to figure out what it does.
Oh..oh... I'm starting to share my secrets.... and to the competition ;)&nbsp; Oh yeah.. you're south... I guess it's ok..&nbsp; :D
First try looking at the icons from the vi's from R&amp;S.&nbsp; I will (try) to check this forum during the weekend.
Take care,
JLV
Ben
2005-09-16 15:43:02 UTC
Permalink
To help sell the graphic icon idea, I offer the attached screen shot and ask you attempt to answer the following questions.
1) Which VI's are used in the PIDs?
2) Which VI's are used to compute Isc and Voc for the diodes characteristic curve?
3) Which VI's control the Lamps?
4) Which VI's control the curve tracer?
5) Which VI's are file related?
6) BONUS QUESTION: Which VI launches the error logger?
7) And for all you HP fans, which VI's control HP DAS and HP power supplies?
&nbsp;
Ben


Icons.JPG:
Loading Image...
Ben
2005-09-16 17:13:27 UTC
Permalink
Excellent questions!
"8... What does the bricks-falling-onto-a-diving-board icon represent?"
&nbsp;
The work of a text based programer I am trying convert over to LV. He still needs some tutoring.:smileyvery-happy:
"9... What's the difference between the "WAIT" function and the "Wait" function?"
&nbsp;
Those two VI's and their callers are the work of the vendor of that gizmo. I guess I should talk to them about their icons. :smileyhappy:
"10... What does it mean when there are 30 icons with the same picture, distinguished only by text?"
&nbsp;
Those 30 icons are all related to the same gizmo. All related VI will have a similar theme. All I have to do is just find one realted to what I am after and then do a "show VI hiera..."&nbsp; find the top, "show VI hiera..." and I have reduce a display with 500 icons down to only the VI that are involved in what I am after.
Thank you for the follow-up Q's Coastal! Your Q's are seldom easy to answer but the prcess of trying is often worthwhile.
&nbsp;
Ben
Ben
2005-11-09 19:13:01 UTC
Permalink
Hi coastal!
&nbsp;
Thank you for the heads up. You (and vivi) know how to find a persons soft spot. The orignal "Terraserver" was&nbsp;placed on-line&nbsp;by&nbsp; DEC (Digital Equipment Corporation) to show case the power of their Alpha servers. I accepted a "package" from them soon after. I get a kick out of seeing the new versions of old stuff I have been associated with.
I will check it out when I get a chance.
I like maps,
Ben

Loading...