Archive for the 'Midlets' Category

Sudoku and My Handphone Solver

Sudoku is the short of “suji wa dokushin ni kagiru (æ•°å­—ã?¯ç‹¬èº«ã?«é™?ã‚‹),” meaning “the digits must remain single”. Its also called Nanpure (Number Place). Don’t mistaken this “Number Puzzle” for a magic square, it doest require adding, at the least maybe just counting. These numbers infact can be substitute with symbols, but digits are still the easiest way to represent 9 objects. The rule fill in digits so each digit(1-9) can only appear once in each row and column in the 9×9 grid, and each 3×3 subgrid. Most of the time you can solve the puzzle finding some pattern by observation.

The first encounter with sudoku The first time I saw of it was when I was reading Bittorrent’s creator Bram Cohen (cant remember was in his biography or interview about his Asperger’s Syndrome ) , when he found out he enjoy playing this game and hence learn about this puzzle.

As usual I learnt alot about the game from a wikipedia article on it.

Just as how Soduku popularise in many other countries, it became popular after appearing daily in Today Newspaper. I spend some fun time (or killing time) in camp solving the daily puzzle from copies of Today’s newspaper my campmate brings.

I believe this topic attract a considerable interest in the programming world, i decide to give a try at it too.. While I didnt do much well, the web provides lots of methods and implementations.

Then came my idea of using my mobile phone to play and solve it. Maybe it was just an idea to show off how my mobile phone can solve a puzzle when the rest are scribbling with pen and paper. So I I decided to create a Sudoku Puzzle Solver midlet for my Nokia 3120 Symbian series 40 phone.

What I use is a port/modification of Stan Chesnutt’s Java implementation/library of Knuth’s Dancing Links Method (see his university research paper)

Its interesting to know that Donald Knuth’s Dancing Links Algorithm uses his Algorithm X method. Dancing links seems to be the most efficient and organised way to find all solutions to a sudoku puzzle. Its uses boolean matrix of up to 700+rows and 500+columns. The operation on the matrix will be the algo x, where trys to solve cover leaf problems in the most efficient way. Here’s also another link for a comparision of dancing links implementations.

Anyway here’s the download to my initial version of my sudoku solver.

I thought at first maybe this sudoku was the only version for mobile phones around (at least free) but I found myself wrong after looking up getjars.com.. Happy Sudoku-ing on your mobile phone!

TorchLight

This idea struck me while using the newly brewed mirror application of mine.

Just the opposite of it, instead of a blackscreen and backlight off, I thought using a empty screen and blacklight on can turn the phone into a light source.

Another silly idea? Hopfully not. Lets say you might drop your car keys below the car seat where the door lights do not provide enough illumitation. Turn the torch light application on.

Then why not just press any button to turn the handphone lights on? 1) You dont have to keep pressing to keep on the lights on. 2) Its the clearest, bright light you can get from your phone lcd screen.

One day, when you find yourself in pitch darkness with nothing but your phone, you should find this application useful. Other uses for this software is reading papers in dim light conditions and … draining battery life..

[update]
At the end of the day after I wrote this version, I found while surfing the net that someone had implemented this idea too but for symbian series 60. See here

[note]
Download TorchLight.jar

I have also updated Mirror midlet so it can exit gracefully on Sony Ericsson phones. Both midlets now have icons.

[source]

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

import com.nokia.mid.ui.DeviceControl;
import com.nokia.mid.ui.FullCanvas;
/**
* Mirror Application for Nokia Phones - Turns Screen Black
*
* @author Joshua Koo http://zz85.is.dreaming.org zz85@users.sf.net
*
* 30 Jan 2006, Monday (Chinese New Year’s Day 2)
*/
public class TorchMIDlet extends MIDlet implements CommandListener {

private Canvas myCanvas;

public TorchMIDlet() {
}

public void startApp() throws MIDletStateChangeException {
myCanvas = new MyCanvas(this);
Display.getDisplay(this).setCurrent(myCanvas);
myCanvas.repaint();
DeviceControl.setLights(0, 100); //Turns on lights

//myCanvas.addCommand(new Command(”Exit”, Command.EXIT, 0));
//myCanvas.setCommandListener(this);
}

public void pauseApp() {
}

public void destroyApp(boolean arg0) throws MIDletStateChangeException {
}

public void commandAction(Command c, Displayable s) {
notifyDestroyed();
}

}

