Mobile phone is now my video game platform of choice

I remember being glued to the television screen while barely surviving in most of the role playing video games I played when I was young. It didn’t matter that most of them were in Japanese, because I would still slog through the dialogue and snatch whatever I could understand. Ahh, those were the days…

As I grew up, I still played video games, but less often. I’ve always preferred to play on console machines rather than the computer. For some reason, game playing felt right on consoles. But game playing on consoles required switching on the television, switching on the console machine… yeah, I’m getting lazy, and selective about my games (you know, not enough time)… It just feels like a bit of an effort.

Then I started to use the computer more often, as a result of my university work and programming. Since the computer was already on, the notion of playing games on the computer started to be more appealing. But I only really play The Sims. Using the keyboard and mouse to play action games felt awkward for me, but the point-and-click-with-no-rush system of The Sims was ok.

But even that sort of died… the loading time was terrible, I had to save… starting up and ending the game still felt like effort…

Then I bought my iPhone.

Now, I own a handheld console (a DS since you asked), though I don’t play very often. The games aren’t “motivating” me enough. Plus the screen is small, and I still have to start it up to play games.

My iPhone, on the other hand, is different. I keep it switched on when I’m awake. That means, if I want to play a game, I just need to load up the game, which is fairly fast. I’m not isolating the iPhone here. Any mobile phone with gaming capabilities fit into the criteria (but I’m kinda invested with the Apple product… not a fanatic, but just reluctant to change phones in general. You know, I’m just obeying Newton’s first law).

When I want to play a game on my phone, I just start the game up. I don’t have to switch on the phone because it’s already switched on. The start up and closing times are (usually) fast. The games don’t need saving, or saves fast, or saves in a way you don’t notice (like on closing). My only concerns are the small screen, and whether I like the game.

I’m saying all this because applications are about the user. I’ve been looking at the top games from the Apple App Store. They seem to be the type of game where it’s easy to learn, easy to start up, easy to let go. Perfect for the attention-deficit and finicky modern mobile phone user. Compare this to the in-depth role playing games I’ve played in the past, burning through hours of playtime just to gain enough levels so I could at least survive the beginning attacks of the boss fight.

Times have changed…

The Psychotic Line – 3rd dimension of the Real Line

We have the Real Line, from negative infinity on one end to positive infinity on the other. Then we have the Imaginary Line, where we rotate numbers on the Real Line around to obtain imaginary numbers (or complex numbers). So what’s the natural logical progression?

Meet the Psychotic Line, with delusional numbers. As expected, special cases of delusional numbers collapse to either a complex number or real number, by simply setting the delusional component to zero.

The delusional part, j, shall be defined as
j^2 = -i
where i is the unit pure imaginary number.

Thus, j^4 = (-i)^2 = (-1)^2 * i^2 = -1

A typical delusional number is written as
d = a + bi + cj
(d stands for delusional, how coincidentally fortunate!)

Where complex numbers require rotation of 360 degrees to span the full complex plane, delusional numbers only require 180 degrees. Simply study spherical coordinates to understand why (part of the effort is already done by rotation from complex numbers). Once one can leap from the real world to the imaginary world, it takes half the energy to jump to the psychotic world.

One should study the psychotic line, delusional numbers and their properties, for they (possibly) hold the secret to untapped human cerebral abilities, interstellar travel, and maybe even a longer answer to the Ultimate Question of Life, the Universe, and Everything. I wish you luck.

PS: This was written in jest. You’re supposed to laugh.

Comparisons using the eyeball check

Back when I first started working, one of my duties every month was to check reports. Yes, I know it says “Systems Analyst” on my job title then. Thank you for pointing that out. Don’t new staff often take on all sorts of miscellaneous duties like that?

As I was saying, I was to check reports (some financial data was involved). The users would check them of course. We’re just checking them (the report generator program was written by us) before handing the reports to them. Basically, it’s to make sure the numbers tally for the sections that they’re meant to be the same.

Now the reports were PDFs. In order to save paper (and more importantly, not keep so much paper physically), I check them on the computer screen. My colleague taught me a simple trick. Use Alt-Tab.

Open the first report and maximise it on the screen. Open the second report and maximise it on the screen too. Then I Alt-Tab between the 2 reports, flipping rapidly to make sure the numbers were identical, then paging to the next on both report, and so on and so forth.

