August 23, 2009Javascript Reversi
Here is Javascript Reversi, an exercise in a basic turn-based board game. The computer player limits itself using wall time, so the faster the Javascript interpreter, the stronger the play. On Chrome, the Javascript opponent can beat me (though I am a very poor player). If you know how to write a good reversi position-evaluation function that would make the computer stronger, please let me know. Posted by David at August 23, 2009 09:21 PMComments
Flash is tough, but personally, I don't typically view Javascript as being much better. I mean, the reversi example requires 500 lines, and the use of two separate, somewhat clunky models -- one fragile document model (HTML), one not-terribly-intuitive abstract OO model (Javascript). For most people, you need to dive into a serverside technology and database to make JS worth using. Not that it can't do neat stuff on its own, just that most people view things like AJAX as worth the price of admission. And that's skipping over the use of JQuery to make the language palatable. (Which isn't and shouldn't be a dealbreaker -- everyone's got their stdlib. But still.) I think my 8-year-old self would still take QBASIC over JS. I have hope that the additions to HTML 5 will make simple procedural graphics easier, and it might solve some of the quibbles I have. But it's still a lot harder to go from nothing to something you want to do a second iteration of -- something that looks "grown up" -- in JS. All this said, I think you're right -- there's no language except JS any more that's more or less an out-of-the-box experience. I want to say Ruby on OS X, maybe, but even it's a stretch. Graphics and "game" programming are bigger deals to someone first getting into writing code, and as it stands, I really can't think of a single language where this isn't a huge pain in the ass. Posted by: Josh at August 24, 2009 03:17 AMIn terms of lines of code, Javascript isn't that bad - here's an QBasic Othello for comparison - at 488 lines, it's about the same size. It is more straightforward but less ambitious. http://tinyurl.com/n7xlo8 Maybe the problem with Javascript isn't the lack of specific technology like procedural graphics or persistent state, but the lack of the ability to do blocking programming - the equivalent to QBasic's "INKEY" or "INPUT". Javascript forces you into event-based programming from the start, which seems like it requires more planning. On the other hand, my son is doing great things in Scratch, which is also an event model. Also, in Scratch, he almost never uses line-drawing graphics, preferring to just move sprites around the screen. I wonder if it would be possible to make a javascript library that would give Javascript a Scratch-like accessibility for kids. Hey David, I'm trying to write some js games too, http://stcamp.net/games/sudoku/ and I'm kind growing a js-library that supposed to help in this process. Maybe you will take a look when you have time http://rightjs.org it is much faster than jquery, has advanced OOP features, plus things like observers, options, Array#shuffle etc. Just thought you might be interested, Post a comment
|
| Copyright 2009 © David Bau. All Rights Reserved. |