Monthly Archive for March, 2007

AJSS: CodeInvaders!

During the 2006 ACM-ICPC World Finals in San Antonio, Texas, there is an intermediate programming contest sponsored by IBM.  The Java Challenge showcases the latest offerings from IBM and try it out in a tournament style.  The name of the tournament was CodeInvaders.  It was released in the IBM AlphaWorks site last June 2006.  Here is a short description from its AlphaWorks page:

CodeInvaders is a Javaâ„¢-based, real-time programming game based on the Eclipse platform. It uses the Eclipse platform and a simple API that allows users unfamiliar with Java to easily compete while they learn the language. CodeInvaders Challenge gives users the opportunity to pit their Java programming skills against other players in a battle of space conquest. Each player writes a Java class that represents and controls a spaceship. Each ship (class) is placed in a simulated battle along with ships from other players.

One of our ACM coaches, Dr. Vergara realized that this platform can be used to teach Java and object oriented programming for kids in the high school range.  This summer, we teamed up (Akie Mejia, me,Doc V) will conduct a Java programming workshop for the Ateneo Junio Summer Seminar (AJSS).  I installed Eclipse and the CodeInvaders plugin into Doc V’s computer and demonstrated how to use the program.  Then we will meet sometime next week to discuss how we plan to approach the workshop and have some fun programming our own spaceships.

In preparation, I made improvements to our initial solution in the ACM which uses a rent-seeking economy paradigm.  In the game, you get points if your spaceships beam energy to their home planets.  So the Linden BoyZ simply beamed all the energy of the mothership and drones to the home planet and obtained the maximum possible score of 280 points.  Most of the contestants during the World Finals used this approach.  Everybody in the tournament arena just laughed when all teams used this strategy at the same time.

The main improvement compared to our previous strategy is that I applied a “look before you leap” approach.  For the spaceships to move around the field, it requires some key units of energy.  Before the game starts, each ship has a pre allocated amount of energy.  Other energy sources are randomly scattered in the field which can be obtained by the ships.  Therefore, in order to increase the maximum possible score, the programmer must design the ships to gather energy.   The energy consumed from traveling in space is used by the ship’s thrusters.  For every amount of thrust used, energy is used per unit of time. 

The thrust will them change the ship’s accelaration a.  Assuming that the ships will have an initial velocity v of 0 to go to the energy source, the time t to reach  the source can be computed through the kinematic equation

[tex] d = \frac{1}{2} a t^2 [/tex]

where d is the distance from the ship to the energy source.  The energy consumed to travel this distance and back is then computed by dimensional analysis.

Results:

Creating a simulation of 6 teams using my strategy gave me the following scores:

As evidently observed from the screenshot, I was able to surpass the maximum possible score of 280!  The sourcecode for the MySpaceShip.java will be posted later on (the participants of AJSS) might use it. :D

Technorati Tags:

Related Posts Related Websites

Introduction to SPICE: teaching demo

I applied a couple of weeks ago to join the faculty of the ECCE Department in Ateneo de Manila. For my demo teaching class, I decided to give a short lecture on using SPICE for DC circuit analsysis of simple resistor networks. 

Lecture Prerequisites:

  1. Familiarity with basic electronic concepts.  The topics for this introduction will contain DC analysis of passive devices (e.g. resistors, inductors, capacitors).  A short lecture on basic circuit analysis might be included if I am able to obtain a copy of Electric Circuit Analysis by Johnson and Johnson
  2. Minor background on operating a CLI (command-line-interface) environment.  The lecture will demonstrate the use of ngspice [1] on a Linux terminal.

SPICE stands for “Simulation Program with Integrated Circuit Emphasis”.  Most simulation tools such as Electronic WorkBench, MultiSim and LTSpice generate SPICE code from the schematics diagrams that were drawn by the designer.  For a quick overview of SPICE here, is a short description from Wikipedia [1]:

