Thursday, July 26, 2007

Blog Moved

This blog has moved to FuzzyWorld.WordPress.com

Please update your bookmarks or RSS feeds.

Expand...

Monday, July 23, 2007

Function pointers

Here's a brief example of how to do function pointers in C++ and C#.
The functionality is the same in both examples: either the minimum or the maximum of two numbers is returned by MinOrMax, depending on a bool that is passed in along with the int's.

C++

int Min(int a,int b);
int Max(int a,int b);
int MinOrMax(int a, int b, bool findMin);

int Min(int a, int b)
{
    return (a < b) ? a : b;
}

int Max(int a, int b)
{
    return (a > b) ? a : b;
}

int MinOrMax(int a, int b, bool findMin)
{
    int (*MIN_MAX)(int,int);

    if (findMin)
    {
        MIN_MAX = &Min;
    }
    else
    {
        MIN_MAX = &Max;
    }

    int ret = (*MIN_MAX)(a, b);
    return ret;
}

int main()
{
    cout<<"Min(1,2) = "<<MinOrMax(1, 2, true)<<endl;
    cout<<"Max(1,2) = "<<MinOrMax(1, 2, false)<<endl;

    return 0;
}

C#

delegate int MIN_MAX(int a, int b);

static int MinOrMax(int a, int b, bool findMin)
{
    MIN_MAX v;

    if (findMin)
    {
        v = new MIN_MAX(Min);
    }
    else
    {
        v = new MIN_MAX(Max);
    }

    int ret = v(a,b);
    return ret;
}

static int Min(int a, int b)
{
    return (a < b) ? a : b
}
static int Max(int a, int b)
{
    return (a > b) ? a : b;
}

static void Main()
{
    MessageBox.Show("Min(1,2) = " +
        MinOrMax(1, 2, true));
    MessageBox.Show("Max(1,2) = " +
        MinOrMax(1, 2, false));
}

Expand...

Wednesday, July 18, 2007

Hope springs... illogical

Fai: if hope is eternal, what is there left when there is no hope?
fuzzy: who said that hope is eternal? i don't even know what that means.
Fai: it is said hope springs eternal
fuzzy: right, what does that mean?
Fai: it means hope never dies
fuzzy: but it does, in some cases. like if i keep hoping that i'll see my dog by the end of the week, and then next week starts, then that hope has died, because it has happened and won't happen.
Fai: it didn't die, it simply passed
fuzzy: *because it hasn't happened
fuzzy: what if it did die?
Fai: it can't
fuzzy: or are you saying that hope never dies, but is simply reused for other purposes?
Fai: it has no physical limitations, there is no need to reuse it
fuzzy: once the week ends, and i haven't seen my dog, hope is gone. that's it. i hoped to see him this week, i didn't, hope is gone.
Fai: why is it gone? merely becase you do not dare hope that time can be reversed
fuzzy: hahaha
Fai: :D
fuzzy: hope is never gone, as long as we pretend that our universe is based on fairy-tale rules
Fai: sure

Expand...

Fuzzy!



Click the picture for the regular-sized image.

Expand...

Friday, July 13, 2007

Bowling and more

Last week I was back in Chicago and had my fair share of adventures. Oh, where to begin? Well, first things first: I got to bowl with Bill. Yes, Bill. That Bill. Gates. Yes, I think we understand each other. You know, I was expecting that Bill would be quite a good player, but he's... well, he sort of sucks. Which is weird, especially for a guy who has two bowling alleys in his home. I kid you not, he has two: one upstairs, one downstairs. Freaking hell! And he still sucks. What does that tell you? It tells me that this man should spend more time bowling than helping out the poor. But that's neither here nor there.

So, there we are, 7th frame, so far we are neck and neck, all strikes. Just then Bill makes his biggest mistake and gets 9 pins on his first throw. I thought he was going to pop. I haven't seen him this angry since that Blue Screen of Death he got during the live demo of Windows 98. On the next throw Bill must have remembered that Blue Screen of Death: he rolled a gutter ball. You have not known fear until you came that close to beating a billionaire nerd at bowling, I had to consider my next move very carefully. I hit 9 pins. Bill leveled those Wal-Mart frames on me and my life flashed before my eyes. Wow, how boring. Before I knew what had happened, I found myself standing in front of the lane, watching a ball recede into the distance. I closed my eyes and concentrated on what I hoped was a latent telekinetic ability. With all my might, I willed that damn ball to- I heard a hit. That's it, my life is forfeit. Would I be offered my favorite meal and a knife? Bill probably watched his fair share of samurai movies, seppuku is quite likely. After what seemed like eternity, I opened my eyes. Bill was beaming. He was quite happy for my success, to have continued where he himself has fallen. Long story short, I got 279, he got 267. I was never happier to get such a low score.

