My First Chess Program

When I was a kid, back in the 70's and 80's, I thought chess programs were the most sophisticated computer programs in the world. That was back when the average personal-computer chess program wasn't very good, and dedicated chess computers cost hundreds or thousands of dollars, so it seemed to me that chess was something very difficult for computers to do. At the time, many experts still thought a computer would never be able to beat human grandmasters. I dreamed that I would one day write The World's Greatest Chess Program, and that would prove I was a great computer programmer.

But one's priorities change. I did look into how chess programs worked when I was in college, and while I found the topic interesting, I didn't try writing my own program. I still thought that writing a chess program was something every Real Computer Programmer should do, but I didn't get around to it.

Now, at age 50, I've finally done it. A few weeks ago I started writing a chess engine in Swift, and it is now capable of playing a real chess game. I call it "kjchess".


So, suddenly, I'm 50 years old. Almost a quarter of my life behind me.

50 really doesn't seem that bad. 40 felt much more like an oh-man-I'm-old-and-have-wasted-my-life event. I'm much happier now than I was then. This has been a great decade for me. I met a wonderful woman, and we are celebrating our ninth wedding anniversary this year. I live in a comfortable house with people and dogs who make me feel connected and loved (most of the time). Being 50 and happy is much better than being younger and miserable.

What's Good on TCM This Week?

I like old movies. In the old days, we had TV stations known as "UHF channels" that showed lots of old movies all night long. But UHF channels are gone, and today all we have is the Turner Classic Movies (TCM) channel and website.

I like film noir, sci-fi, horror, and westerns. TCM has a lot of these movies, but it also shows a lot of stuff I'm not interested in. I don't like browsing the upcoming schedule via the TCM website or via my cable provider's interface, so I wanted a way to generate a schedule just for me so that I can record good stuff on my DVR, or watch available movies on Watch TCM or my cable provider's on-demand service.

It turns out that TCM offers a web services APIs that allow one to retrieve schedule information. So I've whipped up a script that that grabs the schedule for the next week and identifies the movies that match my preferences.

The result is a web page: What's Good on TCM?.

The page displays the movies coming up during the next week that might "good" according to my taste. You can click the name of a movie or name of a director, actor, or screenwriter to search the TCM database for more information.

Your preferences may not match mine. That's OK; if you are a computer person, you might be able to customize my script to find your musicals or romances or screwball comedies or whatever it is you want. It's available on GitHub:

cxxforth: A Simple Forth Implementation in C++

Because implementing obsolete programming languages is a great use of my free time, I've created cxxforth, an implementation of Forth in C++.

Inspired by JONESFORTH, I wrote it in the style of a tutorial. The source code is automatically converted to a pretty-printed format:

Now, on to the next waste of my time...

A Gforth Interface to the wiringPi Library

I recently obtained a Raspberry Pi, an Arduino, and a model train set. This should keep me busy and out of trouble for a while.

My plan is to use the Arduino to read sensors and control the turnout switches on the track, but I think it is easier to use the RPi to do some initial experimentation with driving relays and other electronic components. I did the typical make-an-LED-blink exercise using the wiringPi library. It wasn't difficult, but I wished there was an interactive way to play with the GPIO pins, rather than going through a cycle of editing, compiling, and executing a C program whenever I wanted to try something.

Then I remembered Forth. Forth was designed as an interactive language for controlling hardware, and seemed like the perfect solution for me.

After looking at a few possibilities for Forth-based solutions, I decided to use Gforth, as it provides a straightforward way to call functions in the wiringPi library without the need to build my own Forth.

Here is my Gforth interface to the wiringPi library:

Now, back to the train set...

Performing Privileged Operations in an OS X Application

I am currently developing an OS X application. The application needs to perform some operations that require root privileges (installing and uninstalling launchd daemons, sending signals to other users' processes, etc.) So I started looking for some documentation about how to do that. I figured it would take a few minutes.

A day later, I finally think I understand it. The solution isn't complicated, but learning about it was difficult for a few reasons:

  • Apple's "Authorization Services Programming Guide" is woefully out of date. It tells you to use AuthorizationExecuteWithPrivileges(), but that has been deprecated since OS X 10.7. It also has links to sample code that doesn't exist anymore. (Apple developer documentation people: It seems many of your docs are way out of date. Pls fix.)
  • Apple provides a SMJobBless sample that purports to demonstrate how to use the new SMJobBless() API that replaces AuthorizationExecuteWithPrivileges(). However, while it does indeed install some kind of service that could in theory run as root, the service it installs doesn't do anything, so it is useless as an example. (But you could waste a lot of time with it before you figure that out.)
  • A lot of old documentation and sample code for the original low-level XPC API is still floating around, but once you have a clue (which I didn't), you'll just use the high-level NSXPCConnection API.

So, in the hope I can help others avoid this tortuous path, here is how i would suggest others learn how to do this:

And here is what I wish somebody could have told me before I started:

  • What you will need to do is create a "helper tool" application to perform the privileged operations. This will be a command-line app that creates an XPC listener and handles requests.
  • The helper app has to have an info.plist and a launchd plist with some magical keys (see the EvenBetterAuthorizationSample for details)
  • The helper app will be embedded in the main app's package.
  • The main app will use the AuthorizationCreate() and SMJobBless() functions to authenticate the user and install the helper tool as a privileged launchd service. (This is the point where the system will display a dialog asking the user for an admin username and password.)
  • After the helper tool is installed, use -[NSXPCConnection initWithMachServiceName:options:] to connect to the helper tool. This will launch the helper tool on demand, running with root privileges.

Marathon Aborted

A few months ago, I signed up for the Chickamauga Battlefield Marathon, which will take place this Saturday (November 14). I thought I would have adequate time to train, but it hasn't worked out that way. I ran a half marathon last week, with a time of 2:30 (not great) and in my longer training runs over the past month, I've found that after mile 12, I have to do a lot of walking.

So I've canceled my hotel reservations and will not be running that marathon this weekend. Instead, I've decided I will concentrate on the half-marathon distance. When I get that down to around 2 hours, I'll start thinking about a full marathon again.

A Brainf__k compiler in C++

For fun, I wrote an interpreter for a programming language with a rude name, in C++.

It's available here:

There are other C++ interpreters for this language, but most of them look a lot more like C than like C++. My goal was to avoid archaic C-isms like pointers, fixed-size arrays, global variables, and the use of C stdio and UNIX functions, and write something that looks like "modern C++" (which may be an oxymoron).

C++ beginners may prefer to look at the code for a simplified implementation that represents my first pass at the problem. That is available here:

A collection of BF example programs is available here: It pleases me that the ones I've tried all work with my interpreter. The program is especially impressive.

Labor Day Run for Autism Half Marathon 2015

Today I ran the "Labor Day Run for Autism Half Marathon" at Fowler Park/Big Creek Greenway.

My time was 2:37. Not as good as I had expected. I was hoping for a time in the 2:20-2:30 range. I ran out of gas around mile 9, and walked a lot of the last few miles.

But, the November marathon for which I'm training still seems doable.

A Clock, using D3.js

Hey, look! I made a clock! The Apple Watch is now obsolete.

I am learning how to use the D3.js library to do data visualizations. It doesn't really make sense to consider hour, minute, and second as data to be "visualized", but this was a simple exercise to learn how to create graphical elements and animate them as the data changes.

If you're interested, you can click the JavaScript, CSS, and HTML links at the top to see exactly how it is implemented. (Note that JSFiddle is magically importing the D3 library, so you don't see that in the HTML.)

Here is another way to view the clock along with its source:

Syndicate content