Category Archives : Topics

SDL 1.2 Game Development   Recently updated !

I finally decided to sit down and learn game development. From my research there is only one way to do it, and that is SDL. If it’s good enough for Valve and Steam, it’s good enough for me. As it turns out, it’s surprisingly easy to get up and running with SDL. There are plenty of tutorials about the basic SDL game setup, so I won’t repeat the ubiquitous info and go straight to some basic problems of making a game that no one really seems to discuss. There are two main problems when designing a game: How do I save and restore game state? How do I make my game configurable? C is a great language for speed and algorithms, but it is really shitty when you want to handle data. Games are both algorithm and data intensive. So for half the game development, C rocks. But for the other half, it’s a slog. Saving and restoring game state means populating a structure in your C code with values from a human editable, dynamically loaded file. Things like the x,y or even z coordinates of the player in game space, their health, equipped weapon, inventory items and so on. One solution for solving this problem is to use some kind of config file format like INI, or XML. INI is a good choice for very simple games, and it’s dead simple to write an INI parser in C. The other common option is XML, which means something like libXML, which means I’d rather have […]


How the Knight Attacks

An intermediate introduction to chess

This article will assume that you understand the basic moves of each piece, that a pawn can move twice at the beginning, and only once afterward. That the pawn captures diagonal, or that the knight moves in an ‘L’ shape and so on. The most important shift in thinking about a piece is from how it moves, to how it attacks. In this sense, we think of a guard as any piece that is “attacking” one of it’s own pieces. Of course it’s not really attacking, but it is threatening an attack on any piece that attempts to take its compatriot. It is attacking an empty square in the sense that any piece that moves to that square will be attacked. Next to the Queen, the Knight attacks in the most directions, but it is shorter range than the Bishop. There are differing opinions about which piece is more valuable. The old belief is that the Bishop, which controls a diagonal is more valuable, however you can get stuck with a wrong squared bishop late in the game and his effectiveness becomes 0, whereas a Knight can attack the backrank of the opposing side within four moves. The Bishop is also powerful because novice players, including myself, have a tendency to think in obvious and straight lines of attack, therefore checkmates like this one are common. Here of course is another example using both the Bishop and the Knight. But notice that the Knight is the key piece that seals the deal. Personally I think […]

Learning to play chess at

Latest Game(2015)   Well, due to reasons I can’t really fathom, a loss of heart maybe, I stopped playing chess for awhile, but am back at it. I am only winning about 51% of my games there, I sunk pretty low(down to 690) but have managed to climb back up to 717 in blitz. For standard chess, my rating is 1365, but I’ve only played one game, which I won. I have purchased two books on chess, Mikhail Tals biography, and Robert Fischer’s My 60 memorable games(the newest one with updated notation). I am also trying to use the analysis board more often, and going through some grandmaster games, specifically Fischer’s but also any games showing the KID, which is my chosen opening to practice. I have decent results(50-50) with KID. I am also working on some learning aids, and thought I would share them. Instead of a new post for each one, I’ll just add them here at the bottom as I come up with them. The first one is for learning the squares and the algebraic notation.

Print this out and fill in the squares. Permission granted to use for education.

On Atheists and Objectivity

An atheist is very often a curious character for he removes all possibility of a subjective ideal, in that he worships only the objective and apparent, and an ideal is just too wishy washy for him to waste any time on. Is it any wonder then that clothes, cars, buildings, and art conceived by the atheist are so often very dull and pointless, as if they had no purpose at all except to be. The atheist must do something because he is afraid of doing and being nothing, which is the ultimate goal of his life, oblivion is what awaits us all he proudly proclaims. Much of what he is and produces merits it. It is a man overly concerned with his own sanity from fear of going insane. Of course what that sanity could be he cannot truly know, because he only knows and studies what is not sane, so everything that is not his current definition of insanity is precisely what he should do. That the atheist, or the honest one, cannot have an ideal is easy enough to prove. The atheist proclaims he only believes that for which there is objective evidence, since he cannot believe in an ideal because, objectively, it has no objective existence, cannot be measured in a lab, cannot be photographed by an electron microscope, then it cannot be ‘believed’ in. He may accept an ideal, or even follow one, but then he is hard pressed to escape his gross hypocrisy, for if you can create and follow […]

ANTLR4: So awesome it makes Java look good

I have been trying to write my own programming language off and on for about 5 years now. That doesn’t mean I have spent 5 years on a single project. Only that I have been toying with the idea and educating myself for that amount of time. Writing your own language is kind of the Holy Grail of computer science. Well, writing a language that is actually useful. Over the years, my experience in Ruby, PHP, C/C++, Python and even LISP, has informed my idea of what a good language would look like. Note I didn’t say perfect language. There is no such thing. I have come to believe that all languages are good in some way or another, and bad in other ways. Emotionally I like Ruby, and I like C. The elegant syntax of Ruby makes you happy to program, while the Do-Anything attitude of C makes it the ultimate language. I have been looking at Java( due to it’s cross platform nature ) and have to say at first I hated it. Now I hate it less. The number one reason I hate it less is ANTLR. I love the code generated by ANTLR because it looks like code that a human being would actually write. It’s very dense, but it’s alive. It’s hackish and clever. I have been following along the book The Definitive ANTLR4 Reference. This is a first time for me. Normally I, quite wrongly, just jump in and get it done. This time I am going to RTFM. […]


HTML5 Canvas: Smooth, variable width lines with transparency. 2

