Thursday, May 22, 2014

I Love the Modulus Operator

Warning - Geek Thoughts Ahead!
Proceed at your own caution.  

Life guards are not on duty.


  I freaking love some of the simpler constructs in programming logic.  The binary operators, the ability to store multiple values in a byte and change it using bit maps, and of course, the modulus function.  Modulus (or % to me and the rest of the programming crowd) is that math method to divide by a (mod) number and you either get a value or 0.   I have used the modulus in quite a few programs in the past, but lately I have found another handy use for it.
  I have been trying to put together a simple Level/Player Artificial Intelligence (A.I.) for the game we are building right now.  (A.I. is kind of awkward to type, let's just call it "HAL", eh?)   Since the game is made up of squares on a board, HAL has to select desired squares on the board as the game progresses.  Anyway, I need HAL to do different or the same thing at various times.  I decided to tie the decisions to the seconds of the clock.  This is where the repetition of using a Modulus operation on the game second clock can give me a consistent repeatable action.  Even better, instead of setting up some custom Timer classes, I can just reference the desired modulus/action combinations in a plain text file.
    Cool, now I can tell HAL to touch the square to his left every 3 seconds by giving him a command like, "Modulus:3 - TouchLeft".   Pass the current game time in seconds to HAL and other players, and we will get the desired player action when it is appropriate.  That aught to slow HAL down a bit...
    Anyway, there are many ways to skin a cat, but this one really appeals to me.   Now I can move on to what exact actions are performed at repeatable times.  Currently, I just have a log message to prove that I put the player calls and the game timer together correctly.  Once I figure out the kinds of moves to make, like "Move Left", then I can assign them keywords and build up a 'script' for HAL to follow.  The more I think about it, moveLeft sounds like a pretty good next step.  HAL is going to be a left-stepping fool before this day is over!
    "HAL, I have some instructions for you..."

Tuesday, May 13, 2014

Snake Bit.


I have been struggling off and on with a pretty simple problem with the puzzle game I am creating.  I had it working pretty well at the beginning of last week.  Touch a square and if there are available nearby flows, then start pushing those flows into the square.  Touch all the squares on the board and get them all filled up and you have completed the puzzle.  Pretty simple concept.  I was really digging the interaction, but about 5 days ago I decided to make some changes to show the 'flows' a little better.  I thought little arrows showing the active flow channels would be handy to the player and also help me to confirm everything is working correctly.  I also thought the arrows would help me explain the concept of flows to my family.  This was my solution to showing how the game works, but it was also the root of my struggles.   I did not realize it until about 10 minutes ago.
  Since the squares are all adjacent to each other, I setup up the squares to notify the main game board when they have been touched.  "Hey, you touched me and I am Square (4,5)!"  The the game board checks the square's neighbors and determines the appropriate actions, etc...    This was working pretty well early last week.  Then about the same time that I decided to move the game board squares onto an actual game board sized widget, the squares started overlapping each other.  Click on square (1,2) and you might get (1,2) or you could get the neighbor (1,3).  "Wait a minute!  This was working before I added the underlying game board graphic!"  The squares looked the same, but seemed confused about which square was touched.  I assumed it was putting everything on the new board graphic and proceeded to debug the heck out of everything associated with that layout.  It was a problem for the better part of the last 5 days for me.  I could not figure out this simple problem and it was frustrating.  After a bit of this, I would switch to another aspect of the game and vow to fix the problem later.    Maybe work on the button layout, flow graphics, and game screens for a bit and then come back to this issue.  No luck.  Frustrated again.
  In the end, it was not the board graphic or repositioning the squares.  It was the darn flow arrows I had added to the square.  They were created, but invisible until needed.  I did not get much chance to really debug them before I discovered this square problem, but I did notice that they were not always positioned inside the square they belonged to.  No problem, I will adjust them later I thought.  Well as you can probably guess, it was the stray arrows that were causing the bad square identification.  Move those arrows back into their respective square or remove them completely, and the squares worked fine.
    I guess the take away for this was that I chewed up a lot of time and thought trying to fix the wrong part of the code.  Heck, I could even see the arrows were not located in the right square when they worked.  As my Dad would say, "If it was a snake it would have bit me."  Moving the squares around before getting the arrows working right bit me real good.  Programming can be a joy, but occasionally, it can also slap you in the face with your own stupidity.  
   

Tuesday, May 6, 2014

Where the magic happens

Working Desk
    A few days ago a buddy of mine posted a picture of his desk at work on his birthday.  Although it was neat to see the birthday stuff, I was more fascinated by the actual work area and the surrounding environment in the photo.  Developers are normally pretty good people to know and content with their jobs, but we are also jealous creatures when it comes to things like computers and monitors.  I don't know of a developer that has not created his or her own custom environment to suit their programming system.  We are like those car guys that continue to fix up their rides and spend all their time in the garage.  Lots of custom equipment, tools in the proper place and extra equipment arranged for easy access.  (I assume, I am not a car guy, but seen them on TV)  There is always something more that can be added, replaced or modified that can improve your work area.  Since Rebecca and I both share a home office, one of the first things we did was to install a work area in one of the spare rooms.  Our desks are back to back and full of cubbies like any office cubical.  We figured that if we were going to spend a good part of our day in there, it should be done right.  At least this was my argument for convincing Rebecca that we needed to install cubical desks.
    Anyway, I thought a picture of of the area would help to show where we create the Apps and other stuff.  Like most developers, I like multiple monitors to allow me to look at the code, the device emulators, reference documents, and other stuff like 3D design, music play lists, drawing applications and notebooks.  No shown is the rather full bookshelf full of various programming books, Monty Python scripts, toys and the obligatory large white board.   Toys?  Yes, programmers seem to have some kind of kitschy toys, models, or other silly things that we pick up over the years.  Lately, most of mine have come from our kids, but I do have a few favorites that have been around for at least 10 years.  It is all part of the customization of your environment.  Hey, we are nerds at heart and it shows in our native environment.
    I am not sure why a lot of developers are really just big kids in an adult world.  I suspect it is the familiarity of having a mental fallback place where the stresses of a deadline are not important.  We work some crazy hours and really get wrapped up in our minds and code.  Breaking out of this shell occasionally to play around helps to keep your sanity.  Maybe it is also that a lot of programmers start pretty early in life when toys are still relevant.  Maybe it is just that we like gadgets.  I really don't know.  I have worked in offices where rubber band or nerd gun battles are a known hazard.  Maybe a remote control robot will cause you to hop out of the way to get more coffee.   You might have to defend your honor in a spirited game of foosball, darts, or an online multiplayer game.  It is all in good fun and takes your mind off the pressures for the moment.
 
   Note the Spurs mug placed prominently in the center.  It is the playoffs after all!  Go Spurs!
 

Sunday, May 4, 2014

Rebecca: Poo happens

On the weekends, I enjoy walking with Ben and Pepper, our flat-coated retriever mix.  We discuss what is going on and, generally, enjoy uninterrupted conversation.  This morning, both Ben and I must have been deep in thought because we did not have much to say.  Honestly, I was thinking about the grocery list, and he was fretting about the Spurs vs. Mavericks game.

When we got home, I decided that I had JUST enough time to go to the grocery store before church.  As I was putting on my shoes (in the garage), I caught the faint order of poo.  I looked on my shoe and did a quick glance around me. I did not find any poo.  The poo aroma had faded away.  As I got into the car, I noticed some dirt on my jeans.  After trying to rub it off with my hands, I smelled my hand.  I had POO ON MY JEANS, and now I had a poo-smelling hand.  When I ran into the house, I was paralyzed by needing to clorox by hand, rip off my jeans, and beat the dog (We do not beat our dog or even hit her.  Folks familiar with retriever breeds warn that they like to roll in poo.  Pepper has this retriever trait, and it makes me want to scream.  So again, I do not kick our dog.  But I do scream.)  Since I was screaming that the dog had poo on her, Ben quickly grabbed the dog, confirmed the presence of poo, and washed her in our make-shift outdoor dog bath (We have a make-shift outdoor bath because that is how often she rolls in poo).

After relative calm was re-established, it was too late to go to the store.  I have needed to post, so I decided to write on the blog.  The subject was NOT poo, but today's original post idea was not flowing.  My frustration level was increasing with the decibels of my children playing/fighting/whining in the next room.  Because it was easier to blame my children than myself for the writer's block, I loudly ordered them to play outside.  And to close the door!!!

Ahhh. Quiet.  The blog still was not flowing.  Since I had no one left to blame for my lack of creativity, I finally gave up and shut down the computer.  It was time for church.  Yes, I was heading to church with a very non-church attitude.

After some time and grace, it was my daughter that helped me to laugh at the morning.  Imagine sitting in church, thinking someone smells like poo...only to discover after service, the stinky person was you.  She reminded me that I had discovered the poo before going out in public and that the situation could have been really embarrassing.  She graciously accepted my apology for yelling at her and for allowing a little poo to ruin my morning.

Poo, it happens.  When it happens, don't kick the dog, don't yell at the kids, don't let it ruin your day.  Fix the problem, laugh at the craziness, and move on.

Friday, May 2, 2014

Everyone gets antsy, especially programmers.


    So I switched gears to work on a simpler project this week.   Although the Tower Defense game is progressing very well, it still requires a lot more graphic art and programming to get it ready for release.  I see at least another couple of months of work to finish it up.  The art work and level programming will tie up the majority of that time, but it also needs player support for saved games, top score achievements, and buying tower upgrades, etc...  In order to keep on track, I try to keep focused on the small goals that will lead to the finished product.  If I think too much about all the tasks to accomplish, I get a bit of 'brain lock'.  It can get overwhelming.
    I admit it, I got a little antsy to push out a product.  I also don't want to get burned out on the TD game before it was finished.  After some talks with Rebecca last weekend, I was inspired to tinker with a new puzzle App.  So on Monday, I cobbled together the skeleton for this game and showed it to the Boss.  She was receptive and offered up some good ideas.   I went ahead and put together another design and after a week of fun, I have a working prototype puzzle game.  I will try it out on the family this weekend and then start adding puzzle levels and polish.
    The game is basically a strategy type game to take over an entire board using simple interaction with the game board.  As the levels advance, the board will introduce 'enemy' colors that will compete for conquest of the whole board.  I have a few ideas for how the enemies will behave, but still need to create a rules engine to get them working.  Hey, whats a little artificial intelligence between friends, eh?  Next week should be interesting.
    Hopefully, I can pull this together and get a release out in the next month.  This will also give us one more product to tell our friends and family about.  Then I can get back to the tower game without worrying too much about the long term schedule.
    So I got antsy, but sometimes you just need to scratch that itch.