Chess By Blog 1.0.1

June 24th, 2007 § 6 comments § permalink

A new release, fairly minor. Here’s what’s changed:

  • Now compiled with Google Web Toolkit 1.4 Release Candidate. This automatically fixes the issue whereby viewers can get to your blog from different addresses (i.e. http://levork.org instead of http://www.levork.org) fail to see the chess board due to the Google Web Toolkit’s enforcement of the Single Origin Policy. There are also some speed and size enhancements that automatically come along with the upgrade.
  • The “bouncy resize” of the initial board seen by users of Internet Explorer 6 and 7 has been addressed.
  • In closed games there is now the ability to offer, accept or refuse a draw; also to resign.
  • Games which end in a draw, stalemate, checkmate, or resignation now automatically update the “Result” tag in the PGN.
  • An issue where “+” and “++” was stripped out of the PGN has been fixed.
  • The PGN parser was unable to handle moves ending in ‘=’ (indicating stalemate); now fixed.
  • The one-hour timeout between page view and move post is now reset with each move.

Here is the Chess By Blog blurb page.

Here’s the download – ChessByBlog-1.0.1.zip, 206 KiB.

Please post any questions or issues in the comments. Happy chess playing!

Chess By Blog 1.0.0

April 20th, 2007 § 7 comments § permalink

I think it’s ready for release!

Here is the Chess By Blog blurb page.

Here’s the download – ChessByBlog-1.0.0.zip, 212 KiB.

Please post any questions or issues in the comments. Happy chess playing!

Chess with the Google Web Toolkit

April 1st, 2007 § 2 comments § permalink

Screen capture of Chess applet written with GWT

My brother-in-law and I have been playing chess by e-mail for the last few months. This has been less than optimal: we use the old style English notation rather than algebraic notation, and he sets up a real board while I use Apple Chess, so there’s always some transcription from mail to board. Invariably one of us (usually me) gets something wrong, and we end up backtracking through mail history or making a stupid move that we didn’t intend.

We looked at web interfaces for chess by e-mail gateways, and none of them worked out acceptably for both of us. So finally I decided I’d program something. I decided to put together a client side using the Google Web Toolkit; I plan to integrate the back end with WordPress as a PHP plugin.

The Google Web Toolkit (GWT) is pretty neat, even without diving into all the AJAX/RPC stuff which I might not need for this project. You program the client side in Java, using the GWT-supplied emulation of java.lang, java.util, plus their own classes which provide UI elements and control over the browser object model. During development, the GWT environment runs your code in a Java-enabled hosted browser; once done, it compiles your code into browser-specific Javascript. No Java plugin required.

The result of hacking this weekend: a Chess applet that runs in a browser. The applet itself is about 61 KiB depending on browser, plus 16 KiB for Google-supplied base code. You can play a new game on a blank board here. All chess rules except for pawn promotion are handled, including en passant and castling – you shouldn’t be able to input an invalid move. (If so, it’s a bug! Please let me know.) It should detect check, checkmate, and stalemate (by lack of move) correctly, and the game log should be maintained in proper algebraic notation. The applet can also load a movelist in PGN format (or at least a good subset of it), embedded directly on the web page – for example, here’s Fool’s Mate in 4 moves, view the page source to see the original PGN. For a more interesting problem, here’s Reshevsky vs. Fisher, 1970, black to move and win.

I burrowed the icons from XBoard, themselves generated from a METAFONT font. I noticed Wikipedia has SVG versions derived from same.

The Google Web Toolkit does have a few quirks. No java.util.StringTokenizer, but String.split sort of covers that. It also doesn’t completely cover cross-browser issues. I noticed some differences between regular expression handling (or maybe it was actually newline or whitespace issues in TextAreas), and because of Internet Explorer stupidity (lack of CSS support for min-width), and because I couldn’t figure out how to size an element after an image had guaranteed loading, I couldn’t successfully achieve my goal of getting all sizes and images controlled completely by a style sheet. I still have a ways to go before the client UI is as clean as I want, and with all the chess rules pushed to the client side, it isn’t as optimal as it should be. For example, you may have gotten a script incomplete warning while loading the last page: it’s churning through a lot of possible moves while dealing with PGN notation. Then there’s figuring out how to integrate this all with WordPress properly. Once this is all done though, David and I can finally be rid of my KP1-KP3 gaffes.

Thursday, March 11

March 11th, 2004 § 0 comments § permalink

New l2rib release! I should win some sort of award for rampant abuse of RiTransformPoints for it. Now that the more egregious bugs are fixed, maybe someone will actually send me a picture rendered using this thing.

Thursday, June 5

June 5th, 2003 § 0 comments § permalink

Since I graduated from David Thompson ten years ago this month, expect maudlin reminiscing about high school over the next few weeks. I expect commentary from anyone involved. (You know who you are.)

My mom’s kept around a lot of my papers from around that time which I asked to be shipped down when I moved to Seattle. When I finally started sifting through them lately, I came across the following gem: my Computer Science 12 grades, first time around (I took it in grade 10).

Playing Scrabble with high school comp sci grades

I’d totally forgotten about this. I’ve been trotting out my linear algebra grades in university as an example of my academic ineptitude, but I think this takes the cake. So what happened? Well, I didn’t quite “get” functions back then. I’d aced CS 11 the year before, and what little programming we’d done was accomplished in QuickBasic, without ever using functions – not that this wasn’t possible in QuickBasic, we just never got around to covering that subject. So when we were introduced to Turbo Pascal in CS 12, I just could not make that mental leap to the world of FUNCTION and PROCEDURE. Why on earth would people need to write code this way?

This sounds enormously stupid twelve years after the fact, but that really was the turning point in that course for me. After I got stuck on functions, I more or less gave up. We never even got close to using the object oriented features in Turbo Pascal so I don’t recall what else was covered. It couldn’t have been that much. (Bubble sorting?) I guess it didn’t help that I think I skipped more than half of the classes towards the second half of the year. There’s certainly no way I only missed zero and two days in the second and third terms like my report card says. We’d worked out a system where someone else would say “Here!” when Mr. Turley did roll call. I don’t think he noticed – or more likely, he just didn’t care; there were at least four of us gone each class, all of sitting consecutively in a row next to the printer right next to the teacher’s workstation.

Two years later I did take CS 12 again and more than made up for that glaring ‘P’ on my transcript. In between though, the curriculum hadn’t changed a single bit. (Thankfully, it was a different teacher.) So I ended studying for the AP exam on my own – and the AB level of CS tested some basic data structures, which involved this trivial middling concept called “pointers”. Yet another gigantic stumbling block for my addled brain to deal with. Why would anyone want to know the address of a variable when they already had a name for that variable? Why on earth would people need to write code this way?

Ever hear those programmers who claim they’ve been hacking on computers, ever since elementary school? And how it came naturally to them? Well, that sooo wasn’t me. It was uphill all the way, baby.

Monday, October 14

October 14th, 2002 § 0 comments § permalink

Anyone looking for l2rib should note that I finally fixed the download links. The files they used to point to were certainly present on mac.com’s disks, the corresponding web service was just refusing to acknowledge their existence – until I shortened the filenames. Sorry about that.

By the way, I’m also aware that the address www.levork.org/l2rib.html actually doesn’t point at the right page; it gets you back here. Unfortunately I can’t do much about that for now – the URL redirection service at register.com isn’t very intelligent.

So, has anyone besides me actually made a picture with this thing?

Row and Column matrix conventions in RenderMan

February 7th, 2002 § 0 comments § permalink

I am the very model of a modern Major-General,
I’ve information vegetable, animal, and mineral
– The Pirates of Penzance, Gilbert & Sullivan

Judging by the documents on the Web and on USENET that claim or deny that RenderMan and OpenGL share the same matrix conversions, there appears to be some confusion about matrix convention ordering in RenderMan – even among people who should know better. This is an attempt to clear that up.

RenderMan assumes points are row vectors

First of all, the RenderMan Interface Specification assumes points are row vectors. This affects how the matrix looks in its mathematical form on paper. In this convention, when multiplying points (in the mathematical paper sense), the point goes on the left as a row vector, and the matrix goes on the right. This also means that the translation part of a transformation goes on the bottom:

|sx 0  0  0 |
|0  sy 0  0 |
|0  0  sz 0 |
|dx dy dz 1 |

Note that this is NOT the same convention used by modern linear algebra textbooks, Foley & VD (2nd edition, not the 1st), and the OpenGL documentation. It is the same as Newman & Sproull and many other older, but influential, graphics text books.

RenderMan uses row major ordering

Row major ordering means that the matrix is stored in memory such that row elements are packed together contiguously – i.e. a float m[16] would correspond to the matrix:

|m[0]  m[1]  m[2]  m[3] |
|m[4]  m[5]  m[6]  m[7] |
|m[8]  m[9]  m[10] m[11]|
|m[12] m[13] m[14] m[15]|

Whereas in column major mode, it’s the column elements which are packed together contiguously:

|m[0]  m[4]  m[8]  m[12]|
|m[1]  m[5]  m[9]  m[13]|
|m[2]  m[6]  m[10] m[14]|
|m[3]  m[7]  m[11] m[15]|

C programmers are probably more comfortable with the former representation, because multidimension arrays are indexed in the same sort of order in memory. That is, as the memory address increases, the rightmost subscript increments the fastest. Thus, in a float m[4][4], m[0][0] and m[0][1] are next to each other. On the other hand, Fortran programmers are more comfortable with the second, because as the memory address increases, the leftmost subscript increments.

This gets us to OpenGL. OpenGL uses column major ordering to represent matrices in memory. I believe the only time you really need to worry about this is if you pass a matrix directly to OpenGL using glLoadMatrix or glMultMatrix; you’ll have to pass in 16 numbers in column major order.

The RenderMan C API binding, on the other hand, uses row major ordering. This is most obvious in the RIB binding for RiConcatTransform, where the 16 elements are passed in using row major order.

So if you’re using RenderMan, and you’re a C programmer using the RtMatrix type, it should be straight forward to think of an RtMatrix m corresponding directly to the mathematical representation:

|m[0][0] m[0][1] m[0][2] m[0][3]|
|m[1][0] m[1][1] m[1][2] m[1][3]|
|m[2][0] m[2][1] m[2][2] m[2][3]|
|m[3][0] m[3][1] m[3][2] m[3][3]|
      

But it’s all the same thing in the end!

It is somewhat surprising to learn, given all of the above, that the exact same code can be used in OpenGL to multiply a matrix and a point as can be used in RenderMan. Observe that in RenderMan, you have:

                    |m[0][0] m[0][1] m[0][2] m[0][3]|
v[0] v[1] v[2] v[3] |m[1][0] m[1][1] m[1][2] m[1][3]|
                    |m[2][0] m[2][1] m[2][2] m[2][3]|
                    |m[3][0] m[3][1] m[3][2] m[3][3]|
    

whereas in OpenGL, you have:

       |m[0][0] m[1][0] m[2][0] m[3][0]|   |v[0]|
       |m[0][1] m[1][1] m[2][1] m[3][1]|   |v[1]|
       |m[0][2] m[1][2] m[2][2] m[3][2]|   |v[2]|
       |m[0][3] m[1][3] m[2][3] m[3][3]|   |v[3]|
    

Note that it would end up being the same code in both cases. So RenderMan does work just like OpenGL, internally. It’s just not very obvious, and you need to be careful about how you present your matrices to each respective API.

Monday, November 12

November 12th, 2001 § 0 comments § permalink

I’ve been trying to learn – really learn and understand, not just use ineffectively – the monster that is the Standard Template Library. The fact that the mud is written using STL classes doesn’t mean squat as far as my real understanding of the STL goes. Meyer’s latest book is helping a lot, and getting me past that “Ohhh, I get it” stage, but still, I have to wonder – is this:

for_each(fCharacterAffects.begin(), fCharacterAffects.end(),
	 bind1st(mem_fun(&Character::removeAffect), target));

really so much better (readable? maintainable? understandable?) than the following?

for (vector<CharacterAffect*>::const_iterator i = fCharacterAffects.begin();
     i != fCharacterAffects.end(); i++) {
     target->removeAffect(*i);
}

Wednesday, May 30

May 30th, 2001 § 0 comments § permalink

I have been trying not to be an utter nerd in this forum, but I feel a welling of nerdality overwhelming me today, and I feel helpless to resist. Non nerds may want to ignore the rest of today’s ramblings and check out some cool pictures of Da Vinci’s Last Supper, post-restoration.

Nerdaciousness again – I’ve been stuck on two programming problems over the last week:

1. Getting the Ethernet address on an IRIX box without spawning another program or requiring root privileges. (This is work related – I need to generate UUIDs.) It seems that on every other UNIX I care about, a couple of ioctl calls will extract the necessary information. On IRIX I can only accomplish the task by calling ioctl(SIOCGIFADDR) on a socket of type SOCK_RAW, opened with the RAWPROTO_SNOOP protocol – and this requires root access. This is, of course, completely ridiculous.

2. My TWAIN-somewhat-compliant app (I have been trying to write a tool to help with claymation) can’t acquire any images from the webcam. I’m at the stage where I’ve just enabled the data source (TWAIN-speak for the webcam), and the UI for the source has popped up on screen, but in the app event loop I never receive events from the source. I know next to nothing about Windows and MFC programming (I’m not even sure I’m checking the message loop in the right place) so I’m at a dead end.

I’m happy that I have some issues to be stuck on, though. I’ve been creatively blocked, programming wise, for the last two months – the MUD and the l2rib projects have been in limbo, and work has been spotty as well in that aspect. So the fact that I’ve now unblocked to the point that I’m only stumped by two measly issues – well, that seems to be an indicator of progress.

It looks like google has finally indexed me, so perhaps some random person will drop by, know the answer to one of these questions, and be a kind enough soul to share the information. That would just make my day.

Friday, September 8

September 8th, 2000 § 0 comments § permalink

jfong@playerkill.com now works. So that’s now what all my outbound mail reads, including mail sent to Pixar folks today (but no one has yet commented. Wusses). I had to settle on using exim since sendmail was beyond what my little head could handle.

Getting mail working was motivated in part by my offering web hosting for small Tom (as opposed to big Tom, mentioned in previous entries; both are coworkers of mine), and ensuring that sufficient services were installed to taste. This eventually involved figuring out the intricacies of setting up python, Zope, and various odd bits of Apache. Eventually (once granitecanyon.com comes back from the dead) Tom’s site will be at www.monkeyspeak.com.

Was dorking around this week with writing CGI scripts at work in an effort to look busy and actually came up with something useful and work related – a tool to generate and maintain a FAQ via the web. Also bought a MySQL book recently and am entertaining outlandish thoughts of hooking up the mud to a MySQL backend. Ryan has mentioned there is money to be had in doing web related projects, and if I was apt to be motivated by dollars I’d be probably be looking more into webbish things. Although already with the CGI and SQL stuff it’s proving more fun than I thought it’d be.

Where Am I?

You are currently browsing the programming category at levork.org.

  • Pages

  • Archives

  • Categories

  • Flickr