Thursday, February 11, 2016

Boxes not overlapping


Adding to yesterday's demo, the boxes are now a couple different colors, still moving around. Now they bump into each other and use a simple constraint system to ensure that they don't overlap.

Also, I added some fixed boxes in the world that boxes might move around. Except they're not really smart enough to do that yet. Sometimes, they knock each other loose.

TODO: make stuff smarter.

Wednesday, February 10, 2016

Something a little different


This doesn't tie in to my previous posts, really. Just screwing around, getting a PyGame / OpenGL framework up and running.

There's a few boxes moving around the screen. So, that's something.

Friday, February 5, 2016

Spaceship Flying In Space

Back in college, before I knew much about anything, I gave a resume to a tiny little company called HDC Computer Corporation. That name kind of pegged them (constrained them?) to be a Microsoft Windows development house.

They managed to get some of their stuff bundled into Windows-286, if I recall correctly, including a little space shooter game called "HDC Rocks". Yes, it was about shooting rocks in space. Also, the title was a gag and tongue-in-cheek motto.

The Internet doesn't seem to remember that little nugget, but maybe it will now.


What you see here is the rebuilt version of as far as I had got on my "Space Rocks" demo - a little space ship moving around on the screen, rendering in OpenGL 2.1, with a window provided by SDL2.

Nothing's particularly exciting about it - the pathfinding, if you can call it that, is "move horizontally, then move vertically". There's no real obstacles. It doesn't have a lose condition.

But it's running again, OpenGL commands, as issued from my language, sent through a C shim to a vanilla OpenGL implementation.

As I mentioned in my previous post, I had lost a file (failed to check in my work) called gl_tools.c, which contained that layer, so the effort necessary to reproduce it was simply(?) a matter of exporting GL calls down into my library.

Sort of. The time management code is coming from SDL, so that took a little more attention. The initialization of an OpenGL context isn't quite as simple as I had recalled. I made use of Lazy Foo' Productions' SDL/OpenGL tutorial to figure out what bits I really had to rebuild inside my shim library.

And there you go, it's working again. And checked in, besides.

I even made myself a little convenience tool that launches the program, records frames of it rendering, then compresses that into an animated GIF all in one handy script. I could make it slightly cleverer, by forcing the window to open up at a particular point on the desktop, which would keep you from looking at my emacs window in the background. But maybe emacs makes you comfortable. I wouldn't want to deprive you of that.

The cursor, though, not so sure about that. I could easily suppress the cursor.


So. The demo is back up and running, and the thing I was running into back in July when I last checked stuff in (I don't remember this stuff, but GitHub does) was that I wanted to have a solid story about what I was doing with arrays of complex objects (like structs, say, like you might need to have for a bunch of asteroids floating across your screen). Would arrays have to be statically allocated? What's initialization like? Am I going to have pointers to these things? Python and Java don't have pointers, except that they do, but you don't see them. Is that what I want?

I want to avoid copying complex objects except by explicit deliberate action. It feels like there are a few other choices that can come as a result of that, but I haven't really meditated deeply enough to make it obvious how things ought to work. Perhaps the next step is to try some stuff, and be prepared to roll back if I don't like how things are working.

Wednesday, February 3, 2016

Setbacks, and starting not from scratch

So, it's been a while since I've posted about my compiler project. Projects being what they are, you don't always have steam for everything.

And then, a few months ago, the laptop where I had been doing my development was taken. I can curse the darkness, but it's not as bad as it might have been - I had most of the project checked in to two offsite locations. So, that's nice.

At the risk of Pollyanna, this is an opportunity to verify that I don't have hidden dependencies that I wasn't aware of. So, I'm starting on a new machine, and hopefully, I'll be back to productivity soon.


I've added a Prerequisites page to my development Wiki. (Is that external? I forget. Probably not, or I'd link here.) It's the stuff you'd expect:

  • LLVM 3.6
  • libedit-dev
  • enum34
  • llvmlite
  • PLY
  • emscripten
  • SDL

