C to Java

I’ve almost finished the mostly-mechanical first pass of converting the C GNU Chess code to Java syntax. I haven’t tried to compile yet, but there’s about six files out of thirty-plus that IDEA (world’s greatest IDE) says contain syntax errors. Most of them are complicated printf() calls that I put off, thinking I might just start using Java 5, which comes with a printf() of its own. Also remaining are some threading issues like the use of the signal() function.

The most common C features in C GNU Chess that needed converting to Java:

primitive typedefs
better readability and type-checking by using BitBoard instead of long. I started using Java classes for these typedefs, but BitBoard operations much be fast, and I’ve have to deal with translating between the different semantics for assignment of primitives and objects.
most were just constants; I made functions for most of the others, except a few like CLEARBIT that seemed easier to inline.
primitive reference parameters
I used the return value if possible; otherwise I passed the params in an array.
printf and scanf
only a few of these we hard to convert; Java 5’s printf will help
something else that’s available in Java 5
implicit bools
I can’t count how many times I converted “if (c)” to “if (c!=0)
Java doesn’t have goto, but it does allow labels on break and continue, which sometimes resulted in creating dummy loops just so I could use a labeled break instead of a goto.

A Scoop of Mulch

Last time I ordered mulch it was by the load at Cordell Earthworks of Durham, which is about a small dump truck load and was about right for our needs. This time I ordered from a different place, Southern States of Carrboro, and they measure mulch in scoops, which I figured was about the same as a load. It turns out that a scoop is a lot less than a load. I spread out the scoop in a couple of days and ordered four more scoops, learning that one scoop is equal to one cubic yard. Below are the photos of each delivery for future reference. The Southern States mulch was woodier (less composted) than the Cordell mulch, but surely more expensive (I don’t remember the prices).

One Scoop Four Scoops
One scoop of hardwood mulch One scoop of hardwood mulch

Java Port of GNU Chess

A week or two ago I started porting GNU Chess from C to Java in my spare time. The main motivation is to refresh my Java skills after two years of C++ immersion. It’s amazing how quickly you can lose the subtleties of a tool when you don’t use it.

I’m sure the project will succeed at making we aware of the Java/C differences, but I have to admit it’s unlikely the port will produce a runnable chess-plaing program even if I stick with it. GNU Chess code is pretty hairy, especially since it sacrifices clarity for speed. But if it does by chance run, it will serve as an interesting Java benchmark and will give me something to tinker with.

So far I’ve been translating each file to a Java class composed of static members, and I’m probably about 15% done by volume. The biggest headache so far has been lexpgn, which is a PGN (Portable Game Notation) file parser that is generated from a grammar description, sort of like ANTLR but different. I’ve barely used ANTLR, but if I knew it well, the thing to do would be to translate the lexpgn grammar to ANTLR syntax directly. The main lex() function is 800 lines long with nested switch statements and gotos …

Chess Spring Tournament – Round 2

Every five years or so I play and read a lot of chess, and even when I’m not in such an activity period I try to play in the company chess tournament. I typically finish 2nd of 6 in the lowest bracket. If I had a chess ELO rating, it’d probably be about a 1300.

Today I played a game against Michael Thomas, who I hadn’t played before. He seemed to be of comparable strength though better prepared. I made a PGN Viewer version of the game, or at least what I remember of it–I know some moves are wrong. Black played the Sicilian defense, and I soon felt like I was wandering around aimlessly through the middle game. He got a positional advantage but failed to press it for anything tangible. Though discouraged during the middle game, I decided I should be able to hold on to a draw if I could simplify the position, possibly giving up the exchange (my rook for his bishop).

After White
A series of trades got me to a mostly equal position by move 25 or so when I saw that getting my knight to c6 would tie Black’s pieces down temporarily to avoid a back row mate and at the same time would set a trap for his rook. He fell for the trap at move 29 by taking the “poison” pawn, and I went up a knight for a pawn after setting up a fork.
White to move and win (or draw)
Unfortunately, I was still happy to get a draw and played too conservatively, missing the last chance for a win on move 50. I’m sure it’s not often you can be up two pawns to none and still draw. Michael knew what to do and didn’t give me another chance.

Morganton Bridge Sectional

Mom and I played three sessions at the ACBL bridge sectional tournament in Morganton this week-end. (Actually Mom played two additional sessions with a partner from the partnership desk.) Each session is about 24 hands of duplicate bridge in 3-4 hours and is much more tiring than one would think. At the Raleigh sectional my legs were getting cramped from sitting that long in such a tense state. Fortunately for my legs, we were playing East-West, which meant we had to move tables after every few hands.

2005 Bridge Sectional at Morganton, NC,
That’s Mom in the magenta at the front table.

Our results weren’t too bad. I think our percentage results were 45%, 51%, and 56%, with 50% being average (and the vast majority of scores are between 40% and 60%). We earned a total of about 1.5 masterpoints, which is the ACBL cumulative rating system. I have about 25 points toward the 300 needed to get the coveted “Life Master” ranking. I’m currently tied for first in my unit’s Mini-McKenney Junior Master of the Year count, mainly on the strength of one good day at the Wilmingtion regional earlier this year, which was our first time playing duplicate together.

The Morganton sectional is the most popular in the region, and I can see why. The organizers were friendly and on the ball, and there was plenty of food all the time. Ham biscuits and bagels for breakfast, hotdogs and salads for lunch, and home-made desserts for snacks. I was also pleased to see fruit juice in addition to the usual array of sodas.

I’m encouraged by our results because we lost a lot of points from correctable mistakes, mostly on my side. So we have room to improve without changing our systems.

Spring League Ultimate Tournament

I’m still recovering from the first Hillsborough Spring League Tournament last week-end. I played on Yellow, which finished the regular season in a three-way tie for third place out of six teams and was a fun team with great captains. We made a strong showing in the tournament and were tied for first after the round robin play. That put us in the semifinals, where we lost to Red in a wind-dominated game. Red was also the only team we lost to in the round robin play.

I got scraped up on an unsuccessful layout on Saturday. The scabs are starting to heal, but my elbow and knee are still sore from the impact. My feet survived OK though. I often have problems with blisters when playing multiple games as normal measures like athletic tape and second skin tend to come loose after a couple of hours. This time I used a friction-reducing product called Body Glide that goes on like stick deoderant and work well (with one midday reapplication).

The tournament consisted of 4 games on Saturday and 1-3 on Sunday depending on how you did. My body can no longer take that much Ultimate in one week-end. My legs went dead after about 4 hours of play on Saturday and lasted less than half that long on Sunday.


I’m Xan Gregg, and this blog will help me keep track of my outside-of-work activities. At work, I’ve had a blog for two years to log activities relating to my job writing desktop scientific software (Mac/Windows/Linux) in C++.

Activities that might find their way into this blog:

  • various coding projects (mostly in Java, some Forth, C#, PowerPC asm, PHP, …)
  • playing ultimate frisbee
  • playing bridge
  • math
  • XML Schema
  • learning new things
  • gardening (not so much since we moved to the city)