I’m not understanding the content of the page, I’m using visual recognition. As in that’s not really a zero that’s registering in my brain. More like a slightly vertically elongated circle. I’m not comparing words and numbers. I’m comparing pixels.

PDFs aren’t diff-able (at least not that I know of). And it turns out that comparing PDFs using the eyeball check is exceedingly simple (albeit manual and tedious) with the Alt-Tab trick. It’s like facial recognition. Humans are good at recognising faces. We haven’t gotten computers to do on par though…

P.S. In case you don’t know about Alt-Tab, on Windows (hi Mac user!), when you hold the Alt button and tap the Tab button, the window just before your current window pops up. So I open the first report, then open the second report. The first report is on the window just before the second report’s window. Alt-Tab once to bring the first report into focus, pushing the second report back. Repeated Alt-Tabbing simply cycles between the 2 most “current” of the windows, in our case, the 2 reports.

Unpredictable next moves

I’ve been playing Dungeons & Dragons for a while now, and starting to get the hang of it. This group of friends are, shall we say, very tactics-focused. If you’re a D&D player, you should know what I mean. D&D is a tabletop role playing game, and we just happen to focus on the “tabletop” and “game” part. Nothing wrong with that, and it’s still fun.

Now, these friends are very tactics-focused (I think I said that…), and being the new kid on the block, I want to decide on my moves fast, so that gameplay moves on smoothly for the whole group. The moment my turn ends, I think of what I want to do when my turn comes again.

At first, it was easy. There were few enemies. We were a small group at first (4 players including me and the DM). We were playing low level characters, so we had few powers to select from.

Then we decided to play the higher levels (paragon tier, if you happen to know D&D). And a couple of other players wanted to join. The game was starting to get complex, with a lot of paperwork going on. More players, more powers to choose from, more deadly monsters (the DM had to delegate initiative tracking to another player because he was too busy tracking monster hit points and powers).

There were these power cards that I had, together with the character sheet. Basically, they contained the essential information that power has, such as how to determine hits, damage, and any special effects. At the higher levels, I was holding maybe 30 cards.

This became a problem, because of analysis paralysis. “What do I do now?” was a difficult question to answer. One of my friends gave an amusing solution. He said he’d shuffle the cards in his hands, and then a “I will use this one!”, and randomly picked a card out of the stack.

As we played together, I got used to the tactics used by them. We had teamwork. Yay. Which still didn’t completely solve the problem “What do I do now?” when it’s my turn. I would pick, based on the positions of the enemies and my allies, a power to use that was most advantageous. Which changed, the moment an enemy moved out of my reach, or an ally moved into my planned spot of devastation, or an enemy came after me and practically killed me.

Whatever plans I had was only static when it’s my turn. Which might make all that pre-planning useless. There was this game session where I saw a bunch of monsters grouped together (3, which was a lot, considering the sparsity of monsters in most encounters), and I planned a deadly spell to unleash on the lot of them.

I waited for my turn, keeping track of what my allies were doing, and what the monsters were doing (particularly those 3). And when it was just before my turn, a friend before me teleported right smack into the area I was going to blast. I had to make a quick decision, and ran through my stack of cards to see what else I could do.

He made his attack and was done with his turn. Fortunately, I found something that hurt 2 monsters, thus leaving him unhurt (as well as the lucky third monster). It wasn’t the best choice, but I’d rather not set him ablaze.

With all the available choices and moves of the enemies and allies, it’s hard to foresee how the battle was going, and how I was going to respond. Everything was fairly unpredictable.

The worst thing was, I played the only character with special effects, such as blinding, dazing or moving the enemies. The others had marginal similar effects, but they were mainly the damage dealers. I could best contribute by making the battles harder for the enemies, and easier for my friends. So I was searching for a combination of ok damage, and debilitating effects on my cards. It’s hard.

All this is a long winded way of saying, if you’re designing a user interface, make it as unambiguous as possible. The user do not want choice. You, do not want unpredictable next moves from the user. Unless you planned it, of course.

How long does your program live? Part 2

Ok, it’s been a long time since part 1. I apologise. Frankly speaking, I can’t remember what I wanted to talk about… After much thinking and recalling and tea drinking, it came back to me.