Integrated circuits, unlike board-level designs composed of discrete parts, are impossible to breadboard before manufacture. Further, the high costs of photolithographic masks and other manufacturing prerequisites make it essential to design the circuit to be as close to perfect as possible before the integrated circuit is first built. Simulating the circuit with SPICE is the industry-standard way to verify circuit operation at the transistor level before committing to manufacturing an integrated circuit.

Board-level designs can often be breadboarded, but designers may want more information about the circuit than is available from a single mock-up. For instance, performance is affected by component manufacturing tolerances and it is helpful for designers to simulate with SPICE to predict the effect of variations of those values. Even with a breadboard, some aspects may not be accurate compared to the final printed wiring board, such as parasitic resistances and capacitances. In these cases it is common to perform Monte Carlo simulations using SPICE, a task which is impractical using calculations by hand.

Circuit simulation programs, of which SPICE and derivatives are the most prominent, take a text netlist describing the circuit elements (transistors, resistors, capacitors, etc.) and their connections, and translate this description into equations to be solved. The general equations produced are nonlinear differential algebraic equations which are solved using implicit integration methods, Newton’s method and sparse matrix techniques.

Materials will be posted later on (I hope).  The class will be held on March 21, 2007 (GMT+0800) in Faura Hall Rm 319 (see my Google Calendar)

[1]“SPICE.”  Wikipedia, the free encyclopedia. http://en.wikipedia.org/wiki/SPICE
[2] Ngspice circuit simulator.  http://www.ngspice.org

Technorati Tags: , , , ,

Related Posts Related Websites

Changing Rubik’s Cube sticker labels

It is an established fact the the sticker labels of rubik’s cubes deteriorate fast. For less than a year of using my newly ordered 3×3 cube from http://www.rubiks.com, 4 out of 6 faces were discolored. The “protective” plastic coating of the cube has a greater bonding strength with the colors than the sticker base. So as the stickers peel, so does the color. In the end, one will end up with a purely white cube.

I searched the Internet for methods on how to replace it. The most famous query from a Google search is to buy the official labels from rubiks.com. As a resident of the Philippines, this is the least feasible solution. I scoured various stationary, school and office supplies shops to look for the “official” (yellow, blue, green red, orange) but was not able to find all of the colors.

sticker_seal In order to have consistency among sticker labels, the best solution was to buy a clean sheet of sticker paper and print on it. These sticker labels were bought from National Bookstore along Katipunan Avenue. The yellow sheet is the clear acetate to protect the colors from fading in the future.

sticker_protection The next step is to print on the sticker labels. Using an HP Deskjet 3745 printer, a 600 DPI print of the labels were made. I also uploaded the sticker sheet so anyone can print the sticker labels. Measuring the dimensions from an official cube, each square label has a length of 0.625 inches. (Note: there are extra square labels in the sheet because I was also planning to recondition my Fused cube).
The next step before cutting up the labels is to insert the protective acetate cover. It must be laid out carefully. I think it is preferrable to use a roller-like device to lay down the sticker on the sheet to spread the acetate evenly. My attempt was a failure because I don’t have a roller-like thingie. What happend was very catastrophic. Bubbles formed on the sheet rendering my labels useless. Then off to the garbage bin the labels go.

Since the cube is useless without proper labels, I attempted a method using local materials available in a local supplies store here in the Philippines. I bought assorted art paper from National Bookstore. To efficiently (or hackishly) insert labels, double-sided tape was laid on the back of each color of an art paper sheet. Afterwards the art paper was cut-off according to the rectangular shape of the tape. Then I cut away square portions of the tape-art paper combination to be laid on the cube itself. Afterwards transparent adhesive (aka “Scotch”) tape was inserted on top of the art paper for protection. The result of the double sided tape - art paper - transparent adhesive tape combination can be seen below:

final_cube
Not bad eh? But after playing with my reconditioned cube for a while the labels started to deteriorate (again!). In my next reconditioning attempt, I will try to use clear nail polish for the protection layer and see the difference.

Technorati Tags: , , ,

Related Posts Related Websites