Stephen W. Moore

August 28, 2009

geoDefense for iPhone: Add Custom Levels

Filed under: Uncategorized — Moors @ 1:09 am

geoDefense is a game for the iPhone 3G(S). Using SSH, it is possible to access the application directory and edit new levels.

You must have a jailbroken iPhone and have SSH running. Let your iPhone connect to your wireless LAN and take note of the ip address. SSH into your iPhone. I use PuTTY for Windows. The login information is:

  login as: root
  root@'s password: alpine
  iphone:~ root#

Next, find the directory of geoDenfense. Move up to the root directory and run the find command:

  root #/ find -name 'geo*'

The directories use apparently random generated directory names which are very hard to manage. Mine was under the ./mobile/Applications/xxxxx ….. xxxxx directory (a big long string of characters). Use the ‘cd’ command to get to the directory and then go into the application subdirectory /

  cd /private/var/mobile/Applications/xxxx …. xxxx/

All of the geoDefense levels are *.xml files.

geoDefense Directory

geoDefense Directory

Create a new file for your new level. My favorite level is Eternity (hard map 9), so I duplicated Eternity to a new file:

  cp GAME_LEVEL_H_0009.xml GAME_LEVEL_H_0013.xml
  nano GAME_LEVEL_H_0013.xml

First thing I did is rename it. For my first try, I called it “Eternity version 2”:

  name="Eternity v2"

Voila! It shows up on the levels menu! I also added a couple extra waves of creeps. More on that later.

geoDefense Levels

geoDefense Levels

Now I created my own custom level. This required understanding the coordinate map of the screen. I measured the screen and calculated 6.4 pixels per mm. Later, I found the actual number is 6.417, so I was pretty happy with my measurements. The harder part was figuring out the positioning of the geoDefense grid within the 320×480 screen. My best estimate:

  left edge:	x = 16
  right edge:	x = 304
  bottom edge:	y = 80
  top edge:	y = 464

Reality will show my estimates aren’t exact, but very close.

