I’m on reddit today – stop by and say hi, and maybe win a book

reddit-fantasyToday over at r/Fantasy on reddit, I have the wonderful opportunity to promote my writing to a great group of fantasy readers. Stop by for a fun read, and if you’re a reddit user, say hi (or at least give me an upvote).

I’m giving away a copy of my paperback to the user who asks the best question.

You’ll find me here: http://redd.it/311pvu

Advertisements

31 Things, Day 15: Programming

31 things I'd rather be doing right now

There is something very satisfying for me about programming. I’m specifically referring to coding here; it’s part problem-solving, part art. The problem to solve can be small (make this mess of text into a nice table), or big (make a game).  The art part is the design of the code “building blocks” that will work together to make a computer program. The term used among programmers is “elegant code,” and I think it is an apt word. If you can create some code that can be reused for many things, both now and in the future, you just saved a lot of time. You never have to touch it again, because you know it works. I love that.

Take this example from my own game code, which I find to be very elegant, (if I do say so myself). A tile-based game is a grid where objects can move in any direction to a tile next to it. Sometimes an object can’t move for various reasons, maybe it’s blocked by a wall. In any case, a game needs to be able to handle an object moving from one tile to another.

2dgame

 

When I first made my Heroquest game, the code handled moving objects very specific to the game. I would never be able to use the code again, because it was very closely tied to only that game. Later, I discovered I could refactor that code and make it reusable. In order to do that, I had to completely generalize what was happening when an object moved from one tile to another. It doesn’t matter if the game is Heroquest or Monopoly or Sorry!

This is what I came up with:

When a pawn wants to move in a certain direction, follow these steps

  1. Does the pawn meet the prerequisites to be able to move in the first place? If no, do something else because they are not met. Otherwise, continue
  2. Are Diagonal moves allowed? If no, does the pawn want to move diagonally? If yes, do something else because diagonal moves are not allowed. Otherwise, continue
  3. Does the tile the pawn wants to move to exist? If no, do something else because the tile can not be found. Otherwise, continue
  4. Is the tile the pawn wants to move to accessible based on where the pawn is now? If no, do something else because the move is blocked. Otherwise, continue
  5. If you got this far, the move will now happen:
  6. Process/do the physical move itself
  7. Evaluate the ramifications of the move to the pawn, the surrounding area, and/or the whole game itself
  8. Do any post-move processing (clean up, things that always happen at the end of a move, etc)

Now I had a skeleton framework to make some reusable code, and I could use it any game I wanted. Here is the actual code:

public void move(TileOccupier pawn, Compass dir) {
  if (movePrerequisitesMet(pawn))
  {
    if (!(!diagonalMovesAllowed() && dir.ordinal() > 3))
    {
      AbstractTile targetTile = 
        tileMap.getAdjacentTile(pawn.getLocation(), dir);    
      if (targetTile != null)
      {
        movePreProcessing(pawn, pawn.getLocation(), targetTile, dir);
        if (tileMap.isEnterableFromOppositeDirection(targetTile, dir) ||
          ignoreTileBoundaries(pawn, dir))
        {
          processMove(pawn, pawn.getLocation(), targetTile, dir);
          evaluateMove(pawn, pawn.getLocation(), targetTile, dir);
          movePostProcessing(pawn, pawn.getLocation(), targetTile, dir);
        }
        else { processMoveBlocked(); }
      }
      else { processTargetTileNotFound(); }
    }
    else { processNotAllowedDiagonalDirection(); }
  }
  else { processMovePrerequisitesNotMet(); }
}

Not that long at all. And the way it works is that any game I make in the future will be able to use it because it is abstract. I simply have to make some concrete decisions about what happens in the particular game at the various stages of the move. (For example, one game may yell at you when try to move diagonally; another game may do nothing at all.)

For the non-programmer types reading this blog, this post may have been boring. But whenever I look at that code above – something I made all on my own – I think, “wow, that was a really elegant design.”

And then it makes me want to go code something!

So that’s another thing I’d rather be doing now, programming.

How I Wrote a Novel, Part Four

(continued from part one, part two, and part three)

Before talking about the revision period, I wanted to get into a little more detail of how I finished the second half of my book. One of the things that I struggled with after the big marathon was finding the proper motivation. What, finishing the novel wasn’t enough? Apparently not. Watching my chart during November, knowing I was getting closer and closer to 50,000 words with each passing day, was a great motivator. But come January, the motivation was gone.

What was the problem? Well, burn out for starters, as can be expected. But after taking December off, that wasn’t an excuse anymore. Next problem? Well, there was the fact that I wasn’t really sure how long this thing was going to get. 100,000 words? 150,000 words? And how long would I take to finish it? Another marathon month? Two?

I figured I needed another nerdy chart to watch my progress, but with a wife and one year old at home, I didn’t want to put them through another crazy month. So I came up with a goal of another 50,000 words by the end of March. 50,000 words in THREE months? That meant I only had to work 1/3 as hard as last time! Easy!

Nope. By February I saw the goal slipping so I moved the end date to the end of April. Result:

Goal unmet

Pathetic. But you’ll notice I picked up some steam at the end there. What happened?

stickk happened.

