Monday, October 12, 2009

Still working on some tutorials... Objective-C is weird

One of the things I hate most is trying to learn a new language. Why? I find it hard to concentrate for the most part. But frankly, I like someone teaching me. Giving me examples and something to do (i.e., homework assignment). Having someone teach it to me allows me to stay focused on what I need to do.

Ok ok, these are really just excuses. The answer is really that I don't concentrate and I get distracted very easily. Like I mentioned before, I find it hard to concentrate. I don't know if it's my head, or if I'm just not that motivated, but man it's hard.

Having said all that - I've embarked upon learning a new language, a new system, and just generally jump into a whole new realm. One of my former classmates from UNM got a good jump on the iPhone development and set up this site which has some pretty good tutorials. They're a little light technical detail, but that's kind of a good thing, I'm sure I would get lost if it laid it on. Anyways, I've been going through the tutorials and reading Apple's Cocoa documents and iPhone dev documents. (hopefully those links work, might need an Apple account or something).

There are some other alternatives that maybe I'll take a look at. There's some Mono projects out there. In case you're too lazy to read that previous link, Mono is basically an open source project that allows C# to run on any platform. Why? Because C# is basically a Microsoft language that runs on .NET. Anyways, there are a couple Mono projects that allow C# apps to run the iPhone, not exactly kosher by Apple's iPhone dev EULA, but apparently there have been a few games written for the iPhone. Anyways, that might be worth checking out since the primary language I use at work.

Well, I think that's enough writing for now. I've got an incredibly bad headache...too much sugar...

Oh yeah, Objective-C the original reason I was going to make this post... uhm...yeah, it's weird. I've been with C# and Java for too long....yeah, that's it. lol

Thursday, October 8, 2009

eh...it's been about 5 months...

So might as well post something while I'm here.... it's been long enough....lets see...

Got a MacBook Pro to try my hand at some iPhone development. I've been wanting to jump onto this platform from the beginning, but I didn't want to spend the bucks on the equipment. Said "fuck it" with the blessing from my beautiful wife I got it :D

I have a feeling that I should have jumped in while it was still hot, I came across this article from Newsweek. That was very disheartening, but not surprising. However, this article is very promising. I dunno, I hope this was a good idea. Well, actually, regardless if I don't create interesting iPhone apps, I can always do some Android apps since that's java.

Ok, so I'll admit it. I love this little machine and I hope to be using it like crazy.

Frankly though, I'm still having trouble staying motivated. But just gotta keep at it... at least I've tried some tutorials for the iPhone.

Ok...that's it for now. See you in another 5 months. :D

Sunday, March 1, 2009

hrrmm...these puzzles are apuzzlin' me

So I was perusing the xkcd blag and came across this little puzzle (which was taken from LispClub.com).
Sue and Bob take turns rolling a 6-sided die. Once either person rolls a 6, the game is over. Sue rolls first. If she doesn’t roll a 6, Bob rolls the die; if he doesn’t roll a 6, Sue rolls again. They continue taking turns until one of them rolls a 6.

Bob rolls a 6 before Sue.

What is the probability Bob rolled the 6 on his second turn?
In the blag comment section, there was a lot of confusion over the wording. Personally, I read it as, "what is the probability of Bob winning the second roll?" In other words, what are the odds of Bob rolling a 6. If it is read like that, then most will probably guess 1/6. Makes sense; there are 6 sides to a dice and you have 1/6 chances of rolling the 6.

However, when you read it carefully and think about it, it's really asking for the probability of Bob winning on the second turn. Now, it's not as simple (to me anyways) and I get all sorts of confused. A commenter named Ian posted a lengthy description of the solution. The mathematics wasn't entirely clear to me, but makes kind of sense (very little to be honest). But math isn't my strong suit. Brute forcing is :D I decided to take Rotheral's approach in the comment section and write my own simulation. Granted, I created this the quickest way possible, and it's using java.util.Random, which from what I can remember isn't always the bestest of best random functions. But for all intents and purposes, it'll work just fine.

Here's the code (forgive the crudeness of how it's edited. I haven't figured out how to make blogger display code):