The next step is to draw a map and make x-y coordinates for the various segments. My first map is a spiral, which I will call “Event Horizon”, relating to the Schwarzschild radius ( around a black hole. My first drawing has the following coordinate map. I wanted the pathways straight along the grid lines.

  0   , 80
  64  , 144
  64  , 416
  256 , 416
  256 , 128
  128 , 128
  128 , 352
  192 , 352
  192 , 192
geoDefense Coordinate Map

geoDefense Coordinate Map

Some experimentation showed I wasn’t exactly on target. A little tweaking gave the following coordinate map:

   <point x="0" y="80" />
   <point x="62" y="144" />
   <point x="62" y="416" />
   <point x="258" y="416" />
   <point x="258" y="122" />
   <point x="128" y="122" />
   <point x="128" y="352" />
   <point x="192" y="352" />
   <point x="192" y="192" />

My initial estimates were very close.

Next, I added a few extra levels of creeps, in addition to those already specificed for “Eternity”:

   <spawn type="CHOMPER" count="25"/>
   <spawn type="WIGGLE" count="35"/>
   <spawn type="CHOMPER" count="25"/>
   <spawn type="WIGGLE" count="40"/>
   <spawn type="CHOMPER" count="25"/>
   <spawn type="WIGGLE" count="45"/>

Wow, that last wave of 45 wigglers is very difficult to beat. That’s because the creep’s health increases each level because of this line:

   <creeps waveHealthFactor="1" waveHealthFactor2=".2" waveWealthFactor=".5">

And you can tweak the starting health and speed of each type of creep:

   <creep type="CHOMPER" speed="40" health="100" />
   <creep type="SPINNER" speed="40" health="100" />
   <creep type="WIGGLE" speed="20" health="150" />
   <creep type="STAR" speed="60" health="75" />
   <creep type="CUBIC" speed="30" health="120" />

Overall, I was satisfied with my new level. Now the game has endless possibilities to create new challenging levels.

geoDefense Event Horizon

geoDefense Event Horizon

It takes a little tweaking to make the level playable.

geoDefense Event Horizon

geoDefense Event Horizon


August 27, 2009

iPhone 3GS Lithium-Ion Battery Life: Update

Filed under: Uncategorized — Moors @ 9:34 pm

My original analysis of the iPhone 3GS Lithium-Ion Battery Life is in direct opposition to the conventional wisdom (and sometimes recommended) battery advise is to keep the phone cradled or plugged in whenever possible. For some users, this means all day at work and evenings when at home. Some users even have a cradle that plugs into the cigarette lighter for their vehicles, to keep their precious iPhones charging every available moment (I suppose “cigarette lighter” is now passé, and “12V Auxiliary Power Port” is in fashion).

How to rectify these discrepancies? As always, with data.

Conventional Wisdom is generally applied when the population doesn’t fully understand an idea’s underlying principles. Therefore, to compensate for the lack of fundamental understanding, the population creates a behavior pattern based on consensus and shared experiences. In the case of batteries, the population has a century-long relationship with Lead-acid batteries, and several decades of Nickel-based batteries (i.e. Nickel Cadmium or Nickel Metal Hydride). It’s not surprising that the conventional wisdom surrounding lithium-ion batteries follow a similar rationale:  keep your battery charged, and charge it often. And batteries get warm during charging.

Lead-acid batteries indeed benefit from float charge. Nickel-based batteries indeed heat up as part of normal charging. Lithium-ion does neither.

One thing about being an expert is my opinions are usually confronted by questionable sources. Not really in business, but in general conversation. A common response would be “Reader’s Digest says keep the phone on the charger continuously or whenever possible!” Yes, I’m sure somebody published an article to that effect. Therefore, we shall use data from an equally ubiquitous source to settle this debate: Wikipedia’ entry on Lithium-Ion batteries. Behold, see the battery maintenance advice from Wikipedia:

[1] “Lithium-ion batteries should be charged early and often. However, if they are not used for a long time, they should be brought to a charge level of around 40%–60%.”

Well, it’s no mystery why this statement has the disclaimer “factual accuracy is disputed“. More disturbingly, no source reference is given for this strongly-stated care and maintenance advice. Just a few lines down, a direct contradiction:

[2] “It is significantly beneficial to avoid storing a lithium-ion battery at full charge. A Li-ion battery stored at 40% charge will last many times longer than one stored at 100% charge, particularly at higher temperatures.”

Which one to heed, statement [1] or [2]? The second statement refers to a reference from Cadex, a company that specializes in batteries and battery chargers. Battery charging is Cadex’s entire economy, and specializing on Lithium-Ion battery behavior is critical to their success.

Cadex presents a chart that compares battery life in case of keeping the battery at 40% or 100% SOC. When maintained at room temperature, notice the battery kept at 100% charge (i.e. cradled) permanently loses 20% capacity. The battery kept at 40% charge only loses 4%.

Cadex Battery Life Chart

Cadex Battery Life Chart

This loss is a result of the kinetics in the battery’s chemistry, and cycling or usage is largely irrelevant to the loss of capacity.

As a final exercise, let’s decompose the list of recommendations from Cadex (in blue), with my comments:

Simple Guidelines

1. Avoid frequent full discharges because this puts additional strain on the battery. Several partial discharges with frequent recharges are better for lithium-ion than one deep one. Recharging a partially charged lithium-ion does not cause harm because there is no memory. (In this respect, lithium-ion differs from nickel-based batteries.) Short battery life in a laptop is mainly cause by heat rather than charge / discharge patterns.

[As discussed in the original analysis of the iPhone 3GS Lithium-Ion Battery Life, the cell’s internal impedance causes localized internal heat generation. As long as the deep cycling does not enter into the high-impedance zones, cycling will not put additional strain on the battery. Using the impedance curves, one can accurately make the argument that “deep charging” is the reciprocal of “deed discharging”, and will cause the same damage!]

2. Batteries with fuel gauge (laptops) should be calibrated by applying a deliberate full discharge once every 30 charges. Running the pack down in the equipment does this. If ignored, the fuel gauge will become increasingly less accurate and in some cases cut off the device prematurely.

[This is accurate. The iPhone’s battery is monitored so that runtime can be predicted. As the battery ages, the monitoring circuit makes adjustments. Fully discharging and recharging the battery allows the monitoring circuit to measure the amount of charge the battery can hold.]

3. Keep the lithium-ion battery cool. Avoid a hot car. For prolonged storage, keep the battery at a 40% charge level.

[If you haven’t figured it out, (1) full charge and (2) heat are the biggest enemies to Lithium-Ion battery lifetime.]

4. Consider removing the battery from a laptop when running on fixed power.

[This is a workaround to prevent the battery from being maintained all the time at 100% SOC. Too bad laptop batteries aren’t programmable, because I’d just program mine to target 40% SOC everyday, but charge to 100% when traveling. For now, I use an old worthless battery for everyday office work, and my good battery is in my travel bag.]

5. Avoid purchasing spare lithium-ion batteries for later use. Observe manufacturing dates. Do not buy old stock, even if sold at clearance prices.

[As discussed, a Lithium-Ion battery will degrade over time, regardless of usage. New is always better than old.]

6. If you have a spare lithium-ion battery, use one to the fullest and keep the other cool by placing it in the refrigerator. Do not freeze the battery. For best results, store the battery at 40% state-of-charge.

[Absolutely. A battery stored in the refrigerator will maintain lifeline, losing only 2-3% per year. A frozen Lithium-Ion battery can be catastrophic, so be careful. With an iPhone, this statement is irrelevant, because the battery is not user removable.]

There you have it. Here’s my iPhone battery usage over a week using my custom USB charging/sync cable.

iPhone Battery Usage

iPhone Battery Usage

Create a free website or blog at