If this was all that happened to me that night, I think we would both agree that it was indeed a waste of energy to have woken up that day. But no, there was more.

Combined with the fact that this particular Chicago bowling alley hosted a game with Bill Gates, they were at the time also playing host to one of the biggest ping-pong tournaments in the world. Literally. The bowling alley was hosting the National Fat Guy Table Tennis Tournament.

You've probably got a fair idea of what a table tennis tournament is. In one word, it can be described as 'boring'. In two words it can be described as 'meh, OK'. But the Fat Guy Tournament is a sight to behold!

The rules of the Fat Guy Tourney are similar to those of regular table tennis, but due to the fact that the players are rather large, new rules are added to take advantage of the fat guys' natural gravitational field. See, fat guys are so massive that they posses a quite powerful gravitational field which, while mostly insignificant in everyday life, does quite a number on such a small object as a ping-pong ball. These gravitational fields can be utilized to produce never-before-seen maneuvers that, frankly, lesser players are simply incapable of replicating. Even if a player misses the ball, he can attempt to catch it in his gravity well and continue playing. While the rules do state that ball-body contact is equivalent to ball-table contact, in reference to the number of contacts allowed, and the ball may not come to rest on the body of the player, there is no rule against using the body's gravity to move the ball in complex orbits. In fact, body orbits are a basic necessity in the higher rungs of the tournament between strong players: it is nearly impossible to win a game if the player is not capable of performing at least a 1080 (3 complete orbits of the ball around the player).

At the tournament I observed games in three categories: Tier 1, Tier 2 and Tier 3. Tier 3 held the lower-ranked players, while Tier 1 held the higher-ranked players. But player skill is not the only difference between the tiers. Tier 3 games were very similar in style to regular table tennis matches, with the obvious addition of the basic gravitational rules, but Tier 2 games added atmospheric effects to the mix: players are allowed to establish an atmosphere around themselves to help them. Fat guys are so massive that, in addition to affecting a ping-pong ball's motion, they are capable of having a thin atmosphere around them. At Tier 2 this atmosphere may consist of several heavy (non-toxic) gases as well as a slew of particles. The most widely used one was chalk dust. I was told that this is due to some inherent property of chalk, but I don't remember the details. During the game, this thin layer of atmosphere can act as a brake for the ball. Chalk dust increases the effect, while at the same time adding a spin to the ball. In addition to allowing various combinations of small particles in the atmosphere, the rules state that the player may establish a medium-scale weather system. I did observe slight winds around Tier 2 players, but the rules also put a limit on the speed of wind, which must be kept under a specific threshold. The rule about the weather system really only shines when applied to Tier 1 players, so I suspect that the reason the rule is in effect for Tier 2 players is that, given an atmosphere, weather around fat guys is all but unavoidable.

Tier 1 games is the main reason I chose to even blog about this event. They are spectacular! The skill, the orbits, the hurricanes, everything about the sport comes to a head when such powerful opponents face off. First off, yes, I said hurricanes. Tier 1 games do not have an imposed weather limitations, so a number of players develop devastating weather system around themselves to help in the game. I myself witnessed about three or four hurricanes, two small twisters and, what the announcers and fans all over the world have dubbed it, The Great Blue Spot. The Great Blue Spot is an atmospheric phenomenon that gets its name from Jupiter's Great Red Spot, a storm on that planet that is so large, it is capable of swallowing the Earth, and has lasted at least two centuries, and possibly quite longer. The Great Blue Spot is a hurricane in the atmosphere of the player known as Jove (English form of the name Jupiter), one of the best representatives of the sport. I was told that this hurricane is nearly four years old. It is blue because of the secret dyes Jove uses to intimidate his opponents. A somewhat dubious source also stated that the Blue Spot has swallowed more than 100 ping-pong balls during its lifetime, but obviously I have doubts about this figure.