Ok, maybe not all of that is expected. I think llvmlite's dependencies could be tidied up. And maybe I don't need SDL for everything, but for the Pong sample app, I did.

Once I got stuff installed and cloned the repo down onto my machine, I built the pong demo as a local executable, and it worked great.

I haven't yet rebuilt the web version, but you can play it here, if you like: http://bigdicegames.com/BDGRT/Pong/pong.html - I just link it because I keep forgetting where it is, so this is a bookmark for my own purposes. Also, I notice that that doesn't play nicely with my (current) version of the Chrome browser, but it does in Firefox.

Looking back through my checkin log, I see that I had been doing work on my Asteroids tribute sample, but when I try to build it, it looks like gl_tools.c never got checked in, so I get to rewrite that. How hard can that be? Just wrapping stuff like gl_begin and gl_color3f. I should be able to knock that out in short order, maybe tonight.

I'm also noticing that building emscripten targets (like the web version of Pong) is failing, probably due to not having installed certain bits of emscripten.

But, I'm delighted to say that my little test programs for computing factorial and Fibonacci stuff worked just fine.




Wednesday, December 30, 2015

I've got a lot of books here.



Over the past week or so, I've taken 5 boxes of books to Half Price Books and just now filled another box to go out the next time I'm headed in that direction.

I like books. I like reading books. I like collecting books. I have maybe too many books. I have books that have perhaps been a fire hazard, making easy escape from my house a difficulty in case of an emergency. I have more than once bought a duplicate of a book, either because I've bought it already and forgot, or I just couldn't find the original.

Years ago, I thought it'd be good to organize my books by Dewey Decimal, oh, or maybe Library of Congress. Or maybe some sort of hierarchical tag-based scheme that I never got around to fully exploring. Now, I'm just happy if I can keep track of my books. 

I have a Google Drive Sheets spreadsheet, which is super handy - I can check it while I'm at a bookstore and see if the book I see in front of me is also waiting for me at home. This has already been a benefit.

But it's kind of ponderous - it's just a big list of stuff, and there's not a good way of identifying where a book actually is. (Organization.) I might also like to have a list of all my GURPS books, or when I get a new Kakuro puzzle book (I shouldn't be buying more of those), it might be nice to put it near the other ones of its ilk.

Also, barcode lookup might be nice to support.

So, I've been writing a tool.

Starting with web.py, and using MySQL (for now?), I started manually pulling individual lines from my spreadsheet in. The database knows that authors and ISBNs exist, but the web app has no way to display or edit them. But there's enough to start pulling one line at a time over from my spreadsheet.

Some(!) of my books are in boxes, and each box has its own ID. Each room in my house has its own ID. My house has an ID. So, there's a chain of containment there - such and so book might be in such and so box, which is in such and so room which is in my house. There are container links up from each item, and the web app is smart enough to do a select if I want to know what the contents of a specific box are. I've started printing out listings for the contents of boxes as I do my inventory - easy, just click the "contents" link off the box listing, and hit "print".

The web app does allow for me to use my fancy barcode scanner, storing UPC data for whatever items I feel like tagging. So far, it does nothing with that UPC ID, but I'm planning on doing an automated fetch from isbndb.org and making that data available.

I just now put in a facility where I can search for title substrings. So, if I ask for "gurps", it lists all the GURPS books I've entered so far (only 14, I'm just getting started). And when I ask for "apple", I get 21 hits, all for early '80s stuff. 6502 only hits 5 titles so far.

One thing that this should do is reach back to the Google Drive Sheets spreadsheet and mark which items in my spreadsheet have been added to the web app. And if I add a thing to the web app, it'd be nice if the spreadsheet reflected that without having to enter it twice. And maybe, it'd be nice to import from the spreadsheet, but if that's a lot of work, I'm OK with doing a manual inventory anyway, since my spreadsheet doesn't have a lot of UPC data, which I kind of want to collect at some point.