So, problems. I was talking about a family of programs living way longer than its creators at my company in part 1. And that program dealt with financial years. Here’s the thing. Financial years were represented in “pairs” of years and in 2 digit form. Thus we have, say, financial year 09/10, representing April 2009 till March 2010. The previous financial year would be 08/09, representing April 2008 till March 2009.

My problem then was that, this family of programs lived everywhere. There were “09/10” notations in the database tables and views, in the stored procedures, in the Unix shell scripts, and in the C programs. I had a lot of work cut out for me.

My first goal was to get similar C programs to be replaced by just 1 program. Oh you didn’t know? There were programs like foo0809.c, foo0708.c, foo0607.c, and there’s bar0809.c, bar0708.c, bar0607.c … you get the picture. So I wrote a fooXXXX.c to replace all the foo programs, and corresponding C programs for the rest. It was basically a careful search-and-replace operation, together with an additional parameter for the financial year in the main() arguments.

Sometimes, a program generalised to take in parameters is better than several programs doing the same thing but on different database tables. I guess the original programmers didn’t plan enough about the whole structure of the system working together.

Then I did the search-and-replace operation for the shell scripts too. Some of the shell scripts also creates views and database tables for the new financial year, so I had to take care of that. Then came the really nightmarish task of tackling the user interface run entirely by a shell script…

The UI consisted of carefully aligned printed text, and choice options. Much like the choose your own adventure computer games of yore, where you were given a description of the place you’re at, and some choices you could do. This one looked something like:

     Welcome to Program Foo!

Please choose an option:
1) Jump up and shout
2) Do a funny dance
3) Eat a sandwich
4) Point your finger at your most
   hated enemy, and cry
   "Behold the wrath of my fury!"
   fully expecting some sort of
   lightning or fire to erupt on
   the body of said hated enemy.
5) Exit program

Enter your choice :

The fun part of it was that there were different variations of presenting the financial year. Some parts used “fy 09/10”, some used “fy0910”, some used “fy 2009/2010”. Know also that I worked with it where pre-2000 years existed, and some interesting programming calculations were called for… most notable was 1999/2000.

I had to keep, say 2009 in a variable. For the “current” financial year, I would add 1 to it to get 2010, then do substrings on them to get the last two digits and print them to get 0910. (or 09/10 depending). The requirement were such that the latest 5 financial years were to be displayed, so I decided to just precalculate the 5 years on immediately loading the script.

Then there was the special condition. Because the programs dealt with data from the previous month, when executing the main UI script in April 2009, it’s not considered the financial year 2009/2010. It’s still 2008/2009. I only knew this because that senior developer (previously mentioned in part 1) said the UI was one month “early”.

So finally, I was done. The main UI script has options which run either another script or C program. Those child scripts or C programs then ran against the database tables. And all of them used the correct financial years.

That’s it. I’m fairly sure I had a third part in mind for this series… Let me go search my memories…

Learning via osmosis

Sometimes, I read something even if I’m not interested in the subject. It could be a way to pass the time. Or I have to read it due to work. Or I like the author, because I liked what he wrote before.

So I was wondering, do people often read something even if they’re not interested in the subject? I began examining myself for the motivation behind my readings. And I found that I read to learn other things.

The primary reason I have is, if I only read what I’m familiar with, I’ll stagnate. So I read about other topics. I may not actively seek to read about, say spelunking or the collection of coins. But I will read about other topics in passing whenever they come into my attention. There are secondary benefits to this uncoordinated reading. I read to learn the sentence structure, the “voice” of the author, the presentation of ideas.

There is this article on program run time and big-O notation by Raymond Chen. Frankly speaking, I had no idea what he’s talking about the first time I read it. And it’s fairly long. And I still finished reading it. And I still have no, ok fine, marginal understanding of what he’s saying.

Some of the terms made sense. Big-O notation, hashtables, and ternary trees (wow I thought there are only binary trees!). I can’t quite wrap my head around the subject though. I still read it. I guess the secret wish was I’d slowly and eventually learn whatever he’s talking about via osmosis.

You know, knowledge and understanding flowing from a low concentration of stupidity to a higher concentration of stupidity.

This went for another article I read by Scott Adams on investing. I read it to learn about investing from another view point. And because I had nothing to do then, and I read his blog anyway and the article came into my feed reader…