Physics figures greatly into the sport: players use intuitive physics to predict orbits. I say intuitive because that is exactly what the players must do, develop intuition for the physics of the game, as using a good ol' TI-86 is a bit out of the question. After all, the player might drop it, and then what? Well, then they're pretty much shafted. Well, moving on. In Tier 2 and Tier 3 games, the better intuitive physicist has an upper hand on his opponent. In Tier 1 games, there's a bit of a twist: there are a number of fat guys moving around the players and the table. Their movements are semi-random and their weight is a closely-held secret, at least for the duration of the game. These fat guys represent an added random element, a way to throw the players off-balance and make the game even more challenging. There are usually five to seven fat guys moving around the table in different directions and at different speeds. Their motions are decided prior to the start of the tournament and they are communicated this information through radio linkups. As I said, the motions of the periphery fat guys is semi-random: the random movements are decided almost exclusive by a computer. 'Almost exclusively'. There is one event in every Tier 1 game that is decided by a person, usually one of the judges, beforehand, and that event is called the eclipse. The eclipse is an event, which happens once during a game, when the periphery fat guys are oriented into a line. This 'fat guy eclipse' has the potential for very strong forces on the ball, and on some occasions has been decided the outcome of the game. It is a random occurrence, so one cannot prepare for it, but the strongest players are able to use the eclipse to their advantage from almost any state of the game. I myself witnessed an eclipse occur while Titan (a powerful player from Oregon) was passing the ball to his opponent: the ball literally froze in the air before flying back toward Titan. All seemed lost. While a lesser player would surely have lost his cool, Titan used the sudden acceleration of the ball (due to the eclipse) combined with his own gravity to pull off the slingshot maneuver, forcing the ball to orbit his body and releasing it at the apogee (the farthest point in the orbit) where the force of the eclipse had by this time died down. As a result, the ping-pong ball slammed into Titan's opponent, a wiry New Yorker calling himself Sfinx, and broke, folding in on itself. Titan won the game!

Some would ask if random motion of fat guys is really a viable randomizer. While it is conceivable that a Rain Man-like player may be able to compute the changing conditions and take advantage of the situation, the penalty for cheating is immediate and permanent ban from all tournaments and events. So far, there have been no instances of the application of this rule.

The National Fat Guy Table Tennis Tournament is one of the wonders of the modern world and I urge everyone to try and attend a game if there is one near you. You will not be sorry!

Expand...

GamrChat humor

Expand...

Blog quirkiness

There are some issues with the blog as it now stands, the most obvious of which is the damn 'Expand' link on every single post. I'll try and work on that over the weekend. Damn scripts!

Expand...

House on YouTube