If you look carefully at the screenshot at the top, you'll see 4 digit IDs. That's not because I've catalogged more than 1000 items (well, actually, I have, but that's not why). It's because I had some idea that I'd use the thousands place to denote the type of object - allowing me to have enumerated categories for furniture, rooms, boxes, books, games, and other things. That categorization scheme has sort of fallen apart, but I might go back and rebuild it later, now that it's easier for a bit of code to enforce that sort of thing. Or I might ignore it, now that I've got code that makes it easier to filter and search.

Once I've got it reaching out and writing back to my spreadsheet, the next logical thing to do would be to reach out and write to a BoardgameGeek list, so my games would be listed there. But just games. Again, software is smart enough to mostly get that right, probably.

Also, maybe I could go back to my LibraryThing account and update my booklist there. 

Sunday, December 13, 2015

Clerics & Codenames, v0.0.2



Back in late October, I played a game of Codenames by Vlaada Chvátil. I was impressed with how much fun it is, how challenging, how much the words stuck in my head afterward, and how simple a game it seemed.

I appreciate that when somebody is really good at their art, they can make stuff that looks simple, even if it takes a lot of work, so to say that it seems like a simple game isn't meant to diminish it - it's elegant.

I also wondered how much work it'd be to make a playable set of expansion cards. I had a bunch of questions - should you go for simple words? Just nouns? Would choosing words from a theme make sense? (Star Wars? Computers? Geek Life?) Or would that narrow the range of possible connections too much?