import java.util.Random;
public class RollOfDie {
  public static void main(String[] args) {
  Random rand = new Random();
    int bobRollCount = 0;
    int sueRollCount = 0;
    int sueWonRound2 = 0;
    int bobWonRound2 = 0;
    //loop for 1E8 games, that's 100,000,000
    for(int i = 0; i &lt 1E8; i++){
      //keep track of the turn
      int turnCount = 0;
      int roll = 0;
      //keep rolling until we hit 6
      while(roll != 6){
        roll = rand.nextInt(6) + 1;
        turnCount++;  
      }
      //even numbered turns are Sue's
      if(turnCount%2 == 0){
        sueRollCount++;
      //odd are Bob's
      }else{
        bobRollCount++;
      }

      //turnCount 2 and 3 are the second turn
      if(turnCount == 2){
        sueWonRound2++;
      }else if (turnCount == 3){
        bobWonRound2++;
    }
  }

  System.out.println("Bob won " + bobRollCount + " games");
  System.out.println("Bob won " + bobWonRound2 + " games on the 2nd round");
  System.out.println("Probability that Bob rolled a 6 on his second turn: " +
                      bobWonRound2 + "/" + bobRollCount + " = "
                      +((double)bobWonRound2/(double)bobRollCount));
  }
}

So as you can see, it's relatively straight forward. Just roll the dice until 6 is reached and then check if the turn was on the second turn (in this case, turnCount 2 or 3). I could have made it to run a few times and then take the average each running, but I felt that running 1E08 games was probably enough. That's 100,000,000 games. 

While I am convinced by the outcome of my result - it matches the ~21% others have reported, I'm not confident in the mathematics. There's a lot going over my head.

Regardless, I had fun making this little demo program. Maybe I should have tried making it in Haskell :D

Weezle-Wuzzle...again

So it's been another month since I've posted. I've done very little programming from home. I did work on my AI project some, but then, as was the case for my AI class, I got stuck trying to make my little bots turn and find their target properly and wouldn't you know it, I just stopped. I just cannot see where the problem is. UGH! So frustrating!

For a while, I sat down and tried to design a new system for this AI thing, but I'm unsure how to go about the design. What I need to do is just sit down and design it. Maybe even take out some of my books from my classes and read up (again) on how to properly design something. But then again, I need to make myself some clear cut goals.

This reminds me of this blog I came across some time ago. Looking at it, I'm fairly certain I have done 3 of the 7 items listed here.

So, how will I break this bad habit? Honestly, I'm not sure. I don't have a clear goal as to what I want or what I want to achieve. I also don't have a clear plan of any sorts to achieve any kind of goal. And then of course there's the motivation. I code all day at work, but don't find the energy to do so at home. It's one big cascading problem.

I've read that joining an open source project is a good way to get programming. Maybe I'll search around for something like that. But seriously, I need to sit my ass down and plan out my AI thing.

FOCUS FOCUS FOCUS

Saturday, January 24, 2009

uuuuuuuuuuuuugh...

Dag nabbit, I got totally lazy and didn't continue writing this friggin' blog.

So here's the deal, at work, I have a set schedule for writing my wiki/blog relating to work. But when I get home, gorram it, I have absolutely no motivation to update it. How am I supposed to stay motivated doing this? I'm finding it incredibly difficult. Yar yar yar...

Ok enough bitching. I am trying to start up little projects. I've been playing Supreme Commander a lot and it's made me want to work on some old AI stuff I had from the graduate class I took in Fall 08 (I dropped the class, felt a little bit overwhelmed, perhaps a post for another day). I figure, I can use the basic movement algorithms I got from it and build up from there. I love RTS games and it would be cool to make something.

I've decided to use Processing since the code I do have from the AI class was done in that. I'm very much tempted to use XNA since there is a nifty tutorial on selecting using using a game box. But, I also want to learn how to do it myself and not just copy and paste, which is what I will end up doing anyways. However, I use C# at work, and I want to work in a different language whilst at home. Even though at UNM I used Java.

Speaking of other languages, I've tried my hand at Haskell - aside from what I did for a class at UNM, but I dunno what to use it for. I need to go through the tutorials and figure out how it works to a decent point. There are some cool things you can do, but I'm not sure which ones. I'm thinking of doing Project Euler problems with it, but we'll see.

As for the old game that I had said I'd start working on. Obviously I'm not ranting and raving about it. I got distracted and lost interest. There was so much in there I was sure what to do anyways.