Text Editors

The choice of text editor is a very personal thing, especially for a programmer. If you are going to spend several hours a day working with a program then you had better make the correct choice! The correct text editor can make a huge difference in programming productivity. However, in order to get the full benefits the programmer has to put in the time to learn the editor well enough that the major commands are in muscle memory and can be executed without thinking about them. This means that changing editors involves a significant investment in time and effort.

In the early days of my programming career I used the Brief editor under DOS and grew to know and love its key bindings. When the world moved on to Microsoft Windows, I moved onto CodeWright but still using the Brief key bindings. These days at work I am not doing as much programming but can still use CodeWright pretty well when required.

At home I generally use Linux on my computers and so can’t use the Windows specific editors that I use at work. When moving to Linux, I looked at what editors were available and decided to use of the big open source contenders so that I knew that it would be able to do anything that I needed and that support would never be a problem.

I never really considered VIM as I could never get on with the modal nature of vi when I used it at university. For a while now I have been using emacs and getting on OK with it but I have never got in to using the emacs specific keys for cursor movement, I still use the arrow keys etc. This means that I am not getting the full “move your hand as little as possible” efficiency. Recently, for this reason and general curiosity I decided to have another look at the text editors available in the Linux space.

The available editors have not changed much since the last time that I looked. The one editor that I have now tried is Sublime Text 2.

Sublime is a very good editor with some unique facilities but I was put off spending significant time learning it fully because it is not free / open source. There appears to be a slowdown in the pace of development of Sublime and this is worrying. The author could could stop development of the editor at any time and there would be no chance for the community to take over.

For now I have decided to stick with emacs and take the time to learn the cursor movement keys and at the same time brush up on my touch typing skills!

2011 – New Year’s Resolutions

I have two, software related, New Year’s Resolutions that I will try to follow during 2011. These are “Do some Lisp Programming” and “Do some Squeak/Pharo Programming”.

In terms of Lisp I have purchased the e-book version of Land of Lisp after seeing many good reviews of it on the net. So far it has been an entertaining re-introduction to Common Lisp.

As for Squeak/Pharo, I have been re-visiting Morphic and finding it much more interesting that I remembered. I definitely intend to do some more with Morphic over the coming months.

Now to go and starting putting this into practice ….

Python Adventure Game – Finished

I have now finished my Python Adventure Game by adding some puzzles and a win algorithm. Its a very simple game but was great fun to write.

Source code is below.

#
# Barry's simple adventure game
#
 
# Room data indexs
SHORT_DESC = 0
LONG_DESC = 1
N_EXIT = 2
S_EXIT = 3
E_EXIT = 4
W_EXIT = 5
U_EXIT = 6
D_EXIT = 7
OBJECT = 8
 
