Kinect Manager available for download

Kinect Mgr Demo
You’d think I’d look more pleased that it is working…..

Today I finished all the chapters for my upcoming book about the Kinect SDK. As part of the book I’ve made a wrapper class that makes it a little easier to use the classes in the Kinect for Windows SDK. You can use it to start a Kinect running and then bind to events that driver generates when new frames are available. The frame events are processed on a “round robin” basis so that the driver will not get new data from the sensor until it has been processed by your application. This makes it work well even on low performance machines that might not be able to keep up with the events generated by the Kinect sensor. The manager also generates status messages.

You can download the class, along with a program that demonstrates it, from here. For it to work you must have installed the Kinect for Windows SDK from here. And of course you’ll need a Kinect sensor – either the Xbox 360 one or the Windows one will work fine.

Sony PlayStation Suite Available

image

Looks interesting, in spite of those scary heads.

The Sony PlayStation Suite is now in “Open Beta”. This means that you can download the SDK and start writing games and applications which you might eventually sell via the PlayStation Store. The way I see it (although I’ve not tried yet) you should also be able to get programs running on your own PS Vita using this kit and the PlayStation Suite Development Assistant. The path to market looks like it will be very similar to the App Store or Windows Phone Marketplace, with developers paying an annual retainer (the traditional 99 dollars) to allow them to unlock devices for testing and to sell their wares.

The good news is that the development language is C# and the way that it all works is not a million miles away from XNA. In fact it works so well that we had quite a few teams in our Three Thing Game end up making games using it.

Best Programming Language?

IMG_7331-Edit.jpg

There’s a program in the App Store called “Best Camera”. It takes as its starting point the idea that “The Best Camera you’ve got is the one that you have with you at the time”. The application then goes on to provide all kinds of useful tools that make the iPhone camera as good as possible.

I was reminded of this when there was a tiny bit of debate on my post about the CodeAcademy site, which teaches JavaScript. Now, JavaScript is not a great language, but it works and can be used to create useful stuff. So it is automatically a candidate for “Best Language”. In my opinion, the Best Language is the one that you are using at the moment. I base this on “Robs Rules for Programming Languages”:

  1. You can write great code in any language.
  2. You can write horrible code in any language.
  3. The user does not care what language you used to write the program they are using. The user only cares that it works and does what they want. And that they can afford it.

I’ve written programs in loads of languages. At the moment my personal favourite language is C#, but I have really fond memories of writing embedded C, since in that I could do anything I wanted and I could build all the underlying bits myself from scratch.

This is usually the point that people say things like “But blah doesn’t have blah.” or “Blah programs are really hard to use because the debugging support sucks.” So what. This brings me to the Rob’s Other Rule

  1. Having a nice place to work is much more important than the programming language you are using.

If the language you are using doesn’t have a feature that you need, find a way of programming around it. I’ve written lots of object oriented software in C. C doesn’t support objects, but I arranged the code so that it looked like it did and then programmed by “object rules”.

If the development/debugging support is horrible, wrap something around your program to make it easy to work with. I’ve built emulations of LCD panels and even lasers to avoid having to debug my programs on the real hardware. I’ve written code to make ten thousand customers from nothing, to save me having to type things in by hand. And I’ve added cheat buttons to games so that I can skip levels and inflate my scores and avoid having to play the game all the way through so that I can debug the last bits. 

Remember, when you are writing a program you don’t just control what the code does, you also control the environment the code sits in. Bending this to make things easier is something that will pay off tenfold. Can’t debug your program without a network connection? So what. Fake the web request responses so that you can feed the answers back yourself. This also makes test driven development much easier.