Basically he presented the idea of cutting out the financial professionals managing your investment portfolio. I have little idea and opinions on the subject, so I’ll leave you to interpret however you want.

Maybe this random sampling of subjects is my default mode

Too Fast Too Furious (or instantaneous program run time)

There was this time when a user called me up for help. I recognised the application she needed help on, which I’m maintaining but not very familiar with. For reasons that will be too tedious for me to explain, I couldn’t solve the problem without going to the one computer, which happened to be near my user, that’s running that program. And my user was conveniently located a few floors below mine… I mouthed a silent sigh, and told her I’d be down in a few minutes.

Man in relay race
[image by photosbyjim]

A bit of information on that program first. It’s run once a month, and its purpose is to send a few hundred emails each with an attachment (which is unique to the recipient).

I took my notepad and a pen in case I needed to take down notes, and left for the user’s office. When I arrived, she showed me what she mentioned on the phone. The program ran, but some attachments (and correspondingly some emails) weren’t sent out.

I checked the log file, but there were no error messages, which suggested that the program ran fine. Now the program used a third party DLL to talk to Microsoft Outlook (the email application used), and sends out emails using Outlook. Since the program ran fine (no errors), the only error left would be with that third party DLL or Outlook.

It would be difficult to debug the DLL, so I checked Outlook first. My instincts told me to try sending a test email. It failed. Aha! The error message said something to the effect of “Mailbox full”. I asked the user to archive some of the emails, and she said she didn’t know how. After sighing in my mind, I put on my computer helpdesk hat and proceeded to archive the emails for her.

Then I told her to run the application. She proceeded to go to “Task Scheduler” and I was perplexed, and asked what she’s doing. Turns out that the program was scheduled to run every month on a certain day, and she’s going to reschedule the program to run a few minutes later. The scheduler would run the program a few minutes later, and she would reschedule the program to run at its original schedule. Ai-ya-yai-ya-yai…

Nearing a mental meltdown, I told her as calmly as I could, that she could just double-click on the program to run it.

“Oh really! That should save some time,” she held her hand to her mouth. She went to double-click on the program. And nothing happened. Or so it seemed…

“Nothing happened!” she looked at me.

I went back to Microsoft Outlook, and checked the sent mail folder. Sure enough, the emails to be sent were there. I asked the user to confirm, and she nodded.

“But it’s so fast!” she pointed at the computer screen.

Too slow, and I get complaints. Too fast, and I get complaints. Sometimes, I just can’t win…

Those variables on Bezier curve equations are not fixed

I wrote something on reverse engineering Bezier curves about… *goes to check* woah, 2 years ago! I don’t remember it being that long… (You might want to read that article before proceeding…)

Anyway, I’ve received a few comments and emails about its usefulness. Basically, what I did was to find the 4 control points of a cubic Bezier curve from 4 known points which lie on that Bezier curve. 2 of the known points are to be the end points of the Bezier curve (which automatically makes them control points too). The other 2 known points lie somewhere on the Bezier curve.

Here’s where the confusion sets in. Commenter Yonatan pointed out that there is an infinite number of Bezier curves based on how those 2 known points are defined. And he’s right.

Now, I formed that solution based on the “natural” implicit decision that the 4 points are evenly spread out on the Bezier curve. There is no reason for them to be, and the math never assumed they are. The solution arose from the assumption that the control points were evenly spread out, but in the end, it worked for the general case as well. So long as 0 < u,v < 1 and u not equal to v (and logically speaking, u < v), everything worked fine.

So the whole point of this article is this: u doesn’t have to be 1/3, and v doesn’t have to be 2/3. You are supposed to know or decide what value they take. Once you’ve decided, the other control points will be uniquely determined. Let me illustrate:

Same Bezier curve with different control points

Now the 2 Bezier curves are exactly the same (I would know, I copied and pasted them…). Suppose I define u and v such that f and g lie on certain points on one Bezier curve, and they lie on different other points on the other Bezier curve. What happens is that the control points p1 and p2 are different for the 2 Bezier curves, even though the curves are exactly the same!

Disclaimer: I haven’t worked out an example such that it is true (other than the trivial case of a straight line), that a Bezier curve can be drawn with 2 different sets of control points. As in exactly the same. However, based on the math, I can say that 4 points lying on a Bezier curve can be drawn with 2 different sets of control points. The resulting curves might (actually they should) differ slightly, a twitch of a pixel here, a slight upward gradient there. But the 4 points would be exactly positioned as calculated. It’s meant to be a, what’s the word, sensational example. So there.

