Posts Tagged ‘game’

Muddl - A Word Game

Thursday, June 12th, 2008

GSP East AppNite Demo While at GSP East, I presented on Muddl, a light fun word game that is anagram like in nature. I received lots of great feedback on the game from folks and encourage everyone to check it out.

It’s currently available on Facebook and Bebo. I’ll be finishing the port to MySpace and other OpenSocial containers soon.

The game play is very simple. After you go to the app you’re presented with some scrambled up letters. You then try to figure out what the word is. If you don’t get the word correct the system gives you a clue. If you’re still wrong you’ll get the first letter of the word revealed. After 3 tries you’ll be provided with another word. The game continues to challenge you as you play by increasing the length of the word.

Muddl Screenshot

Photo of Erik © James Duncan Davidson used with permission.

It’s All In a Roll of the Dice

Friday, May 16th, 2008

White dice Sitting in an airplane recently I began thinking about roll playing games and how they’re slowly gaining popularity on Facebook and MySpace as MMOG’s (Massively Multiplayer Online Games for those who don’t know). Basically the game engines of Dungeons & Dragons etc are simply extensions of more conventional game dynamics from simple board games. Specifically I began thinking about RISK and how the odds change based on the number of armies you bring to the fight.

So sitting in that airplane, I created a PHP class to play around with the odds and how things come out using classic risk weighting. First I created a simple class to roll a six sided die and then expanded it so many instances could be created representing virtual dice. I then created a roll method which will take an optional parameter to handle multiple dice (say 2 dice with 6 sides each common in many games). Last but not least I created to classes for actually rolling an opponent vs. defense, vs() and risk(). The risk class returns a Losses object with the number of units defeated in battle.

Have Fun!

I should note, I’m not the first person to be curious about the odds of Risk or other games for that matter. Google returns over 3.4 Million results for “risk odds”, but I wanted to call out a few that do a nice job of explaining the whole idea here, here and here.

class Dice {
	private $s = 6;
 
	// General constructor
	function __construct($faces = 6){
		$this->s = $faces;
	}
 
	// Returns a roll based on the sides of the dice being thrown
	function roll($dice = 1){
		$total = 0;
		while($dice){
			$total += rand(1,$this->s);
			$dice--;
		} 
		return $total;
	}
 
	// Uses a classic risk model that rewards putting more troops in play
	// removing the 3/2 limit if desired.
	function risk($of = 3, $df = 2){
		$losses = new Losses();
		$dl = 0; $ol = 0;
		$dt = array(); $ot = array();
		for($i=$df; $i>0; $i--){ $dt[] = $this->roll(); }
		for($i=$of; $i>0; $i--){ $ot[] = $this->roll(); }
		rsort($dt); rsort($ot);
		while(count($ot) > 0 && count($dt) > 0){
			if(array_shift($ot) > array_shift($dt)){
				$losses->defense--;
			} else {
				$losses->offense--;
			}
		}
		return $losses;
	}
 
}
// Helper class to pass back the losses from a risk roll
class Losses{ var $defense = 0; var $offense = 0; }
© 1998-2008 AF-Design, All rights reserved.