Tuesday, December 16, 2008

Heroes and relativity

I don't want to make this a theme, but I really feel like complaining about Heroes right now.

If you haven't seen last night's episode (Season 3 Episode 13 - Dual), then you might not want to read this. I'll try to keep spoilers to a minimum, but I need to spoil a little bit to get my point across.

Last night's episode wasn't bad, but their physics were horrible. I am always more than willing to suspend my belief for a good story. I love the super powers--flight, time travel, all that weird stuff Sylar and Peter can do, etc.. If you're going to explain how the powers work though, at least tell us something acceptable. Maybe Daphne's ability is related to time. Maybe she can move really fast because she's really just slowing time down. Maybe when coupled with Ando's new power she can manipulate time even better and is able to travel back and forth through time.

Don't feed us a bunch of crap about how she can travel through time because she runs so fast that she can travel through time. The theory of relativity doesn't work that way, so don't tell us that it does. Find some other way to tell the story. You can let Daphne time travel without lying to us about physics.

Here's to a new season of Heroes. May it be better than the last couple of seasons.

Wednesday, December 10, 2008

Maze generation in Python

When I was in school, I created (as an assignment) a program that created mazes and allowed the user to run through it in 3D. I used a recursive backtracking algorithm to create the maze. While this isn't a bad way to do it, I wanted to try implementing a different solution in python.

Enter Kruskal. Kruskal's algorithm is an algorithm used to find a minimum spanning tree for a graph. If this doesn't sound like a good way to build a maze, just hang on. I'm getting there. A lot of the time, the most difficult part of applying an algorithm to a problem is fitting it into some sort of data structure. A maze makes a perfect graph--every square is a node in the graph. Every square that is not separated by a wall is connected.

For more details on graph theory or Kruskal's algorithm, Wikipedia is your friend.

Back to the point: I love how simple the python implementation is.


width, height = 20, 20

# create a list of all walls
# (all connections between squares in the maze)
# add all of the vertical walls into the list
walls = [(x,y,x+1,y)
for x in range(width-1)
for y in range(height)]
# add all of the horizontal walls into the list
walls.extend([(x,y,x,y+1)
for x in range(width)
for y in range(height-1)])

# create a set for each square in the maze
cell_sets = [set([(x,y)])
for x in range(width)
for y in range(height)]

# in Kruskal's algorithm, the walls need to be
# visited in order of weight
# since we want a random maze, we will shuffle
# it and pretend that they are sorted by weight
walls_copy = walls[:]
random.shuffle(walls_copy)

for wall in walls_copy:
set_a = None
set_b = None

# find the sets that contain the squares
# that are connected by the wall
for s in cell_sets:
if (wall[0], wall[1]) in s:
set_a = s
if (wall[2], wall[3]) in s:
set_b = s

# if the two squares are in separate sets,
# then combine the sets and remove the
# wall that connected them
if set_a is not set_b:
cell_sets.remove(set_a)
cell_sets.remove(set_b)
cell_sets.append(set_a.union(set_b))
walls.remove(wall)


I'm sure there are things here that could be improved, but I really like the way Python works. If I were to implement this in C++, it might run faster (not that it needs to, the mazes are generated fast enough in Python) but it would take a lot longer to write and would end up with a lot more code.

Tuesday, December 09, 2008

Wall-E is bad science fiction

I should go ahead and write this down before I try searching about it on google, because I'm pretty sure that somebody else has already written something very similar.

I realize that Wall-E is intended for kids. I don't care. It doesn't work. I don't even care about the political agenda they are trying to push. Go ahead and push it, but at least make a few details plausible.

Even if it is possible for the earth to become that polluted and devastated, at least give some reason on how that could have happened. I just can't believe that people would be able to create that much waste without realizing that there was a problem and doing something about it. In addition, it seemed that most of the garbage was some form of metal. It would probably be easier to melt it down and reuse it than it would be to mine fresh ore out of the earth.

How could a seed have possibly sprouted on an earth that had been barren for 700 years? Where did it come from? If by some miracle a seed had been able to survive and still be viable after 700 years of crop withering weather, how could it have started growing? I didn't see any water, and it didn't get any sun--it was growing on the inside of a refrigerator.

The people kept having children for 700 years, even though they didn't seem to ever talk to each other in person or ever touch each other. The only thing that I can think of is that the robots harvest the seeds and grow the babies in tubes somewhere.

When the people (with major bone density loss) return to earth, they are able to walk with no problems, even though they have never walked in their lives. They never even walked in space. They were completely helpless if they ever even fell out of their chairs.

On earth, the plant was re-planted. Somehow, this plant, which was discovered on earth, was able to turn into millions of plants. It was able to cover the entire earth. Not only was it able to cover the entire earth, it was able to grow an endless variety of plants. I also saw, during the credits, birds, animals, and fish. This was not some remnant of earth life that somehow survived the 700 lifeless years. The flora and fauna came from nowhere.

I take umbrage. Please, please, if you are going to make science fiction movies, at least make them a tiny bit plausible.