Gripes and Moans of a High level programmer in a Low level world

Posted on 2009-04-29 21:22 in Blog • Tagged with programming

The majority of my schooling, I focused on high level software. I was more interested in data structures for sorting and storing information, abstracting ideas to create very robust classes, and implementing distributed applications (client/ server) than most of the low level programming details. That being said, I did take an assembly, C, and C++ class which have all proved very helpful in my day to day work as a programmer.

I currently work for a defense contractor writing software for embedded systems. Many of the components have a painfully small foot print. Getting a processor with 2K ROM which runs at 20kHz is not usual. This being said, all the software is written in either C (not C++) or assembly.

This has led to a major problem for me. I have found myself assuming too much while programming and inadvertently introducing logic problems, because a statement works differently in C that it would in Java or C#.

Type checking and precedence:

char a = 0xA0, b = 0x0A;
if(a | b != 0xAA)

As a java programmer I assumed the OR operation would be completed, and then the two sides would be compared. As it turns out, the comparison has a higher precedence level than the bit-wise OR. Still, in java, the strict type checking would have caught the problem since a Boolean value can’t be OR’d with a character value. In C, the result of the comparison is either a 1 or a 0, a number. It is a fairly straight forward fact that a number can be OR’d against another value. As such, this little logic error was propagated forward and was caught in testing a few days after getting committed. It has since been corrected:

if((a | b) != 0xAA)

Another problem I’ve been dealing with has to do with compiler bugs. Today, I ran into an annoying compiler optimization.

v1 = data[0]
v2 = data[1]
if( v1 != ~v2 ){
    return...
}

continue function another 12 lines

The compiler “optimized” this to…

v1 = data[0]
v2 = data[1]
return

It threw out the ‘if’ statement and all of the code below the ‘if’ statement and replace it with a simple return. The unusual thing about this, is v1 and v2 are local variables and should have been optimized out also if they are going to be assigned and then immediately discarded. Hmm… The code was modified below and everything acted as it should have.

char a = v1 ^ v2
if( a != 0xFF ){
    return
}

As I find more unusual traits of the compiler I’m using, I’ll be sure to document them.


Continue reading

bmmoAI Competition

Posted on 2009-03-16 20:59 in Blog • Tagged with programming

The competition was a great success. I held it two Saturday’s ago, on March 7th. There was a modest turn out of 12 students in total, although only six stuck around for completion.

There were a few minor technical difficulties encountered during the competition. First, I had trouble getting the projector hooked up to my laptop. There wasn’t a simple, ‘Laptop’ cord to plus in. I had to go digging in the mess of cables behind the computer to find a video in cord. Secondly, I had trouble completely disabling my firewall (to allow the AI clients to connect to my locally hosted game). It turns out Windows 7 has two firewalls. One for trusted networks (the one I turned off first); and a second one for untrusted networks.

About half an hour into the competition, one of the students asked for some help getting the sample client to work. Apparently I had a glaring logic problem. The client waited in an infinite loop, looking for an available action point before acting. However, there was no command to query the server for how many action points were available during the loop. I had missed this previously, since my debug environment always had free action points available. At the start of the competition, there were no points available, so the AI was stuck. I quickly published an updated version of the sample AI that actually worked.

I look forward to hosting another competition soon. Abram, one of the competitors and the current ACM president was very pleased with the success of the program. “It actually worked!” he told me halfway though the coding portion of the competition. He said that the last several (3 or 4) competitions he had been to were still being actively developed by the hosts as the students were busy writing their portions. He suggested for next time, that we make a bigger show out of this and envite the other two local colleges to come and compete.

I would like to congratulate the winners below, listed with their final point totals and the prize they selected.

Place Winner Points Prize
1st Mike 660 4 GB Flash Drive
2nd Kerber 120 5.5 lb. barrel of licorice
3rd Nathan 105 2 GB Flash Drive

bmmoAI Contest Winners


Continue reading

Competition Update

Posted on 2009-02-24 23:56 in Blog • Tagged with programming

It’s official, I’m going to be hosting a programming tournament at my old college. I’ve completed the initial contacts. Members from the ACM are going to take care of advertising and reserving the room, so all I have to do is show up with a working program. I’m going to have to kick it into overdrive to be sure to finish in time.

The only major feature I have left to implement is scoring. To do this, I have to first decide how many points each activity is worth. Another item I have left is creating the maps the students will be playing. I don’t forsee that being much of a problem. I have not yet performed any stress testing, so I’m not sure if the server can take the load of up to 20 clients playing at the same time. This will be easier to test once I have implemented an AI of my own.


Continue reading

Programming Hamlet

Posted on 2009-01-30 23:02 in Blog • Tagged with programming

public boolean hamlet()

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Wilson Kernighan


Continue reading

RPG Programming Project

Posted on 2009-01-28 20:26 in Blog • Tagged with programming

Early last fall, I set myself the goal of running a programming competition for the NDSU ACM club sometime this school year. The reason for the goal was twofold. First, I was always disappointed the ACM wasn’t more active while I was a member. But since I was extremely busy with class work I was unable to create a presentation of my own to increase the activity level. Now that I’ve graduated, my evening and weeks are less stressful and I can dedicate time to an ACM project. Secondly, I wanted a fun project to work on that would actually be of use. Towards that end, I decided to create a game framework, where the students would be creating AIs and battling them against one another.

What kind of game should I create? After rolling the idea around for a while, I settled upon a RPG style game. This would provide the most free-form mode of game play I could think of. The players could go the classic AI route and battle against one another, or they could focus on solving challenges within the game to earn points. Furthermore, the concept of path finding through an unknown maze is a classic AI challenge.

Wanting to avoid designing from the ground up, I began searching the net for RPG that were currently in their development phases. Most of what I found was too complicated for my needs, until I stumbled across BMMO. A good deal of the desired features were already implemented: rooms, doors, objects, weapons, and message parsing. There were only a few minor bugs and usability enhancements to make.

I walked down the list of known bugs from the BMMO group and immediately fixed them. I attempted to get in contact with the group members, but they were unresponsive to emails. So, I forked their project and setup my own using their existing code as the basis for mine (fully citing the originating source). Next, I set a standard message format for messaging between the game server and clients in preparation of moving the game from a text based console with human formatted messages, to an AI driven game.

I then began the painful work of creating the GUI structures. This helped me develop a more standardized message structure as I had to parse the different results and propagate them to the appropriate fields.

I’m feeling really good with the progress that I am making. Final remaining peices are to get the GUI working properly, and then completing message processing and data management to account for an AI thread running the game instead of a client. It boils down to how I’m going to expose the data structures to the AI that contain the game objects. This is mostly complete, just the details are left to finish.

Hopefully, the ACM members will apprecate the game when its ready for the competition.


Continue reading