# Room Data
rooms = [
['dummy'],
['the entrance', 'the entrance to a rather large looking cave', 2, 0, 0, 0, 0, 0, ''], # 1
['a coridor', 'a coridor that stretches off to the North', 3, 1, 0, 0, 0, 0, 'Lamp'], #2
['a round room', 'a round room with many exits', 7, 2, 4, 0, 20, 6, ''], #3
['a crawlway', 'a narrow east / west crawlway', 0, 0, 5, 3, 0, 0, ''], #4
['a low cave', 'a low dead end cave', 0, 0, 0, 4, 0, 0, 'Knife'], #5
['a well', 'a deep well with no way out', 0, 0, 0, 0, 0, 0, ''], #6
['a crystal cave', 'a beautifull cave with crystal walls', 8, 3, 9, 0, 0, 0, ''], #7
['an alcove', 'a small alcove in the cave wall', 0, 7, 0, 0, 0, 0, ''], #8
['a passage', 'a long east / west passage', 0, 0, 10, 7, 0, 0, ''], #9
['an anteroom', 'a richly decorated anteroom', 13, 11, 12, 9, 0, 0, ''], #10
['a wardrobe', 'a large wardrobe with space for lots of clothes', 10, 0, 0, 0, 0, 0, 'Key'], #11
['the throne room', 'a very large room with a golden throne on a dais', 0, 0, 0, 10, 0, 0, 'Crown'], #12
['the view room', 'a cave with a small hole giving a view along a green valley', 0, 10, 14, 0, 0, 0, ''], #13
['the guard room', 'a room with chairs and a table that looks like it was used as a guard room', 0, 0, 15, 13, 0, 0, ''], #14
['the ballroom', ' a magnificent ballroom with purple and gold walls', 0, 17, 18, 14, 16, 0, ''], #15
['the organ loft', 'a small room containing the controls for a large pipe organ', 0, 0, 0, 0, 0, 15, ''], #16
['the vault', 'a small airtight vault with shelves around the sides', 15, 0, 0, 0, 0, 0, 'Diamond'], #17
['the dining room', 'a long room with a huge dining table and chairs', 0, 0, 19, 15, 0, 0, ''], #18
['the kitchen', 'a large dusty kitchen', 0, 0, 0, 18, 0, 0, ''], #19
['a gallery', 'a high gallery leading off in a number of directions', 24, 22, 23, 21, 0, 3, ''], #20
['the waverfall cave', 'a large cave with a dark lake and a waterfall at the far end', 0, 0, 20, 0, 0, 0, ''], #21
['the echo cave', 'a small cave where sound echoes all around', 20, 0, 0, 0, 0, 0, ''], #22
['the assasin room', 'a small room bare room', 0, 0, 25, 20, 0, 0, 'a dead Masked Man'], #23
['a dark cave', 'a dark cave', 24, 24, 20, 24, 24, 24, ''], #24
['the exit', 'the exit of the cave', 0, 0, 0, 23, 0, 0, ''] #25
]
 
objects = ['dummy']
visits = [0]
for room in range(1, rooms.__len__()):
    objects.append(rooms[room][OBJECT])
    visits.append(0)
 
current_room = 1
visits[current_room] = 1
 
inventory = []
 
battery = 100
 
# Code
 
def describe_room(room):
    print
    if visits[room] > 1:
        print 'You are in ' + rooms[room][SHORT_DESC]
    else:
        print 'You are in ' + rooms[room][LONG_DESC]
    print
    if rooms[room][N_EXIT] != 0:
        print 'There is an exit to the North'
    if rooms[room][S_EXIT] != 0:
        print 'There is an exit to the South'
    if rooms[room][E_EXIT] != 0:
        print 'There is an exit to the East'
    if rooms[room][W_EXIT] != 0:
        print 'There is an exit to the West'
    if rooms[room][U_EXIT] != 0:
        print 'There is an exit leading upwards'
    if rooms[room][D_EXIT] != 0:
        print 'There is an exit leading downwards'
    if objects[room] != '':
        print
        print 'There is a ' + objects[room] + ' here'
    print
 
def move(exit):
    global current_room
    if rooms[current_room][exit] != 0:
        # Can't enter the vault without the key
        if ((current_room == 15) and (rooms[current_room][exit] == 17)):
            if 'Key' in inventory:
                print
                print
                print "You use the key to open the door to the vault"
                current_room = rooms[current_room][exit]
                visits[current_room] += 1
            else:
                print
                print
                print "You can't open the heavy door but it does have a key hole"
        else:
            current_room = rooms[current_room][exit]
            visits[current_room] += 1
    else:
        print
        print
        print '>>> There is no exit in that direction'
 
def north():
    move(N_EXIT)
 
def south():
    move(S_EXIT)
 
def east():
    move(E_EXIT)
 
def west():
    move(W_EXIT)
 
def up():
    move(U_EXIT)
 
def down():
    move(D_EXIT)
 
def get():
    if objects[current_room] == command.split()[1]:
        objects[current_room] = ''
        inventory.append(command.split()[1])
    else:
        print
        print "There is not a " + command.split()[1] + " here"
 
def drop():
    if command.split()[1] in inventory:
        inventory.remove(command.split()[1])
        objects[current_room] = command.split()[1]
    else:
        print
        print "You are not carrying a " + command.split()[1]
 
