public boolean step() {
        // get relevant rule
        int c = grid[pos_x][pos_y];
        Rule r = rules.getRule(state, c);

        if (r == null) {
            System.out.println("No rule for state " + state + ", colour " + c + "!");
            System.exit(-1);
        }

        //Change the colour and state, work out new direction, and move.
        grid[pos_x][pos_y] = r.getColour();
        state = r.getState();

        switch (r.getDirection()) {
            case 8:
                direction += 1;
                break;
            case 4:
                direction += 2;
                break;
            case 2:
                direction += 3;
                break;
            case 0:
                return false; //Halting state
        }//If it's 1, don't need to do anything. Can ignore other numbers.

        direction %= 4; //Make sure it's still in range

        switch (direction) {
            case 0:
                pos_y--;
                break;
            case 1:
                pos_x--;
                break;
            case 2:
                pos_y++;
                break;
            case 3:
                pos_x++;
                break;
        }
        pos_x = (pos_x + width) % width; //Wraps position around
        pos_y = (pos_y + height) % height;

        return true;
    }