|
Helping ordinary people create extraordinary websites! |
Secrets of the Wireless Elite: Mobile Applications Need Scripting Too!By John Papageorge2005-04-13
Theory in Practice: Park's Example Code To avoid computation, Park advises that you preprocess data and use it later. "It's nice when you can preprocess data at load time or during run time," he says. He continues, "I wrote an American football game in which the AI could use hundreds of random numbers per second. In this case I could avoid a fair amount of computation by pulling from a pool of random numbers during each football play. Resource pools represent a simple and common concept employable in many other contexts." Here's the code: Listing 1. Class RandomPool import java.util.Random;"Between plays, the pool refreshes with new numbers by calling RandomPool.generate()": Listing 2. Method RandomPool.generate() public static final void generate()"During plays, the game grabs numbers from the random number pool," he says. "Instead of refilling the pool when it runs out, the game reuses the numbers in the pool until the play completes, then refreshes the pool before the next play": Listing 3. Refreshing the pool public static final int nextInt(int limit) Tutorial Pages: » Mobile Apps Developer Tom Park Imparts His Wisdom » The Mobile Gamer's Toolkit » Park's Secret Weapon: Scripting » What Every Wireless Developer Should Know » What Every Wireless Developer Should Avoid » The Challenges Every Wireless Developer Faces » Time to Market Equals Success » Brand Games Extended to Mobile Devices » BREW vs. Java Technology » Theory in Practice: Park's Example Code » Mobile Gaming: the Future » Resources First published by IBM DeveloperWorks |
|