def inv():
    print("Inventory: ")
    for item in inventory:
        print item
 
commands = {
'north' : north,
'n' : north,
'south' : south,
's' : south,
'east' : east,
'e' : east,
'west' : west,
'w' : west,
'up' : up,
'u' : up,
'down' : down,
'd' : down,
'get' : get,
'inventory' : inv,
'inv' : inv,
'drop' : drop
}
 
# Main game loop
exit = False
while (not exit):
    print
    print
    describe_room(current_room)
    command = raw_input( "What do you want to do: " )
    if command != "":
        command_name = command.split()[0]
    else:
        command_name = "none"
    if command_name in commands.keys():
        commands[command_name]()
    else:
        print
        print
        print '>>> I don\'t understand that'
    # Check lamp
    if 'Lamp' in inventory:
        battery = battery - 1
        if battery == 50:
            print
            print
            print "The battery in your lamp is half used"
        else:
            if battery == 25:
                print
                print
                print "The battery in your lamp is three quarters used"
            else:
                if battery == 10:
                    print
                    print
                    print "The battery in your lamp is almost exhausted"
                else:
                    if battery == 0:
                        print
                        print "Your lamp has failed"
                        print "You fell in a pit and died!!"
                        print
                        exit = True
    else:
        if current_room == 3:
            print
            print
            print "It's dark here, you should find a light source or you might get hurt"
        else:
            if current_room > 3:
                print
                print "You fell in a pit and died!!"
                print
                exit = True
    # Assasin puzzle
    if current_room == 23:
        if 'Knife' in inventory:
            print
            print
            print "You killed a masked man with the knife you were carrying, well done"
        else:
            print
            print "A masked man killed you, you should have looked for a weapon!"
            print
            exit = True
    # Win check
    if current_room == 25:
        if (('Crown' in inventory) and ('Diamond' in inventory)):
            print
            print "Well done, you found all of the treasure"
            print
            exit = True
        else:
            print
            print "There is more treasure to find, go back and keep looking"
            print

Python Adventure Game

As well as the space invaders game mentioned in an earlier post I thought that I would also implement a textual adventure for the nostalgia value.

I sketched the map of the game on paper as shown below.

Map 1

Map 2

And then implemented the data structure in python.

# Room data indexes
SHORT_DESC = 0
LONG_DESC = 1
N_EXIT = 2
S_EXIT = 3
E_EXIT = 4
W_EXIT = 5
U_EXIT = 6
D_EXIT = 7
OBJECT = 8
 
# Room Data
rooms = [
['dummy'],
['the entrance', 'the entrance to a rather large looking cave', 2, 0, 0, 0, 0, 0, ''], # 1
['a corridor', 'a corridor that stretches off to the North', 3, 1, 0, 0, 0, 0, 'Lamp'], #2
['a round room', 'a round room with many exits', 7, 2, 4, 0, 20, 6, ''], #3
['a crawlway', 'a narrow east / west crawlway', 0, 0, 5, 3, 0, 0, ''], #4
['a low cave', 'a low dead end cave', 0, 0, 0, 4, 0, 0, 'Knife'], #5
['a well', 'a deep well with no way out', 0, 0, 0, 0, 0, 0, ''], #6
['a crystal cave', 'a beautiful cave with crystal walls', 8, 3, 9, 0, 0, 0, ''], #7
['an alcove', 'a small alcove in the cave wall', 0, 7, 0, 0, 0, 0, ''], #8
['a passage', 'a long east / west passage', 0, 0, 10, 7, 0, 0, ''], #9
['an anteroom', 'a richly decorated anteroom', 13, 11, 12, 9, 0, 0, ''], #10
['a wardrobe', 'a large wardrobe with space for lots of clothes', 10, 0, 0, 0, 0, 0, 'Key'], #11
['the throne room', 'a very large room with a golden throne on a dais', 0, 0, 0, 10, 0, 0, 'Crown'], #12
['the view room', 'a cave with a small hole giving a view along a green valley', 0, 10, 14, 0, 0, 0, ''], #13
['the guard room', 'a room with chairs and a table that looks like it was used as a guard room', 0, 0, 15, 13, 0, 0, ''], #14
['the ballroom', ' a magnificent ballroom with purple and gold walls', 0, 17, 18, 14, 16, 0, ''], #15
['the organ loft', 'a small room containing the controls for a large pipe organ', 0, 0, 0, 0, 0, 15, ''], #16
['the vault', 'a small airtight vault with shelves around the sides', 15, 0, 0, 0, 0, 0, 'Bag of Money'], #17
['the dining room', 'a long room with a huge dining table and chairs', 0, 0, 19, 15, 0, 0, ''], #18
['the kitchen', 'a large dusty kitchen', 0, 0, 0, 18, 0, 0, ''], #19
['a gallery', 'a high gallery leading off in a number of directions', 24, 22, 23, 21, 0, 0, ''], #20
['the waterfall cave', 'a large cave with a dark lake and a waterfall at the far end', 0, 0, 20, 0, 0, 0, ''], #21
['the echo cave', 'a small cave where sound echoes all around', 20, 0, 0, 0, 0, 0, ''], #22
['the assassin room', 'a small room bare room', 0, 0, 25, 20, 0, 0, 'Masked Man'], #23
['a dark cave', 'a dark cave', 24, 24, 20, 24, 24, 24, ''], #24
['the exit', 'the exit of the cave', 0, 0, 0, 23, 0, 0, ''] #25
]