I would not have started a novel without NaNoWriMo, but I would not have finished my novel if it weren’t for stickk. I highly recommend stickk for anyone who wants to “stick to a goal” (get it?). I chose a method that worked very well for me, and I called it negative reinforcement. I set a goal of 10,000 words from the last week of March to the end of April, 39 days. I gave stickk my credit card number. I authorized them to take $10 of my hard earned money and give it to an ANTI-charity (a politcal organization I was opposed to) if I didn’t meet my goal. You can set up a referee to tell stickk you stuck to the goal, but I chose the honor system. I WAS HONORABLE.

And it worked. Here’s a better view of late March and early April:

Much better

I still floundered a bit there. That was because the goal was so small (250 words a day). I needed a little more to keep the pressure on. For May, the goal was 12,379 words to get up to an even 80,000. June was 15,000 more words. That was a busy month and I was scared I wouldn’t make it, so July was back to the easier 10,000. For August I just needed a little more time to finish it up. I finished on August 8, 2011.

Every month I wagered $10 or $15 that could have gone to “the evil charity” if I didn’t meet my goal. And I was dead set on making sure they never got any of my money. They never did.

So I had finished a novel in less than a year, pretty cool. Except, as I said in part three, the two halves of the novel were very different. So really, I hadn’t finished at all. I was again only half-done. It was revision time.

Concluded in part five

How I Wrote a Novel, Part Two

(continued from part one)

National Novel Writing Month, affectionately known as NaNoWriMo to its participants, occurs every November, with the goal of writing 50,000 words in 30 days. Quick math: that’s 1,667 words a day, about 5 double spaced pages. When you break it down like that, it doesn’t seem all that bad, does it?

What, just me?

Alright, I know I’m not your average guy–or person for that matter. I like complicated things. Really complicated things. My wife says my leisure activities are more complex than most people’s jobs. She’s probably right. My favorite books are thousands of pages long encompassing hundreds of characters involved in intricate interweaving plots (Lord of the Rings, Song of Ice and Fire). My favorite video games take hours of dedicated gameplay over many months to unravel all the deep lore and nuance of the designers’ vision (Elder Scrolls, Zelda, Civilization). My favorite board games cost over $50, take hours to play (or an hour to take your turn), and involve great strategic thinking and planning (Axis & Allies, Agricola). My ideal movies are hours long, with artsy camera work, strange plots and lots of quiet reflection afterwards (The Fountain, The Thin Red Line).  I like my music to be multi-layered, in odd time signatures, busy, and out there (Genesis, Yes).

So, write a book in a month? Game on.

October 2010 was planning time. The rules were that you couldn’t have any prose before Nov 1, but you could have an outline. I took all month to write a ten page outline and I also drew a map. (Fantasy books need maps, you know.) I had just joined a writing critique group, so I had 8 people who knew what I was doing. I told many other friends and family. I highly recommend this strategy: the more people you tell, the harder it will be to quit, because you will have to tell them.

Nov 1 arrived and I hit the ground running. I wrote during lunch at work, and at night at home. Sometimes it flowed so fast that I was done in an hour. Other days I had to stretch myself for 3 hours to get anything down. Sometimes I didn’t make the daily quota, other days I got ahead. I took Thanksgiving Day off. I kept a good pace. Here’s my actual chart:

National Novel Writing Month, November 2010

National Novel Writing Month, November 2010

Yes, I charted it. I’m a geek, so what? It worked though, because you notice the end there? Yeah, I did it. I won. 50,000 words in one month. Unbelieveable, right? You know what was even more unbelieveable?

I was only halfway through my book. Argghh.

For my own sanity, and my wife’s, I took a break. All of December. During that month I let my critique group take a look at the first chapter. I know, I know, you shouldn’t let anyone read your first draft. It really wasn’t that bad, though. I wanted to see what they thought.

They liked it. A lot. Praise felt good. Well, there was one guy who didn’t really like it. He’s been published before, I better listen, right? He came to the group after I started. He didn’t know the origin of my story. And what did he have to say?

“It doesn’t read like a novel. It sounds more like a role playing video game.”

Uh oh.

…Continued in part three

How I Wrote a Novel, Part One

My novel wasn’t a novel at first.  It began as a video game.

Seriously.

Since the mid 90’s I have always wanted to make my own Role Playing Game (RPG) in the style of my old-school SNES favorite Final Fantasy II (IV if we’re being true to Japanese numbering).   I still do.  Making games takes time, though.  I worked on learning programming over the course of many years, and only gave a little bit of thought to the story line.

A few years ago I discovered RPG Maker XP, and then the easier-to-use RPG Maker VX.  Wonderful tools, just a little too expensive and too short of a trial period.  But I started making something I really liked without the hassle of coding.  It was fun.  And lo and behold, a story emerged.

The demo ran out of time, but I kept writing the outline for the story.  That was fun too.

Then life happened. Depression happened.  Life ambitions fizzled, and with it my life’s focus.  A dark page.

I can’t remember why I started thinking about the old game, but it was around the summer of 2010.  I guess I just wanted to be creative again.  I looked over my notes.  It was pretty good.  Complex story.  A bit cliche, but standard fare for the RPG genre.  I remember thinking about the first task the game required: go to the temple cellar and kill all the rats (a deliberate cliche).  I remember picturing the lead character, Adain, swatting away rats with a pole, the weakest weapon in the game.  In my mind it looked like a movie.  Wait, what if I wrote it down like a story?  I hadn’t written fiction in 10 years or so.  But sure, why not?  I wrote a paragraph.  Wow, pretty good again.   Not bad for a depressed guy. But it sat for a while.

And then in October of 2010 I saw something that would change my life:  National Novel Writing Month.

…Continued in part two