I poked around, looking for word lists of common words (inspired by Randall Munroe's Thing Explainer, which also inspired Space Weird Thing, which is awesome, but is only super loosely connected to the game I was talking about), but couldn't find a list I liked, so I set things aside for a bit.

Then, last week, somehow the idea of taking a bunch of words from fantasy role playing games might be a place to start. I went back to a couple of the works that made an impression on me at an early age, the Holmes edition of the Dungeons & Dragons ruleset and B2 - The Keep on the Borderlands. Skimming through there (and paying particular attention to glossaries), I came up with many words that were burned into my brain first through Dungeons & Dragons.

Those words went into a Google Docs Spreadsheet (er, a Google Spreadsheet as hosted on Google Drive?), which I then exported as a CSV file.

Using Reportlab and PIL (actually Pillow), I made a PDF, which I printed out on cardstock:


I invited a few of my coworkers to sit down and see if a strongly-themed cardset would actually be fun, and I was surprised first by how enthusiastic people were, and then I was surprised that it played really well.

Some of the feedback included:

  • randomize the cards, because we had a bunch of 'h' words, followed by a bunch of 'c' words. Shuffling home-printed cardstock cards is challenging.
  • wouldn't it be awesome for the red and blue 'cover' cards from the Codenames set were also themed?
  • remove words that are too close in meaning. e.g. 'cave' and 'cavern', 'vial' and 'phial'.
  • rework the script so that the fontsize is consistent from card to card
  • I would totally buy this on DriveThruCards
  • Maybe this should be posted on Board Game Geek 



So, stuff I've done today:

Script rework. I reworked my Python script to generate either letter (print and play) or mini-card (Drive Thru Cards) page sizes. Reportlab's canvas object defaults to letter, but you can pass in a pagesize argument.

I pulled the UniversalisADFStd-Regular.otf file into fontforge and exported it as a TTF. This made Reportlab happier with the file, as the outlines were in a format that it liked. (Known issue, they're in no hurry to support Postscript outlines, or something.

In my 1st printing, I had worked around the OTF limitations by using Pillow to create an image just large enough to hold the text, rendering the text to an in-memory image, then using Reportlab to insert that image into my PDF. Now that Reportlab can render the text directly, I can skip Pillow for this, which fixes the odd sizing artifacts that I was seeing - for some words (ones with descenders, I think), the images were sizing differently from others. Now, since I'm not using images, the font sizes don't have that step to cause strange behaviors.

Randomized the cards. For the first image (above), I wanted to make sure I could easily find "dungeon" and "dragon", so I sorted the words. This led to a whole bunch of the same first letter. This will be solved, in time, when I get better printed cards. Until then, I might as well shuffle the words before creating the PDF.

Custom Red & Blue cards. I've made some solid color cards, as well as some temporary placeholder themed cards using copyrighted content that I cannot distribute. Red and Blue line up nicely with that particular content, though.

Word curation. I got rid of 'cave'. I added 'sepulchre'. I should probably spell that the way any good United States citizen spells it. Oops. Also forgot to remove 'phial'.

Printed out a new playable set:


I haven't got my print settings set up right - the cards aren't lining up front-and-back the way I had intended. Not a huge thing, totally playable as-is, but if I wanted to distribute this as print-and-play, I'd want to make sure that it's possible to line up the cards.

Board Game Geek posting. I have had an account on BGG for years, mostly using it to read reviews. I found the link to create a new listing for a new game, which itself depends on a BGG page for designer and publisher, so I created new listings for myself and for Big Dice Games. It's like I'm a real boy!

All of the above are under review. I think that's a good policy. If it were faster, I'd include a link here to my listings.

DriveThruCards listing. As much to test out the process (is the PDF I generated from ReportLab the right flavor of PDF that DTC is expecting?) as anything, I made a listing of this on DriveThruCards. This required setting my account up as a publisher account (whee). It also required a cover image, which I made by cropping the above photo. Good enough for a work-in-progress.

Apparently, it passed the simple checks to get to the point where I could order a proof, so I have. I'm eager to see if it prints without errors, and if it gets to me before I'm on vacation.


Feels like a lot, and this is for a trivial little expansion to somebody else's game. But it's fun to play, and it's been fun to go through the process. 



Sunday, November 29, 2015

Extended Range, at the Ready.

So, back in High School, I played a bunch of the "Star Wars Lightsaber Dueling Pack" by West End Games. It's a two player diceless combat system, where one player plays Luke Skywalker, the other player plays Darth Vader. Both players simultaneously select moves from a movement reference card keyed to their player (Luke selects "Jump/Dodge [8]" , Vader selects "Hurl Objects [24]"). The cards direct you to pages in combat books, which then dispatch based on the pair of actions, and the players end up looking at pictures of what their character would see, along with points (maybe), and instructions for their opponent. In this example, Luke manages to avoid the projectiles, and the combatants face off at extended range for more combat.

(from page 49 of the Darth Vader book. I claim "Fair Use", since it's a small portion of the original work.)

In college, I took a game theory course which touched on the traditional payoff matrix analysis, but spent a lot of time on combinatorial game theory. I guess if Berlekamp is teaching, you're in for a course on nimbers, tiny, spiny and any number (ha) of other esoteric concepts.

As a project in that class, we had to analyze a game. I selected Star Wars Lightsaber Dueling Pack. I'm going to call that Saber Dueling, because the full name sounds dumb. I wrote a C program to generate a payoff matrix for Saber Dueling, but I think I trimmed a few of the details. (For instance, you can dislodge an opponent's weapon, but I don't think my program represented that.) I ran into a few weird scenarios, probably due to oversimplifications. (In the example above,  Vader ends up at extended range as part of the basic logic, but Luke only ends up at extended range based on conditional logic that I probably didn't implement. If you don't get that right, Luke's close to Vader, who's far from Luke. Whoops.)

I had something like a 32x32 array of integers (probably 8-bit integers, because I was stingy back then) and I jammed that into the minimax algorithm that we had been taught on the one day of class we weren't doing the combinatorial Berlekamp stuff. And I came up with a mixed strategy for playing the game. And I forget, I probably got an OK grade on the project.

And yet, it wasn't really satisfying. I had drained out a bunch of the character of the game in the simplifications I had made. I mentioned losing your weapon. It's kind of important to know that you don't have a weapon in order to select good moves. There's a "Retrieve Weapon" action you can take, but it doesn't score you points, so if you're just looking to maximize the points you score on this turn, you'll overlook it, even if the representation is there.

Another simplification that I had made was to skip over the move restrictions and bonuses. Each move leaves you (and potentially your opponent) in a situation with potentially only a subset of moves available. If I knock you down, your next move has to be a jump. If I know that your next move has to be a jump, I don't have to defend against a downswing - I might restore some hit points, or something. Maybe choose an attack to hit you when you're down. Restrictions are important, but my college project skipped all that.

Years later, and this is perhaps not central to any particular narrative thread that I'm spinning, I had a dream where I was at some sort of gaming convention. I forget if this is the same dream that featured "Cremwits", which I might post about at some other time. This was a convention maybe something like GenCon, which I've never been to. Picture a bunch of folding tables with hard to find, rare, possibly out of print games. I was super excited to find (this is still inside the dream) a copy of "Han Solo with Bomb", a compatible book to go along with the Luke and Vader books. This particular bomb would probably be a thermal detonator, or some similar grenade-like explosive device.

The idea of a new character to play against these two characters was pretty exciting to me at the time. I'm still fairly excited about it.

On the left, some files, on the right some debug output.


I spent a chunk of this past weekend revisiting the analysis of Luke vs Vader. I started by scanning in everything. I don't think that's really important, but it feels handy to have digital copies.

I proceeded to create a Google Docs Spreadsheet (ahem, a "Google Spreadsheet" inside "Google Drive") with one page each for moves, results, and the dispatch table for each character. I exported them all as CSVs, and began writing some python scripts to wrangle the CSV information. I've got classes for restrictions, heavily laden with comments saying "TODO - prohibit use of the Force" or "TODO - enable Spin&Strike", as I still haven't got the full logic working for restrictions. I've got classes for characters. I've got a utility function that figures out what moves are available. I've got a test harness that takes two characters, with some (partially working) move restrictions, chooses legal moves, and figures out what resulting pages they end up on.

Which is, maybe, 75% of the way towards my somewhat disappointing Game Theory class project.

I could imagine this turning into a way for me to play a version of the game solo vs a randomized AI.

I've been thinking it might be a little more interesting to allow the AI to learn how to play the game by playing against itself, or against a population of AI players. I've been toying with a bayesian model that would adaptively figure out what the best moves are for each situation. I haven't made specific decisions about how it would be implemented, but the shapes I've considered would probably still have the one-move-lookahead problem I mentioned above - retrieving your weapon is a good idea, and you want to do it, even if it doesn't win you points right now.

The unfun bit that I was hitting yesterday was doing data entry, filling out a big dispatch table. I'm pretty sure that's done (modulo finding and correcting errors). The bit that's baking my bean right now is keeping track of what bits of information apply to which player - Player 1 looks up a move on the "Luke" movement reference, but turns to a page in the "Vader" book, and then, based on Player 2's action, Player 1 turns to a different page in the book, and tells Player 2 what Player 2's restrictions are for the next turn. Simultaneously, also vice versa.

And I haven't yet got to scoring. I've got the data for it. Each move has a score modifier. Did we properly apply those back in High School? I kind of suspect we ignored that. There's a bonus that carries over for one round that doubles the effect of The Force. There's a Force move that heals 3 hit points. There's another result that loses 6 hit points in one go. Doubling up the Force and then pulling off the heal would totally counter that one result. So, I'd like to see some AI that knows the value of a well timed healing move.


I mentioned that having one more character seems kind of exciting. Well, what about several dozen? Turns out, Saber Dueling is an adaptation of the Lost Worlds Combat Picture Books, which I was somewhat aware of in High School, but only started collecting more recently. I've got around a dozen books that I collected around a year ago. Just now, I went to a handful of different online retailers to see what copies they had lying around. I found three different places that would allow me to put titles into shopping carts, and two of them actually let me check out. It seems weird that an online store would have server problems this weekend of all weekends - or, rather, it's weird to me that this weekend, problems like not being able to complete a checkout would go unfixed.

If-when I get my Luke/Vader scripts playing Saber Dueling, then I'll consider expanding it to allow Man With Plate Mail and Broadsword vs Unicorn vs Magician With Dice Bag vs Skeleton with Scimitar. Perhaps Luke can hold his own against the skeleton. I'd be interested to see.

And, even if Luke vs Skeleton isn't a battle we can see, I think I understand the system now well enough to craft Han Solo vs somebody. One bit at a time.