Wednesday, November 23, 2011

Dart Horse: A Darts Game

So this post is a little out of the ordinary for what I usually write up.


Today a coworker and I invented a new game, which is the "Horse" version for Darts.

The object of the game is just like regular "Horse", where you try to get your opponent to spell Horse first, but the rest is different.

There are two roles each player will hold. The role of the setter and the role of the matcher.

These roles can be initially determined by either a closest to bulls-eye or highest score pre-throw. The winner of this throw will be the matcher.

The setter throws a dart at the board setting the point total which is to be matched. Once the point is set, the matcher throws their dart to see if they can accumulate the same value as the set point. If the value is matched then the setter receives a letter. This can be achieved by utilizing single, double or triple point accumulations. For example, if a setter throws their dart and hits triple 6, giving them 18 points, then the matcher can throw the dart at either single-18, double-9 or triple-6 in order to give the setter a letter.

A player keeps their role for a turn, which consists of three (3) set/match attempts. At the end of the turns the players swap roles and start the next turn.

Turns continue until one player has been given all of the letters of "Horse".

Penalties:
  • If a player throws a dart while their foot is across the line, then they receive a letter.
  • If a player throws a dart and it fails to stick in the dartboard (dartboard area includes outside circle), then they receive a letter.
  • If a setter hits the outside circle, then they receive a letter.

Stumble Upon ToolbarDigg this Post This to FacebookShare on Facebook Tweet Me

Friday, October 21, 2011

JavaScript CamelCase string conversion to Proper Case

I ran into a case where I wanted to be able to reverse a CamelCase string to Proper Case format. Without using regex, due to the amount of time it would take for regex to make the replacement, I built up a function to convert a CamelCased string with the most likely proper result possible.

This function will add a space before a capital letter if it is not the first letter in the sentence, if the following character is not a capital (allow abbreviations/acronyms) and if the previous character was not a space (unlikely to be used, but allows for partial camel cased strings to be corrected). Unfortunately this function will not be able to detect a single letter capital word as an independent work, like 'I'. Since it's less common that 'I' would be used in a variable, when compared to an acronym or abbreviation, this was decided to be the lesser evil of errors.



String.prototype.camelToProper = function () {
if (this == null || this == "") {
return this;
}
var newText = "";
var characters = this.split("");
for (var i = 0; i < characters.length; i++) {
if (characters[i] == characters[i].toUpperCase()
&& i != 0
&& !(characters[i + 1] == characters[i + 1].toUpperCase())
&& characters[i - 1] != " ") {
newText += " ";
}
newText += characters[i];
}

return newText;
}

Stumble Upon ToolbarDigg this Post This to FacebookShare on Facebook Tweet Me

Monday, October 17, 2011

Speed Test: Document-Relative vs. Root-Relative

Today I got curious if there was a speed difference for loading using Document-Relative paths or Root-Relative paths.

I created a sample test on one of my sites which loads up 583 thumbnails and put in a trigger to change the type of relative pathing utilized.

I did a series of load time measurements and based on these tests it appears that the difference insignificant. Therefore, use whichever method you like best.

Document-Relative Paths: http://aiwl.us/test/?relativity=document

Load Time First Byte Start Render DOM Elements Result (error code)
20.844s 0.516s 0.890s 586 0
Document Complete
Time Requests Bytes In
20.844s 583 3,050 KB
Fully Loaded
Time Requests Bytes In
20.844s 583 3,050 KB


Root-Relative Paths: http://aiwl.us/test/?relativity=root

Load Time First Byte Start Render DOM Elements Result (error code)
20.606s 0.430s 0.832s 586 0
Document Complete
Time Requests Bytes In
20.606s 583 3,070 KB
Fully Loaded
Time Requests Bytes In
20.606s 583 3,070 KB

Stumble Upon ToolbarDigg this Post This to FacebookShare on Facebook Tweet Me