class MyCanvas extends FullCanvas {

int toFill = 0×999999; // white

MIDlet m;
public MyCanvas(MIDlet m){
super();
this.m = m;
}

public void paint(Graphics g) {
//g.setColor(toFill);
//g.fillRect(0,0,getWidth(),getHeight());
}

public void keyPressed(int keyCode)
{
if (keyCode == Canvas.UP)
toFill++;
if (keyCode == Canvas.DOWN)
toFill–;
if (keyCode == KEY_SOFTKEY1)
m.notifyDestroyed();

repaint();
}

}

Mirror MIDlet

If you have come across this Mirror application for Palm or this commercial PocketPC version, here’s my software for turning your nokia phone into a “mirror”.

Simple, silly, yet “idea!”, it works by turning all the pixels on the screen black. For my version, it turns off the backlight to reduce reflections glare. Works best under the sun, you might use it to spy on people behind you while look at the reflections on the black screen held in your hand.

Its about 2 years since I wrote a mobile application maybe - 1) disappointment in grades i got for my mobile applications module, 2) really never get to have hands-on using a real phone.
Its now with my Nokia 3120 I got, and a DKU-5 cable, installation of Sun Wireless Toolkit and Nokia Developer Tools I can get started again. Btw Nokia 3120 is really one of the cheapest phone with a “symbian os” - series 40. Programming language is java, (j2me -mobile edition if you care), and the program can be called a midlet too because midp (1.0) is required on handphones to run them.

Download it here for nokia phones, if not here for slightly more compatible version, if not just turn ur phone off to make it work the same way too.

Here’s the source code if you cared

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

import com.nokia.mid.ui.DeviceControl;
import com.nokia.mid.ui.FullCanvas;

/**
* Mirror Application for Nokia Phones - Turns Screen Black
*
* @author Joshua Koo http://zz85.is.dreaming.org zz85@users.sf.net
*
* 28 Jan 2006, Saturday (Chinese New Year’s Eve)
*/
public class MirrorMIDlet extends MIDlet {

private Canvas myCanvas;

public MirrorMIDlet() {
myCanvas = new MyCanvas();
}

public void startApp() throws MIDletStateChangeException {
Display.getDisplay(this).setCurrent(myCanvas);
myCanvas.repaint();
DeviceControl.setLights(0, 0);
// dealing with Backlight http://discussion.forum.nokia.com/forum/showthread.php?threadid=64234 http://discussion.forum.nokia.com/forum/showthread.php?t=33194
}

public void pauseApp() {
}

public void destroyApp(boolean arg0) throws MIDletStateChangeException {
}

}

class MyCanvas extends FullCanvas {
public void paint(Graphics g) {
g.setColor(0×000000); // black
g.fillRect(0,0,getWidth(),getHeight());
}
}

Well, some other j2me applications for handphones that kept me interested recently
1) Go Bible - “Go Bible Java applications that can be loaded onto phones. ”
2) ReadManiac - “A Library in the Pocket”
3) vOICe - “seeing-with-sound technology for the totally blind”

Well.. if I free (word being very subjective), I’ll try working on some other ideas I have. If you have any cool ideas, let me know and see if I challenged to implement it. Meanwhile checkout some sites - Wireless Java downloads, Imserba - “The best mobile phones portal and community in the world”

[update:] After running this application, I found it could serve another purpose. To trick people into thinking the handphone is off as the screen is dark and blanked out.