I can’t tell you what u and v are, although 1/3 and 2/3 should work fine. I gave you the theory and the solution. It’s up to you to decide how to use it. Depending on your context, you might decide on different values for u and v, which will influence how your control points are calculated.

My original intent was to produce a camera path flying in 3D. I didn’t care about the “correctness” of its path, only that there is one. As such, u=1/3 and v=2/3 worked excellently for me.

You might find that 1/3 and 2/3 don’t work for you. That’s fine. u and v are variables. By definition, they’re not fixed. Choose whatever value works for you. Depending on context, you might even want to come up with a simple formula (based on your situation) to calculate u and v dynamically.

Moving backgrounds, different speeds

Back when I was younger (which is an obtuse way of saying “I haven’t the friggin’ idea exactly when”), I dabbled a bit in game development. There was a period when I was studying side scroller games. Remember those? The classic Super Mario Brothers was one of them.

I also noticed that in some of the games, the backgrounds moved. Yes, backgrounds, plural. I could understand forming a background “tile” made up of hills, clouds, trees, grass, flowers, rocks and whatever suited the game as background. But there was something, else, moving in the (for lack of a better word) background.

There was another background layer, moving at a different speed. Wait. Oh, it’s moving at a slower speed.

When I moved that little sprite (that’s representing my sole means of interacting with the game) on the screen to the right, the flowers and trees and rocks sped past to the left. But that faraway mountain was moving to the left at a slower speed. And the overall effect was a realistic simulation of 3D, a semblance of depth in an essentially 2D game.

Now that I think about it, I have one question. How do you calculate how slow the other background should be? I searched high and low, though I found what this effect is called (parallax scrolling), I found no trace of any suggestion to the relative speeds between the 2 backgrounds.

So I did a little thinking. And drawing. I was trying to work out mathematically the slower speed, given the “distance” between the background layers (there’s practically no distance in implementation. Maybe 0.01 units…) and the speed of the background that’s “in front”.

It didn’t make sense, because no matter how I pivot the movement, the calculations don’t work out.

Parallax scrolling backgrounds

L1 and L2 are the “distances” between the respective layers. d1 and d2 are the distances from the objects in question to the perpendicular line formed by the sprite position. v1 and v2 are the velocities of the respective layers moving to the left (or right, depending on how you view this whole thing and how you define the direction… never mind).

The layers aren’t really separate. There is a tiny distance between the layers, say 0.01 units. If you’re in a fully 2D environment, then the farthest layer is drawn, then the next closest layer is drawn, subject to transparency to allow elements from the farthest layer to be shown, and then the playing layer is drawn (where our sprite and other objects are). There’s no distance (between the layers) to speak of in a true 2D rendering environment.

I started with the “don’t move the focus, move everything else” approach, keeping the sprite in place, and moving both backgrounds to the left. This meant pivoting around the sprite. The objects drawn on the other two layers are what our sprite would see in a straight line towards somewhere forward. Those objects should coincide at the “perpendicular” line together.

Since the distances d1 and d2 are obviously different, therefore the velocity (or speed. I’m just trying to be scientifically correct here) of the two objects moving to the left must be different. There lies my problem. It meant the farthest object had to travel faster, contradicting our original observation.

What if we pivoted around the object in the “front” layer? The sprite moves to the right, and the object on the “back” layer moves to the left, and all three line up in a perpendicular line (perpendicular to the layers anyway). Too troublesome. Same with pivoting around the farthest object.

I toyed with the idea of pivoting around the vanishing point. At this point (no pun intended), I decided to give up.

So I assumed that the background image(s) in the “back” layer are appropriately sized with respect to the “front” layer. I decided a simple ratio probably worked best. Thus we have
v2 = v1 / (L1 + L2)
which should give an appropriately slowed velocity.

And now, finally, I’m telling you this. It might not matter. What matters is that you test the velocities, and if the 2 background layers scroll at a pleasing velocity, then there you have it. Ultimately, we’re just trying to simulate a 3D perspective given a 2D environment. If it’s believable, then that’s the correct velocity.