What the hell is wrong with 'House' fans on YouTube?! Do a search for 'house md' (here's a link) and all you will find are music videos. That is, clips from the show spliced together with a soundtrack. That's all. There is a very small number of actual 'House' clips, something that I can watch in the background and have a small laugh while working on this damn bug. Argh!

Expand...

Thursday, July 12, 2007

Burnout Paradise

A new racing game is coming to the PS3 and the 360 that will use both systems' cameras in an unusual (and possibly dangerous) way: the cameras will snap a picture of your opponents when they crash, so you can see the torment you bring to other people's lives. Fun! Oh, and these pictures are immortalized on your hard-drive, so you can sneak a peak at your opponent's 'damn, my freaking engine just tore a hole in the car' pics. No, that's not creepy. Of course, the problem with this is obvious: instead of the camera actually pointing at myself, I'll train it on a picture of Will Ferell's portrayal of Janet Reno. Guaranteed to give nightmares!

Expand...

Die Hard 4

Below is the review of 'Live Free or Die Hard', the 4th 'Die Hard' film. The whole review, as well as my overall rating of the movie, is major spoiler-territory. Click expand if you've seen the movie or don't care about me spoiling it.



So, first off, I give this film an A-. It's good on its own, but somehow not up to par with the rest of the series.

Now, let's start with what the film did right. The action scenes are phenomenal, McClane is back, kicking ass and taking names (or not even stopping to take names). The characters are great: John is the no-nonsense cop we've come to love, Lucy is a tough cookie, the bad guy is determined and scary and the henchmen come in a variety of flavors, ranging from Red Shirts to the jaw-dropping Mai and the parkour-trained Rand. The ensemble of actors also impressed me, as the producers didn't just use no-names to fill the smaller roles of the government officials. Kevin Smith's presence sort of surprised me, but the character wasn't a throw-away cameo, for which I'm grateful.

The computer hacks weren't all idiotic Hollywood-esque plot devices with no real-world basis. Sure, there were a few points that made me cringe, but nowhere near as many as there could be. For truly cringe-worthy technobable and a disgusting portrayal of technology, see 'Man of the Year'. Which is probably one of the very few reasons to see that movie. Moving on.

Of course, the overall production style and the Michael Bay-inspired action sequences and camera angles deserve a mention and a few extra points: the action scenes were very well done, taking the camera incredibly close to the action in some shots and doing wonderful long views in others. In particular, I enjoyed the overhead views of the helicopter flying around DC area as, almost outside the viewing area, we can see the car collisions that were just then triggered by the bad guys.

Of course, and this is a really big point, the rating of the film is increased by the subject matter. I am sick and tired of bad guys claiming to be patriots and "serving the interest of the country". This has been claimed by every hack Bad Guy in recent history: every season of '24' presents us with yet another white man behind the curtains who claims to love this country so much that he is willing to place millions of Americans at risk to protect them. Somehow, that makes sense to the writers. Whatever. The bad guy in the film is a similarly-themed patriot who is doing the country a favor, but the difference here is that what he is doing makes sense, on some level. While I may not agree 100% on the methods used, I must say that I see eye to eye with him on the underlying problem: America has not learned anything in the past 6 years. 9/11 caught the country with its pants down, and nothing has changed since. Katrina was, by definition, a clusterfuck. The federal systems in place for dealing with disasters, be they natural or man-made, are ineffective and incapable of preventing or dealing with anything other than a cat stuck in a tree. (My "favorite" example of the system in action is the foiling of the 2007 Fort Dix terrorist "plot": the government caught on to the plot after the idiots went to Circuit City to turn their training tapes into DVD's and an employee forwarded the tape to the feds.) The systems in place are overgrown, immobile, red-tape covered, outdated dinosaurs. I agree that a shakeup is what is needed. Certainly not as extreme as shutting down the entire country, but at least they're acknowledging that the problem exists.

Now, on to the bad. The worst thing about the film is that it takes so long to get started and doesn't maintain the pace consistently. There are great action sequences, but they are spread out, and in between them is slow chatter that attempts to explain the plot and character motivations. Boring!

The music is also a let-down: I didn't notice any of the scores from the first three movies popping up. What happened to the good ol' 'Die Hard' music? I miss it. That, and McClane's hair, but I can forgive that, somewhat.

Actually, that's it for the bad. As long as you can stay awake through the parts of the film that aren't filled with gunfire, you'll be set.

Oh, I forgot something: this movie is rated PG-13. Yeah, go figure, a 'Die Hard' film that's not R. But they pulled it off. I think it was through bribery. There is a lot of profanity in the film, and even two times when McClane drops the f-bomb, but in those instances there is too much gunfire to make the words out clearly. This is a bit of a detriment, but not seriously. Even if the film loses the sailor language of the first three movies, it still has enough and doesn't resort to idiotic replacements like 'gosh darn it'. That would have made me a very sad panda.

That's all for now. Watch the movie, it's good.

Expand...

Wednesday, July 11, 2007

Mass Effect

There's all this hype about upcoming games: we know of a game a year before it comes out; we salivate over every single frame of the rare in-game animations the companies toss our ways; we are waiting for more games to come out than we are currently playing. The whole tires me out. And yet I can do nothing but salivate more and more as I watch this damn trailer: http://kotaku.com/gaming/clips/mass-effect-trailer-starring-keith-david-277058.php

Oh, Keith David, you're dreamy. In that this-guy-has-a-scary-voice way. Yay.

Expand...

Wednesday, July 04, 2007

Determinism

It has been far too long since my last blog post. And far too long since I've had a rant. I probably won't start with one, but I do hope to have one in the next few whatevers.

So, this first entry that have written in quite a long time, will be focused on determinism. Why? Why such a boring topic when I could rant about religious fundamentalists, cheese parties or the cutest dog in the world? Because that is what I will do. It is my fate, my destiny. Also, I've been thinking about this issue for a while and it seems best to put down my words and concepts before I move on to other things.

First, what is determinism and why do we care? To explain determinism, and much of what is to follow, I will use examples. To begin, let's consider an introductory-physics problem: two objects are moving along a plane, collide and bounce off, moving in new directions at new speeds. Determinism is this: a person not of the system, an outside observer, can look at this experiment at a point in time before the objects collide and can predict exactly what will happen in the future. Namely, the observer knows at what time the collision will occur and the resulting velocities of the two objects. That is determinism: objects of a system following a set of rules. Since there exist rules and things don't just happen at random, the future state of the system can be predicted if the current state is known.

Now, let's introduce another concept. I call it 'reverse determinism'. I'm not sure if there's a different name that older and wiser thinkers before me have come up with, but this is what I will call it. Reverse determinism is just that: ability by an outside observer to observe a system and accurately describe a previous state. Extending our above example, an observer can look at the system at a time after the objects have collided and be able to exactly calculate where the object originated and where the collision took place.

What's the point? Stop asking me that, if I knew the answer to that particular question, I imagine life would be much easier.

Now, let's look at our world, which is a hugely complicated system about which we know very little, and other comparable, but infinitely simpler, systems. First, let's consider a basic physics environment: a few objects moving on a frictionless plane. This is a very simple example, one that can be determined both forwards and backwards by a half-way competent physics student. The second example is Conway' Game of Life. This system is even simpler than the previous one: cells, or colonies, or whatever, exist on a grid. If a cell has 2 or 3 neighbors, it lives; any more or less, and the cell dies. If a space on the grid has exactly 3 cells as its neighbors, a new cell is born. You'd be surprised just how complex a system can be made from these simple rules: stable configurations of 'organisms' can be built from groups of cells. Some organisms are gliders, groups that fly diagonally across the playing field, replicators, groups that create exact copies of themselves, and glider factories, groups that go one producing gliders infinitely (or, at least, until interrupted). Some scientists have even devised computers that take input and perform calculation entirely within the Life playing field: they use gliders to communicate. I'm not sure how information is stored, or even if Computer Engineering concepts can be, or need to be, translated. But that's a deviation.

So, we have our three systems (our world, basic physics experiment, Game of Life), let's do some constructive thinkering.

First and foremost, the physics system is both deterministic and reverse deterministic, while the Game of Life is only deterministic. Why? The rules of the Game of Life are such that it is impossible in non-trivial cases to determine the previous state of a given system. Consider a very simple example: a blank board. Who is to say what the previous state was? Was the board empty, or was it just sparsely filled with single- or double-celled groups? All of this information is gone, so there are a large number of possible solutions for any particular state of the system. (The only exception to this is a state of the system termed Garden of Eden: these are configurations that are unattainable through the rules of the system, states that have to be set-up by an external source.)

What does it mean that the physics model is reverse deterministic? Who cares if the Game of Life is not reverse deterministic? I do. I care why one system can be 'wound back', while another can't be. I wonder what a non-deterministic system would look like. Imagine if that system was reverse deterministic. That means that you could reliably 'go back' through events that have already occurred, but going forward, 'Back to the Future', so to speak, is impossible, or perhaps simply inconclusive.

My theory on why the Game of Life is non-reverse deterministic is because of the lack of the conservation of energy (and of course matter): cells disappear into nothingness and are spontaneously born out of it. In the physical model, the two objects collide and change paths, but throughout it all they still remain, both mass and energy of the system staying constant. Even if we were to add friction to our physical model, a seemingly daunting problem to consider, the system still remains reverse-deterministic: friction results in heat, and by knowing exactly the amount of heat an object (in this case the plane and the moving objects) has it is possible to model the spread of heat back to source, giving us an accurate model of just what the state of the system was at some point in the past. The Game of Life lacks this ability to record events. There is no way to know that a cell existed in a particular location, or for how long.

Is our world deterministic? Is it reverse-deterministic? Perhaps.

First, is our world deterministic? If you were asked this question at the beginning of the 20th century, the answer would be a very loud 'yes'. That is, until quantum mechanics came along and spoiled the party. Quantum mechanics opened a dangerous flood-gate: there was no set path for an electron, no specific outcome for a simple interference experiment, the new fashion was chance, the new tool of the scientist was a probability graph. There are higher odds of electrons bouncing off a barrier, but a non-zero chance exists of that same electron passing right through. Poof! goes determinism, burned up like so much tinder in the fire. Granted, the probabilities are such that everyday objects, gargantuan in comparison to electrons, still behave in pre-quantum mechanics ways, but we are now faced with the reality about the most basic building blocks of our universe: no conclusion can be drawn about a future state. (Perhaps, if our world supports reverse-determinism, this is the world I tried to imagine a few paragraphs above.)

However, I do not agree that the universe plays with dice. Consider events in everyday life that can be assigned probabilities: the flip of a coin, tomorrow's rain, the chance of asking for 'a tall mocha, no whip, no lid' and the baristas actually getting an order right. All of these probabilities arise out of one fact: our lack of knowledge about the system in question. If you knew the state of every air molecule in the room and the velocity, both linear and rotational, of the coin, you could accurately predict the outcome of the toss. If you could instantly see the entire atmosphere of the Earth, knowing when and where it will rain will be a trivial task. Probabilities arise out of our lack of information. It is therefore possible that our current understanding of quantum mechanics as being a probability-driven field is based only on our sparse and inaccurate description of the universe. If that is indeed the case, quantum mechanics may very well be a deterministic part in the bigger deterministic system. If every part is deterministic, the system as a whole is deterministic.

What's it matter, though? Well, it doesn't. To accurately predict the future, or to look into the past, we must possess all the information about the current state of our world, have a working knowledge of all the underlying rules and a computational device powerful enough to calculate the next state of this monstrous machine. You'd better step outside for that, as well, since your actions will invariably change the outcome.

Expand...