DIY LabVIEW Crew Documents

cancel
Showing results for 
Search instead for 
Did you mean: 

Dots & Boxes Game

DaB_intro.png

Behold! Yet another game from our childhood, when nothing more than paper and pencil was all we had to keep us entertained, Dots and Boxes was one of those intangibly exciting and addictive games we used to play against our bretheren. Simple, fun and cheery, it was quick to set up and strategy was key to beating your foe. And now, for your entertainment, it's available to play in LabVIEW!

Intro

As a personal project I spent some time creating this game in LabVIEW because, well, I wanted to. And that's good enough reason for me.

If you don't know Dots & Boxes then the rules are simple. The winner is the player with the most boxes at the end of the game, and you create boxes by drawing lines between the dots. The challenge is creating boxes without letting your opponent steal them!

Each player takes a turn to draw a line between two dots (only horizontal and vertical lines permitted). If that line completes the four sides of a box then you win the box and get to draw another line. Use strategy to force the hand of your opponent and crush them into defeat!

I want to play it, how please?

  1. Download and open the LabVIEW project Dots and Boxes.lvproj
  2. Open Dots and Boxes Game.vi and run it.
  3. The game will ask you which grid size you want - select 7 by 5 for your first game.
  4. If you're playing alone, change the Player 2 player type to computer.
  5. Start your first move by selecting a space between two dots on the grid to create a line.

Computer Opponent

If you're playing against the computer, it will choose it's edge immediately so it will be your go again quicker than you can blink. Keep drawing edges, and attempt to complete boxes. Warning! The computer player will spot any 3-edged zones that can be easily completed to make a box, so if you leave an obvious opening like that it will take your box from you and leave you weeping in the cold! So try to be strategic!

The computer opponent is not so smart actually, and can easily be fooled. Sometimes it will create 3-edged areas itself, handing you a free box opportunity on a plate. And it can't project forwards to estimate the value of any particular move, so with your human brain you should be at an advantage. However, it's beaten me more than once, and I'm not ashamed to admit it.

Game Features

It's very simple, but these features are worth checking out:

  1. You can set you player names if you wish - just select the name and start typing.
  2. You can move the game around by dragging the title area (check out the Event Structure to see how that's handled)
  3. None-rectangular front panel! Not so obvious in the snapshot above, but the rounded corners are transparent. See Steve's blog on Groovy Splash Screens for hints on how this was achieved.
  4. The grid is an XControl (queue ominous orchestral blast). XControls are awesome. Period. Check out the code!
  5. The whole code is open source - so please feel free to browse through it at your own pleasure. Don't criticise the style though, this was a personal project conducted without all the usual controlling processes so it's messy in places - especially the code for drawing the grid which got hacked at more than once.

Creating your own Computer Intelligence

I'm hoping y'all out there will be interested in creating your own computer opponent! The "Computer_Play" state of the state machine calls the computer player code to choose which edge to create, and included here is my own very basic computer player. Please go ahead and create your own computer player code and try it out! If you can post it here then all the better! I'd certainly be interested to see what people come up with!

There will be a challenge over on the Breakpoint forum for user entries, and if we get enough we might be pitching them against one another. Fun times!

LabVIEW Specifics

It's written in LabVIEW 2011 under Windows 7. It should work on all platforms, although I haven't tested it on anything else.

Comments

There's room for improvement, furtherment, or I might just do nothing more with it. It was fun to create, and I'd love to see some intelligent computer opponents developed by you smart folk out there that will make this game a real challenge to play!

All comments welcome!

Parting Words

Enjoy! And don't let your boss catch you playing games at work. It may be LabVIEW, but it's still a game

Version History

V1.0 - First release (7th April 2014)

Thoric (CLA, CLED, CTD and LabVIEW Champion)


Contributors