Thursday, July 14, 2005

Stanislav Petrov

I ran across this link in the wikipedia
(http://en.wikipedia.org/wiki/Stanislav_Petrov).

Having never heard of Stanislav Petrov before or the events of September 26, 1983, I was amazed and grateful for his actions. I'm not sure I would've trusted my intuition that much - I'm glad he did.

Friday, May 27, 2005

Top Grossing Movies Of All Time

I got curious the other day about what are the top grossing movies in the USA. IMDB has a great site and provides just the list I was looking for. However, they state at the bottom that the "figures are not adjusted for inflation". Bummer.

Being the guy I am though (and also that I don't consider Titanic to be all that great of a movie despite it's #1 ranking), I decided to find an inflation calculator and adjust the numbers to see what would turn up. Wow, what a difference!

Here is the top 20 from the original list that is NOT adjusted for inflation. As you can tell, with a few notable exceptions, most all of these movies are from the late 1990's and on. Which makes sense since the price of a ticket has gone through the roof. (not sure why there's a big white space here...scroll down...)























RankTitleYearUnadjusted Sales
1Titanic1997$600,779,824
2Star Wars1977$460,935,665
3Shrek 22004$436,471,036
4E.T. the Extra-Terrestrial1982$434,949,459
5Star Wars: Episode I - The Phantom Menace1999$431,065,444
6Spider-Man2002$403,706,375
7The Lord of the Rings: The Return of the King2003$377,019,252
8Spider-Man 22004$373,377,893
9The Passion of the Christ2004$370,270,943
10Jurassic Park1993$356,784,000
11The Lord of the Rings: The Two Towers2002$340,478,898
12Finding Nemo2003$339,714,367
13Forrest Gump1994$329,691,196
14The Lion King1994$328,423,001
15Harry Potter and the Sorcerer's Stone2001$317,557,891
16The Lord of the Rings: The Fellowship of the Ring2001 $313,837,577
17Star Wars: Episode II - Attack of the Clones2002$310,675,583
18Star Wars: Episode VI - Return of the Jedi1983$309,125,409
19Independence Day1996$306,124,059
20Pirates of the Caribbean: The Curse of the Black Pearl2003$305,388,685


To adjust the figures, I used the Consumer Price Index tables found at ftp://ftp.bls.gov/pub/special.requests/cpi/cpiai.txt. I took the CPI from this year (2005), divided it by the CPI from the year the movie was released and multiplied by the unadjusted amount. If this is the wrong way to do this, somebody please let me know.

Now, here's the list adjusted for inflation. Now we're talking! Classics all the way down the list. And only ONE (Titanic) was released after 1983. In fact, the first movie from the 2000's that enters the list, does so at number 31...and it's Shrek 2...ugh...grossing $443M























RankTitleYearAdjusted Sales
1Gone with the Wind1939$2,744,015,350.79
2Snow White and the Seven Dwarfs1937$2,465,673,133.33
3Star Wars1977$1,460,390,225.74
4Bambi1942$1,210,862,134.97
5The Sound of Music1965$994,829,933.71
6One Hundred and One Dalmatians1961$982,474,916.39
7Jaws1975$927,881,040.89
8The Exorcist1973$884,605,405.41
9E.T. the Extra-Terrestrial1982$865,391,669.72
10The Jungle Book1967$815,388,428.26
11Titanic1997$718,689,882.92
12The Sting1973$690,162,162.16
13Doctor Zhivago1965$680,972,190.48
14Star Wars: Episode V - The Empire Strikes Back1980$676,098,060.58
15Mary Poppins1964$633,600,000.00
16The Godfather1972$619,277,865.65
17The Graduate1967$600,127,053.41
18Star Wars: Episode VI - Return of the Jedi1983$595,904,402.89
19Butch Cassidy and the Sundance Kid1969$535,240,021.80
20Grease1978$534,066,257.67


Just thought this was interesting. Also, if you do the numbers, each successive Star Wars movie has made less and less money when adjusted for inflation:

Star Wars - $1.492B
Empire Strikes Back - $736M
Return of the Jedi - $590M
Episode I - $491M
Episode II - $330M
Episode III - ?? (so far, it's $191M)

I guess this is why I get a little irritated when they say a movie had a "record breaking" weekend. It's only record breaking because a ticket cost $8 now instead of 50 cents (or whatever it cost it 1939). Oh well...it's interesting nonetheless.

Wednesday, January 26, 2005

Accessing Private Fields

I had read an article about unit testing private methods. As the article states, there are several approaches to this and also several reasons why you should consider NOT doing it (such as considering your design more carefully and testing public methods will indirectly test private ones). And while I'm still thinking about the merits of when you really need to test private methods, one thing did stand out to me and has proven very useful for my Monopoly Simulator.

I found that my Player objects should not expose their amount of cash as a publicly accessible field or method. Players in the real game of Monopoly, need not reveal how much money they have on hand. However, this presented a problem from two standpoints:
  1. The Bank (or some other aspect of the game) might need to know how much money they have left in order to properly control the flow of the game - I have yet to actually run into this scenario yet, so I'm going to employ the principle of YouArentGonnaNeedIt - and not worry about it until I need to.
  2. During unit testing, the cash level of a player indicates a successful test or not. This I have ran into and have used reflection to solve the problem.

Here is a method that accesses a private int field of any object:

private int getObjectPrivateIntValue(Class clazz, String fieldName, Object object) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
   Field field = clazz.getDeclaredField(fieldName);
   field.setAccessible(true);
   return field.getInt(object);
}

This is my first time bypassing the security of a class like this, so I'm not sure of all the ramifications yet. One thing I've noticed though, is that I'm tempted to put this kind of method into my actual application. This seems like a really bad idea. But, for unit testing code, it seems ok.

My next challenge, which is along these lines, is going to figure out how to make it so certain methods on Players (such as sendToJail() and pay(int amount) ) are only accessible to authorized classes (such as the Bank or Board objects). I can't make these methods package protected because other Player objects should not be allowed to call these methods. I need either some sort of SecurityManager. Maybe this is another place that aspects could help?


Wednesday, January 19, 2005

Monopoly Simulator

I have been working on a Monopoly Simulator for the past week or two. It's turning out to be an interesting project. At first I thought it would be interesting to simulate games to see if I could glean any strategic points, but a quick Google search turned up all kinds of Monopoly statistics. But, the more I thought about it, the more I thought it would be interesting to have a "pluggable" architecture so that different "players" could have different rule sets. Of course, because of my competitive nature, this quickly leaped to having people develop their own players with their own set of behavior rules (e.g. when they buy property, which properties they go after, trading, etc...) that could play against each other. On the other hand, I have a hard enough time finding people to play the regular Monopoly board game with me, much less code their own player rules in Java.

So, now I think I'm resigned to develop it just for learning's sake - which is sort of freeing.

I started out ok last week and identified which objects I would need and came up with what I thought would be a working model. Things were going ok, but then in typical form, I got a little excited about the whole thing and threw TDD out the window. Several lunch hours later, I had a Monopoly simulator that was "working" in that it actually simulated games and had a winner at the end, but I had no idea if it was working properly because I had no unit tests. The design also ended up in a rather unsatisfying mess with little room for expansion or flexibility. I need to refactor, but looking at it again I think I need to start over and just pull bits and pieces out as I need them.

I'm really interested in trying to integrate AOP in here somehow. I think in the area of generating statistics this will be great because that is certainly a cross-cutting concern. Each action in the game should be able to register some statistic of what just happened. Also, I'm thinking of using a rule engine for the player rules. That way, it's much easier to modify the player behavior using pseudo-english and, who knows, may even help get someone else to develop their own player.

More on this later.