Of course, given the choice, you should pick the most appropriate language for the task. Give me an AI problem and I’ll be looking hard at what Prolog (or perhaps F#) can do for me. But for me programming is not about the language, it is about the problem solving, and that means a programmer should be able to turn their hand to whatever the occasion demands. Even if it is JavaScript.

Codeacademy for learning JavaScript

DSCF6379.jpg

During a First Year lecture this week I said that the students should spend some time this Easter learning JavaScript. Everyone should know a bit of JavaScript, it is what makes web sites work, and with the coming of HTML 5 it will be even more important. I’ve just found a really good way to learn it too. (this also works for anyone who fancies doing a bit of programming). Take a look at Codeacademy.

http://www.codecademy.com

Looks like great fun.

When is a number not a number?

IMG_5863.jpg

Pop quiz. What would the following C# code do?

float x = 1;
float y = 0;
float result = x / y;
Console.WriteLine(result);
  1. Fail to compile.
  2. Throw an overflow exception.
  3. Print “Infinity”
  4. Cause the universe to explode.

Here’s the thing, the code prints the word “Infinity”. Dividing any floating point variable by zero gives a special result which is encoded into the floating point variable range as “Infinity”. Now what about this?

float y = 0;
float result = y / y;
Console.WriteLine(result);

This time we get the message “NaN”, which means “Not a Number”. Dividing zero by zero does not give a number as a result. There just isn’t a value for this quantity. The value is not as big as as infinity or as small as zero its just, well, not a number. You get the same non-result if you divide infinity by infinity.

The C# runtimes are based on .NET which uses an IEEE (Institute of Electrical Electronics Engineers) standard that contains representations for negative infinity, positive infinity and “not a number”. Calculations in a C# program will produce these results when given dodgy values to work on. This is very important. You might think if you do silly things with numbers in your program you are going to get an exception thrown. Like this would.

int i = 1;
int j = 0;
int Result = i / j;
Console.WriteLine(Result);

Run this code and it throws a “Divide by Zero” exception when it tries to, er, divide by zero. But this does not happen with floating point calculations. This is probably because the range of values for the int type does not include one to represent “infinity”.

The bottom line here is that if you do sums involving floating point values you can’t expect exceptions to be thrown if the calculations go wrong. The good news is that you can use methods provided by the float type to test results of calculations:

if (float.IsNaN(fresult))
    Console.WriteLine("Welcome to the Twilight Zone");

This prints the enigmatic message if the value in fresult is not a number.

Making Kids Creative with Computers

Hornsea Lights

This seems to be the year that the education system woke up to the fact that getting kids to make things with computers is a good idea. Excellent. I’m sure it was my blog post yesterday that tipped the balance….

Anyhoo, if you’ve got kids and you want to get them into programming here are my tips for tools that you can use. Note that these are just the ones that I’ve heard of and used, there are lots of others. If you have ones that you want me to mention, let me know and I’ll add them.

Making Computers Do What You Tell Them

These systems get kids used to the idea of logic and control. They have strong gaming context, but that is not a bad thing because it is engaging and gets kids thinking in the right ways.

Little Big Planet – making games goes mainstream. A great way to play games with your kids, create stuff and get things out there. Lots of scope for making things and showing off.

Wairo Ware DIY – make your own mini-games on Nintendo DS. Great fun.

Kodu – make games that run on your Xbox 360. All the programming is done using the gamepad and it is very easy to get interesting game behaviours.

Scratch – wonderful, free platform for the PC and Mac that lets students build fun games using their own assets.

Alice – great little scripting language.

Fiddling with Hardware

There is nothing quite like making hardware jump around and lights go on from software control. Kids love this.

Lego Mindstorms – a bit pricey perhaps, but no more than a few computer games. And you get Lego quality components and a really nice development environment that lets you create some very complex behaviours. Can also be used as a stepping stone into real robotics via things like Microsoft Robotics Developer Studio

Arduino – a good way to get your hands dirty of you want to make things out of tiny components. Lots of add-ons and an easy programming environment to get to grips with. Great if you want to learn some electronics along with your programming.

Gadgeteer – just coming onto the market. If you have folks who can write simple programs (Java or C#) and want to give them an easy way onto proper hardware then this is for you.

Writing Proper Programs

This is were we get more serious. These are tools that take you into the world of proper program development. They are not to be taken lightly, but they do let you make things that you probably can sell.

Small Basic – a version of basic that is free, very easy to understand and works a treat.

XNA – a very easy to use game development environment which takes C# skills and lets you write proper games using them.  Start at the create hub and find a wealth of resources for learning and making games and programs.

A Word of Warning

Learning to use computers creatively is hard work and involves lots of practice. Just like learning to play a guitar is hard work and involves lots of practice. I’d hate folks to think that because these tools make it easy to get started (and they do) that making things that are properly impressive and useful is easy. It isn’t.

The ones that are best at writing software are the ones that are prepared to put the time in fiddling with their programs, persisting with them when they don’t work and polishing them to a high gloss when they do.

Be prepared for the moment when your kids get into computers and they find that actually they have to work at it. Good advice in this situation:

  • Too many ideas can kill you. Does your game need helicopters and evil rabbits? And laser guns? And an equipment shop? Kids latch on very quickly to the idea that with a computer program you can do anything. Unfortunately they often then try to make a program that does everything. Then they find they can’t and get disillusioned with the whole business. Suggest a step by step approach, and throwing things away if you don’t really need them just yet. After all, if the player never knows you meant to put evil rabbits into the game they will never miss them.
  • Make your steps as small as possible. Get something small working and build on it. Get the ball to bounce, then add the paddles, then add the targets, then add the boss level and so on.
  • Walk away for a while if you get stuck. Don’t spend more than an hour on any problem. If you haven’t solved it in that time, do something else for a while and go back.
  • Other people’s code is dangerous. It is very tempting to just search for a program routine to do what you want. But this often ends in tears. You are using something from someone you have never met, which might not do exactly what you want, and might not work. If there is one phrase that worries me when someone describes a problem they are having with their program it is “I found some code on the internet…”. If you make the effort to write the code yourself then you have a much better chance of understanding what went wrong. Having said that, don’t be afraid to look at the work of others and get ideas from it. In that context I recommend  CodeProject and StackOverflow – but remember that these are for proper programmers.
  • Remember that this is supposed to be fun. If you are doing something that seems to be a bit of a grind, find a way of making life easier for yourself. Simplify the problem or use your computer skills to make a tool that will help with the work.

Programming Humans with Evil Squash

Main Board Hi Res

I’m gaining a new respect for board game designers. It turns out to be quite difficult to create rules for the games that are unambiguous and easy to understand. Even what I thought was a simple game, Evil Squash, has turned out to have some nasty edge conditions that we have had to think quite hard about.

Of course, a game design is really a “program for humans”. It is a sequence of instructions that involve the processing of data, with decisions and outcomes. The tricky part is that the rules are written in English, which is a language in which it is very hard to make yourself completely clear.

Perhaps as an introduction to programming we could get a bunch of people to design the rules for a game of some kind, and then “debug” it by playing the game. I’m certainly going to invent a new “imaginary” game for each first year programming course from now on, just exploring the rules and getting students to think about how they work has given a nice new dimension to the coursework.

You can find out more about the game itself at www.evilsquash.com.

The Best Way to Write Programs

Main Board Hi Res

So, how would you represent the arrows?

The Software Development for the First Year C# Programming course this year is a game I have invented. I’ve called it Evil Squash. It even has its own web site:

www.evilsquash.com

The game is very like Snakes and Ladders, but with a twist that makes it a bit like Ludo as well. At the moment we are working on the player movement, which uses a board like the one above. When a player lands on the tail of an arrow they must then follow it to the destination. We have decided that there are three ways that you can implement this behaviour.

  • A whole bunch of conditions that hard wires the arrows into the program
  • An array with a location for each square that provides a redirection to the destination square.
  • An array of “redirects” that holds the behaviour of the 10 arrows

You might want to consider which is the “best” one. To me, the answer is “you can’t say”. Each of them has advantages and disadvantages. Some of them use less memory, some go quicker. Some are easier to test and some are easier to understand.

One of the things that we try very hard to do in the programming course is to get people to think that often there is no “best” way to solve a problem, merely ones that are better than others against certain criteria. We give extra marks to students who manage to use arrays (I’ve nothing against hard wiring the arrows, but I thing showing you can use an array is something that should be rewarded).

Next week we are going to get the player and the “Evil Squash” behaviour sorted, on the way to making a complete game and maybe even some AI powered opponents.

I’m keeping the domain in case we get some good ones (maybe even phone based) that we might want to distribute.

The Return of Three Thing Game

robmiles.com

We are running another Three Thing Game development at the end of October. These are open to any Hull University students who fancy having a go at some intense game development.

The "things" will be assigned to the teams on Monday 24th of October, with an overnight development session from 29th to 30th of October. We even get an extra hour thanks to the move from BST to GMT, which might prove crucial.

Registration is open now, you can find a registration form here.

We are searching out some bumper prizes for the winning team.

When Clouds go Bad

Victoria Dock

I’ve been a fan of Dropbox and Live Mesh for a few years now. I pride myself that I can work anywhere, and if my computer breaks or I get a new one I can just attach to the shared directories out there on the network and carry on. No worries about backups or version control, just messages every now and then that files have been updated. Live Mesh is better because you get more storage. Dropbox is better because it keeps track of versions. Both seem to coexist on the same machine with no problems and life has been good. Until now. We have been keeping all our content for the Mango Jump Start (sign up – you’ll love it) up in the cloud. This has been great for collaboration and instant access to the latest versions.

But then weird things stated happening. Files would vanish and older versions reappear. Worse yet, and this happened this morning, both the Live Mesh and the Dropbox versions of some files completely disappeared. Wah. It reached the point where I had to go home, find my desktop machine, unplug it from the network, start it up, and make backup copies of the missing files before they were “synchronised” into oblivion. I’ve no idea why any of this happened or what is to blame. All I know is that, like anything else, if you rely on something to be there all the time, sometimes it won’t be. This means that the sad message is that while cloud storage is wonderful and lets you work anywhere, you can’t beat a good backup. I’m now going to copy from my synchronised folders to another place on the disk (or perhaps a different disk) every now and then. Just because nothing is perfect.

Oh, and a note to students. The line “The cloud ate my homework”, while more original than one involving a dog, will still not get you an extension.

What’s Wrong with this Picture Answer

image

Why is this stoopid?

There is nothing wrong with letting you run the program from the last successful build. Perhaps you want to quickly show somebody what your program looks like, but you are in the middle of editing it. In this case you just click Yes and that person can see your program running, even though it won’t build at the moment.

The problem for me (as some of you have already spotted) is the nasty “Do not show this dialog again.” check box. If you check that it means that Visual Studio will always run your last successful build without giving you a message. The scenario where this bites you is as follows:

  1. Run program, notice an error.
  2. Edit source code, fix error but forget to type semi-colon, leading to a compilation error.
  3. Run program again to see if error has been fixed. Program fails to compile, so Visual Studio runs the old old version without telling you. The error appears to be still there.
  4. Go nuts trying to find the error that you have already fixed. Every change you make has no effect. Give up programming and become a beekeeper.

An experienced programmer will be looking out for compiler errors and will know that they are running old code. But not everyone will. You can get a similar effect by working on the wrong source file. In that case you got the fix right, but a file somewhere else is being used in the build. If I suspect a “reality fault” like this I do something that is guaranteed to break the build:

wobble;

This should not compile and run. If it does, something else is happening. If you want to put this back to how it should be (in my opinion) you can go to Visual Studio Tools>Options and find the following entry:

image

Change “Launch old version” to “Prompt to launch”.

image

If you want to get rid of the dialog box completely, and never have the program run when it won’t build, change it to “Do not launch”.

I’ve been racking my brains as to why you would want to hide the dialog box and always run the old version. To be honest, I can’t think of a reason why you’d want to do this, and I’d be a bit happier if the folks at Visual Studio hadn’t.

Poolside Programming with the C# Yellow Book

df5jg[1]mc6oc[2]

Russell, who has signed up to be in our First Year starting in September, shows how he is getting ahead of the game by taking the C# Yellow Book for some poolside programming in Fuerteventura. Good stuff.

It seems that the Yellow Book is looking a little pasty this year. I was going for an artistic shade reminiscent of dappled sunlight through tall tress in spring. Unfortunately I got muddy white. But don’t worry, the next Yellow Book is going to be the yellowist yellow you have ever seen. I’m presently working on updates for the content. Remember that you can get your own, completely free, PDF version of the book from www.csharpcourse.com I’ll put the new version up when I send it to the printers for copies for next year.

TouchStudio for Windows Phone

image

If you want to create programs on your Windows Phone 7 device you can of course use the delightful Iron7 implementation of Ruby. This works startlingly well, but using it you are painfully reminded of the fact that mobile phones are best suited for consuming programs, not creating them.

TouchStudio is a project from Microsoft Research that aims to change that a bit. It has been designed from the ground up to work with a touch interface, rather than in spite of it. The commands and the syntax of the language have been created to make it easy and engaging to write applications for the phone, on the phone. There is a nice paper that sets out how it works here here and the project web site here. If you search Windows Phone Marketplace for TouchStudio you can download the latest version for free.

The programming model is easy to pick up, although the language syntax is different from ones you might have seen before. I don’t see this as a bad thing actually, I reckon that programmers should be used to the idea of using different types of language. What makes it stand out for me is the ease with which you can create stuff, and the level of integration they have with the phone. You can work with pictures, maps, music and even set up phone calls from within the language. The web integration is very good, in around 10 minutes I had a program that would fetch my Xbox avatar, convert it to black and white, display it and then save it as a picture on my phone:

My first TouchStudio program

I need to do a bit of scaling and tidying up, but the program itself is simple enough:

action AvatarDisplay() : Nothing { 
  pic := web->download_picture('http://avatar.xboxlive.com/avatar/rob the bloke/avatar-body.png'); 
  pic->desaturate; 
  pic->post_to_wall; 
  wall->screenshot->save_to_library; 
}

There are also a bunch of built in programs that play games or even do some simple image processing. This is what one of “\themify Picture” did to one of my photos:

Touch Studio Dalek

If you want to while away some time with your phone and actually achieve something fun and maybe even useful, you should grab a copy and have a play.

Making Great Games

100 Camera in 1

I’ve spent pretty much the entire day marking. I’m now giving grades to everything I see. I’ve been impressed with what our students have been getting up to this year, it always surprises me how many different takes you can get on the same problem. This year we were making Breakout. Many of the games that they made were good enough to go to market. Some have had really poor presentation but fantastic gameplay. Others went the other way, with lovely graphics but nothing worth playing. Some thoughts for game writers:

Get someone else to play. You might spend so much time admiring your scrolly graphics and particle effects that you forget that it has to be fun. Get other folks to play. You know you are on a winner when you find people playing who become better at your game than you are. And won’t let you back onto the machine to work on it.

Embrace serendipity. Some of the games had really strange collision behaviour that I’m sure wasn’t intentional. Their ball careered through bricks in really odd ways. However, this made the gameplay much more interesting than some of the better behaved ones. If this sounds like some folks got more marks for writing imperfect code I must add at this point we weren’t marking gameplay as such, this was strictly a programming exercise. But it did bring home to me that if something strange happens you should investigate what is going on and not always fix it. Sometimes these things make good features.

Give the player control. Some games had fantastic graphics, sound, etc etc but the ball always bounced the same way off the paddle. Boring. Other games had very poor graphics but amazing ball and paddle interaction that really let you aim at things on the screen. Much more fun. Consider what happens at your average game of table tennis in real life. Not much happening graphically, but a fantastic range of shots available from a simple ball and bat combination.

Put the graphics on after the gameplay is sorted. In real life game developers often use empty “placeholder” graphics when building the game. This forces them to think about gameplay first. No amount of graphics will compensate for poor gameplay. So get the gameplay right before anything else, and then use the graphics to add value afterwards.

Enjoy your games. I got the feeling from many of the games that the students had really enjoyed writing them. There were little touches and flourishes that you would only add if you were really having fun writing the code. This is great, and just how it should be.

Static on the Radio

HypnoCube2

I was doing a C# revision lecture yesterday and I was talking about static class members. I mentioned the fact that every year some students write “Static means that the value of the variable cannot be changed” in the exam, which produces an anguished cry from me and zero marks. I was trying to think of a better way to explain what static really means. And I thought about the radio. If you turn on your am radio and tune it away from a station you will hear static. And that static hiss is always there. It has been there since before radios were invented and it will be there until the universe cools right down. Static class members are a bit like this. They are always there. They exist whether you make an instance of the class or not. Static in this situation doesn’t mean “can’t change” it means “always there”.

We use them in programs when we want a data member that is part of a class but not part of each instance. For example, in a bank we might have loads of accounts, but the minimum amount you can withdraw, the maximum size of the balance we can have and the minimum age for an account holder are all relevant to accounts, but not stored in each account instance. Static works well in this situation.