First Geocaching Outing 2010
2010-03-15Date Set for Iceberg Races
2010-03-9Iceberg races is a go! I’m in Fargo for a couple of days attending the capstone presentation for the student group that I’m sponsoring. While in town, I decided to stop by the ACM office to notify them that I’m almost ready to run my second AI competition.
I chatted with the ACM Chair for an hour and we worked out a date for the competition to be held, the evening of April 2nd. The Chair agreed to manage finding a location to hold the competition and they will manage all the advertising (at NDSU and across the river at MSUM and Concordia).
I’ve now got a final deadline for when all the coding and documentation needs to be completed. At the moment, the server is written and the two clients are completed. However, I have not performed any stress testing on the server and have no managed multiple incoming connections, all of my testing has been running off the local machine where the server is located.
My final plan is to open source the complete game (server and clients) when the competition starts. (I’ll also probably post the game description document as a blog update.
Mercurial
2010-02-27For the last three weeks, development on my news program, Iceberg Races, has been in high gear. Each night before bed, I simply zipped up my work and archived it away. This approach was fine at first, as I was hammering out the design as I coded, which meant I took a lot of dead end paths. Large chunks of code and entire files were created and then deleted the next day (as I discovered better implementation methods.) It’s true that the best way to learn a language is to dive right in by writing ‘useful’ program.
On Wednesday, I realized that my code structure had stabilized a week prior and I was overdue for tracking my code in a source revision tool. Luckily, I ran across an amazing Mercurial tutorial and decided to give it a try.
So far I’m loving it. The commands are all straight forward. It was extremely quick to setup, and has perform admirably for the past two three days that I’ve been using it. I’ve summarized the most useful commands below (this is not an exhaustive list):
| Command | Description |
|---|---|
| hg * | All commands start with hg followed by… |
| init | Create a new repository in current directory. |
| add | Add new files to repository |
| remove | Remove file from repository |
| status | View the status of the repository. This lists all the modified files, files that aren’t being tracked, and files that have been marked for deletion. |
| diff | View the differences between two different versions of a file. |
| commit | Save the current state of the files to the repository. |
| rollback | Undo the last one commit. |
| merge | Resolve conflicts in a file. |
| log | View the revision history. |
| update | Check out files to a specified revision |
| push | Copy changes in local repository to a remote repository. |
| pull | Copy changes in a remote repository and bring them into your local repository. |
I’ve bolded the commands that come in the handiest. This includes the operations to save the current state of the repository and how to restore a past state.
XmlHttpRequest
2010-01-25I was reading about Websockets and their usefulness the other day when I realized how little of their precursor, the XmlHttpRequest, I actually knew. I performed some research and code a few quick and dirty example pages and discovered a new realm of capabilities that I was previously ignorant about.
For years, I had assumed AJAX technology was only useful if there were server side scripts interpreting the requests, gathering the needed data, and returning well formatted responses. These responses were then used to update the page content. While coding one of the examples, I had an ‘Ah-ah moment’. AJAX capabilities could be utilized to load static content when updating the page. Instead of having to address PHP or ASP pages, plain old HTML files could be the target.
Within minutes, I had seamlessly written a basic homepage, consisting of several sections that loaded all the content without a single page refresh. This game me a liberating feeling. Now I can update the content without losing my JavaScript variable values.
Quick Example
The simplest way to dynamically load content is to specify
/* Create the request object */
if (window.XMLHttpRequest) { // Modern browsers
____xhttp = new XMLHttpRequest();
} else { // Old Internet Explorer
____xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
/* Perform the request */
xhttp.open("GET","external_file.txt",false);
xhttp.send("");
destinationElement.innerHTML = xhttp.responseText;
This creates a new XmlHttpRequest object across multiple browser types. The ‘open’ command defines how the file will be retrieved (GET vs. POST) and the URL for the file. Send performs the actual communication with the server. After the communication is complete, responseText is extracted and displayed to the user.
This block of code is very straightforward and very misleading. It performs no error handling (file not found) and does not take into account the amount of time needed to retrieve file (server load).
Better Example
A better approach would be to use a JavaScript library that is designed for this type work, JQuery.
$(".destinationElement").load("external_file.txt");
This single line of JavaScript performs the same function as the block of code above. It says load the contents of the files, external_file.txt, into the DOM element whose title is ‘destinationElement’.
Again, this over looks the same errors the first block contained, errors while loading the file and what not. Luckily, JQuery has built in error handling events. As a programmer, we can define what action should be taken when a query fails.
$(window).error(function(msg, url, line){
____// handle the error
});
Quick note, the above block will catch all errors that occur, not just errors AJAX errors.
Python: with
2009-06-7Python is a beautiful language. It has taken a while to get use to the lack of brackets, but the benefit of ease of use has made that transition fairly straight forward.
One feature I discovered recently has made me a full fledged backer of the language: the ‘with’ command. Specificly, how it helps make the code cleaner. When multiple threads have to share access to a resource, it is common place to use a synconizing feature, usually implemented as a symaphore. For most languages (C based), the semaphore is aquired, the critical section is executed, and then the semaphore is released allowing other threads to interact with the resource. The problem arises when a peice of code fails while it contains the lock on the resource.
A try/ catch block must be established around the critical section to guarentee that a failure in the thread will not deadlock all other threads that need to access the resource. The following code sample demonstaits this functionality.
—-self.lock = threading.Lock()
—-self.lock.acquire()
—-try:
——–# Critical section of code
—-finally:
——–self.lock.release()
With the use of the ‘with’ command, a lot of the extra code can be removed.
—-lock = threading.Lock()
—-with lock:
——–# Critical section of code
——–…
The specification of the with command, guarentees that the lock will be aquired before the critical section is executed, and (more importantly) the lock is released before the block is exited, even in the event of an exception. The logic for checking for an exception and then releasing the lock has been abstracted to the interpreter.
Gripes and Moans of a High level programmer in a Low level world
2009-04-29The 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.
Download Caps
2009-04-27I do not believe in the practice of applying download caps to broadband accounts. Specifically when the account was established, the quantity of service that was discussed involved transfer speed as opposed to transfer amounts.
When I moved into my apartment, the first item of business that I took care of was signing up with a local ISP for internet access. I got a 1.5Mbs account for the reasonable price of $35. After thoroughly reading the contact, I signed on the dotted line and happily started surfing the net. Halfway through the month, I received an email saying we were close to going over our allotted bandwidth amount and would be charged an additional fee if we did.
A call to customer service enlightened us to a phase in the terms of service (referenced by contact, but not in the contract) saying if a subscribed was deemed to have excessive usage they would be charged an additional fee. So what was considered excessive? 10 GB/ month. What was my usage at the time of the email reception? 17 GB.
I was informed that we would be charged $2 per gig over the allowance, which would close to triple the cost of the account since we weren’t even two weeks into our service. Or, we would pay a onetime activation fee and then additional monthly fee to remove the download caps all together.
We politely told them we were going to be canceling our account with their company and seeking broadband service elsewhere.
My main problem with the 10 GB cap was not that there was a hard cap, but for how low it was. If I were to utilize my connection at the full speed that I was paying for a month, I should be able to download 474.6 GB. With the 10 GB cap, I am only allowed to utilize 2.1% of my connection before I have to pay an additional fee. The following quote from Slashdot sums up the speed vs. cap argument quite well.
Quote from Slashdot (didn’t save link)
All earlier poster put it best. The internet is a national public infrastructure, and the biggest problem with it is not treating it as such. The internet should be like roads, publicly owned. Anything less is always going to have problems. The public owns the network and anyone can sell their services over that network. Competition would exist and many of these problems would go away.
So, if you want to compare the internet to anything, it should be compared to roads. Because that is what it is truly analogous to. Electricity, water, natural gas, etc. are all items that are used up and require more money to obtain more of. The internet network like roads, take money to build, and can only handle a certain amount of traffic, but they are not used up by usage (the internet less so than roads actually). Thus, the analogy to water and other utilities is not an appropriate one, because it shares little in common with them.
bmmoAI Competition
2009-03-16The 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.
1st: Mike - 660 points - 4 gig flash drive
2nd: Kerber - 120 points – 5.5 lb. barrel of licorish
3rd: Nathan – 105 points – 2 gig flash drive

Winners: Kerber (2) Mike (1) Nathan (3)
Competition Update
2009-02-24It’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.
Posted by icedpenguin