The game is now mostly working. Only the puzzles left to implement.

Pygame

I have been looking for a project to use as an excuse to write some Python as its been a while since I last used it. Searching around I came across pygame (http://www.pygame.org) and decided to look into it.

It has been many years since I have written a game but the documentation and examples on the pygame site look very good. I have started a good old Space Invaders game and will see how I get on from there.

Squeak 4.1

Squeak 4.1 was released this week. After all of the problems with the community splitting after the Pharo fork, Squeak appears to be back on track. Squeak 4.0 was a licence clean release without any new functionality but 4.1 includes all of the updates that were made during the re-licencing process.

Hightlights include a new look and feel based on the Newspeak UI, new anti-aliased fonts, the closure enabled compiler from Cog, core library improvements and modularity advances. More details can be found on www.squeak.org.

I hope that I can find the time to check it out more fully soon.

Open University

I will have less time for my own programming projects for the next few months because I have started a new Open University course. I felt that I had done enough maths after two courses and so now I am doing a software one, M255 – Object-oriented programming with Java.

This will be the first time that I have been formally taught object-oriented programming or Java. Should be interesting!

Best laid plans…

After stating that I would use Ruby for all of my personal programming I did something that changed all of that. I downloaded VisualWorks 7.7 NC and started to play with it. Smalltalk has always held a dangerous attraction for me since the fist time I saw Squeak many years ago.

The latest version of VisualWorks looks good and there is so much material around the Internet to support it both from Cincom and third parties. I am now going to port some of my personal applications to VW to see how I getting on using it as a development platform.

HTC Hero

I have just changed my mobile phone to the Android powered HTC Hero. I have not had that much time to play with it but it is working well so far. I have also decided to do some coding for Android.

I have downloaded the development tools and brought a copy of “Hello, Android” from the Pragmatic Programmers. So far I have made the initial “Hello World” app to make sure that the development tools are installed and working correctly. Now to move on to more interesting things!

BjbGtd project on Kenai

In order to keep my life in order I have for many years used a task management system based on Getting Things Done (GTD) by David Allen. Initially I used a system called Life Balance on PC and Palm then moved to My Life Organised on PC and Windows Mobile.

I like the way that both of these systems work but as a software guy I have always thought “I can do that!”. So now I am putting my money where my mouth is and have started my own open source GTD project. Initially I am implementing a library to handle the GTD data items (Tasks, Contexts, etc.), this will be followed by desktop, mobile and, maybe, web applications that all use the library.

The library is called BjbGtdLib, is written in Java using NetBeans and is hosted on Kenai.

Go take a look!