When making a drawing app with HTML5 canvas, you might come up against the problem of making a smooth, variable width line. Eventually you might find that you can make several calls to ctx.quadraticCurveTo(x,y,xc,yc) and get some kind of effect. If you stroke every 2 or 3 points, then as long as the line width is very small, you won’t notice the jaggedness. Unfortunately, if you try to do this with semi-transparent lines, the effect is truly horrible. To solve this problem, instead of drawing lines, I simply draw very thin shapes, and fill them with a color. This allows for 1) variable thickness and 2) nice transparency. Variable transparency is a problem I haven’t quite figured out yet. It may require composing the shape from individual pixels, which is simply too slow, especially in IE. What I am writing is a drawing App that works with the Wacom Web Plugin, and therefore varies line thickness based on pressure. I would like to vary opacity too, but this seems problematic right now. A solution that may be possible is to fill the shape with a complex gradient, if it is possible to create semi-transparent stops. Here is an image of what the program does so far:   Each line is actually a full shape, with varying degrees of opacity. Thickness and thinness is accomplished with pen pressure from the Wacom Intuous5 tablet. As the line is drawn, a temporary line is shown to the user, when they lift the pen, that line disappears, and a […]

HTML5 Canvas, Pixel Compositing, Transparency, and why all the trivia!

One thing I really hate about new technology are all the early adopters who incessantly post the same trivial examples. They cross link them too. So you can go from one page to the next, and see essentially the same example, just with the bits renamed or moved around. At a certain point, I got it into my head that I wanted to make a quickie HTML5 App that works with my Intuous5 Wacom Pad. Wacom has a web plugin that let’s you get data about pen pressure and so on from the tablet. So I started to work on it, and found the said trivial examples and started mashing something up. Pretty soon it became apparent that if I wanted my lines to look good, I might have to anti-alias them, or so I am trying, I don’t know if it will work, because I just spent the better part of 2 hours looking for a solution to a simple problem. If you look for examples of pixel level manipulation for HTML5 Canvas, you will find the same trivial examples over and over again, which basically say: var id = context.createImageData(1,1); var d =; d[0] = r; // where r is 0…255 … context.putImageData(id,x,y); If you actually want a full trivial example, use google, they abound. The problem with the above is: it replaces the entire pixel, all the way to the background, erasing any colors beneath it. The alpha channel of the pixel doesn’t make it transparent to what was under the […]


Backbone.js + Rails 2

You all know that my opinion of Ruby On Rails couldn’t be any lower if it was under the basement carpet of a Pompeii1 house, so this post won’t be very suprising. So, awhile back I was having a discussion with a  friend about how, as a general rule, about 90% of a web app should really be taking place on the browser, and this was vindicated in my opinion with several other developers coming to much the same conclusion and releasing some very interesting application frameworks for javascript Single Page Applications. Of course this conversation took place when jQuery was just really starting to take off. The problem at that time was that no one was really talking about a client side application in javascript methodology, how such a thing could or would work. In hindsight it all seems obvious, but actually, Backbone and other such frameworks represent some really great out of the box creativity. Anyway, after my last Rails project, I more or less swore I would never work with that ass backwards platform ever again. I decided to revisit this idea of Single Page Applications and low and behold I stumble onto Backbone.js, and I decide I am going to learn to use this tool. While looking around for some books on the topics of jQuery and Backbone (I’ve more or less decided to give up the ghost and use jQuery ui elements in all future applications cause rolling your own is just too much work.) low an behold I find […]

Parsing infix to postfix in C++11

Pursuant to my interest in programming language design, I have been giving a lot of thought to mathematical expressions. Making sense of a mathematical expression written by a human is difficult from an algorithmic point of view. It’s certainly not impossible. Humans read and write mathematical expressions in a notation called infix1  however this requires sorting operators by precedence2, which humans are very good at, but computers not so much. To be able to do it, a computer has to first parse and identify all parts of a token stream until the end, and then group those parts, and then sort them based on the operator precedence. That’s an awful lot of work. There is however another type of notation[actually there are several.] called postfix3 which is very easy for a computer to operate on because each time it encounters an operator4 it simply collapses the last two numbers and replaces the operator with the answer. In this way the token stack reduces to a single number by a series of linear actions requiring no lookahead5 or knowledge of what is to come. I decided today to implement a mini calculator language that takes an infix expression6 and returns the value after parsing it into postfix to operate on it. Here is the code: #include #include #include #include #include #include template void puts(T x) { std::cout << x << std::endl; } template std::string ToString(T i) { std::string dest; std::stringstream ss; ss << i; dest.assign(ss.str()); return dest; } double ToNumber(std::string& s) { return atof(s.c_str()); } bool […]


Looking up variables based on a context.

The general caveat for all these articles I am writing on Programming Language Design is: I don’t know. I am just messing around and trying to figure out how they work and how they can be implemented. The internals of most programming languages are scurry scurry1 places. When you read the source code for say the v8 engine you are struck by the apparent elegance of its design, it’s quite fun to read the source, and you can even abstractly understand what it going on. But an abstract understanding is not the same as a pragmatic understanding. Pragmatic Understanding To see if you have a pragmatic understanding of something, unplug your computer from the internet, then write an algorithm or program in your preferred language that implements that understanding, accepting a series of inputs and consistently producing the expected outputs. You can only use printed references that detail libraries, i.e. you can look up the details of some STL functions and the like. When you can do this, you have a pragmatic understanding. It’s easy to describe the process of creating a programming language like this: Well, first you scan for tokens, then you create a parse tree, then you navigate that parse tree and either a) emit byte codes or b) execute core functions.2 Nebulous Bit The Nebulous Bit® is not really a single thing, but a grouping  of things3. We can look at it a bit like an engine. In most programming languages you have the Byte Code Emitter(Fuel injector), The Virtual Machine(The […]