Wednesday, August 15, 2012

Gauss and Palida

From the latest high-end malware:

 "Named after the German mathematician Carl Friedrich Gauss, the new malware, like Flame, Duqu and Stuxnet before it, is somewhat of a mystery at the moment..."
"...Another interesting component of Gauss is the installation of a custom font called Palida Narrow. The purpose of this font installation is currently unknown," Kaspersky's researchers said."

The font may mark machines that have been infected already.

pálida

Spanish

Adjective

pálida f
  1. feminine form of pálido

Noun

pálida f (plural pálidas)
  1. (colloquial, Chile, Argentina) pallor, paleness (due to drug abuse or sickness)

 





Sunday, March 4, 2012

Souls for Smuggler's Shiv.js

Taking a break from Code Academy to work on a project for the D&D campaign I am running using Paizo's "Serpent's Skull" books. The players are castaways on a topical island along with a few others from their ship.

I decided I wanted to simulate what happens to those non-player characters left back at their camp next to the wreck of the Brine Demon, while the people in my game are out exploring. The program takes a starting and ending day (based on how long they have been on the island), and generates output like this:

Day 1: 8 food.
Aerys becomes shaken. She does nothing today.
Gelik remains shaken. He guards the Brine Demon campsite.
Jask remains hopeful. He keeps the camp clean and bug free.
Sasha remains hopeful. She hunts and fishes 2 food.
3 Human Zombies mindlessly stumble through the traps and are destroyed. 4 Thrunefang Cannibals watch the camp from a distance.
Gained 2 food, consumed 4 with 6 food remaining.


Day 2: 6 food.
Aerys becomes frightened. She does nothing today.
Gelik becomes frightened. He guards the Brine Demon campsite.
Jask remains hopeful. He keeps the camp clean and bug free.
Sasha remains hopeful. She hunts and fishes 4 food.
3 Dimorphodons soar lazily nearby.
Gained 4 food, consumed 4 with 6 food remaining.


Shiv processing complete! Shiv.js

I still need to add in the functions that test if they have come down with, or recovered, from some tropical disease. As their internal numbers are influenced by illness, which npc is assigned to a job may change.

Thursday, February 23, 2012

???? (A new ternary style operator)

I saw a silly post ending with "????" and my brain pounced on the multiple question marks, at the same time wondering when three was enough or if four is warranted. Perhaps because of javascript can use === to test equality I thought the ???? could also be an operator, riffing off the ternary style of compressing if/else into one line.

Well, ???? Could be a compressed switch/case statement!

Ternary:
if (a > b) {
    result = x;
}
else {
    result = y;
}
 
becomes...
 
result = a > b ? x : y; 


????
switch (input) {
    case: "compare to one possible input"
    "do something"
    break;

    case: "some other possible input"
    "do something else"
    break;
 
    "etc" 
 
Using similar characters as the ternary...
 
result = input ? comparison 1 : output ? comparison 2 : output ? comparison 3 : output ... etc
 
Anyways, just having some fun, right????  
 
** edit: it could be called multiplus 

Tuesday, February 21, 2012

#mathishard


So my Codeacademy lesson has a Dice Game project, which means random number generation. Apparently the common way to generate random numbers is a function call that returns a random number between 0 (inclusive) and 1(exclusive). . So to get a d6:

// pick a random number between 1 and 6 for our roll of the die
var die = Math.floor(Math.random()*6 + 1);

Random() is returning 0.0000000000000000 to 0.9999999999999999

floor() is rounding down to the nearest integer. And the +1 is so we get 1-6 and not 0-5.

I suppose I don't understand why this gives an even chance to get 1 through 6. I made a list using just one significant digit and got the following distribution. Maybe the short cut is causing an illusion that it is not equally random? Though I would think there would be an equal number for each 16 digit number leading with like 0.0... and 0.1...

0.9 * 6 + 1 = 6.4
0.8 * 6 + 1 = 5.8
0.7 * 6 + 1 = 5.2
0.6 * 6 + 1 = 4.6
0.5 * 6 + 1 = 4
0.4 * 6 + 1 = 3.4
0.3 * 6 + 1 = 2.8
0.2 * 6 + 1 = 2.2
0.1 * 6 + 1 = 1.6
0.0 * 6 + 1 = 1

If I numbered a 10 sided die like that, I would expect to see more 5's, 4's, 2's and 1's over 6 and 3, right?

It is 2am at the moment, maybe it will make sense tomorrow.

**update realized I could just run a series in javascript. For a series of 100,000 rolls I am getting results like:
Total 1's = 16749
Total 2's = 16493
Total 3's = 16829
Total 4's = 16599
Total 5's = 16574
Total 6's = 16756

So had some late night confusion. Code below:

//loop to gather some data

// var die = Math.floor(Math.random()*6 + 1);
// that gives 1-6, remove the +1 for 0-5,
// our array positions

var diceArray = [0,0,0,0,0,0];
for (i = 1; i <= 100000; i++) {
    var die = Math.floor(Math.random()*6);
    diceArray[die] = diceArray[die] +1;
}
//print results
for (i = 0; i < 6; i++) {
    var dieFace = i +1;
    console.log("Total " + dieFace + "'s = " + diceArray[i]);
}
// Yes they really add up to 100,000
console.log(diceArray[0] + diceArray[1] + diceArray[2] + diceArray[3] + diceArray[4] + diceArray[5] );
console.log("=================");

** edit #2
After some thought and discussion today I realized my error was assuming I could abstract the float using those 10 cases. They were like 10 slits into the entire range of results, and if I picked 10 points using say two digits I could have gotten a different set of results that also would have appeared lumpy in distribution.

I think the good part of this late night exploration into random() was I was wondering about the results, created a model that didn't match line up with what was supposed to happen, then went and gathered some empirical data. From that data I went back and talked to some programmer friends until I understood how I got confused in the first place.



Friday, February 17, 2012

Character Skill Should Matter


A game character that specializes to be excellent at something should have that represented by the game's mechanics. If a game isn't doing this, I feel that is a problem, one which can be solved by identifying actions anyone can take and those only available to specialists.

I started thinking about this after playing and reading some rules light games. In these the characters have seemed effectively identical on what they can accomplish. The motivated couch potato fights as well as the career martial artist, or the same martial artists can kick off computer operations as well as some transhuman super hacker, who can persuade as well as the master orator. The cause seems to be  systems which give players some dice to roll for their skill, and then more if they can explain how they are emotionally motivated or have appropriate gear.

The counter argument to my complaint focuses around violence, and is that someone could be held at knife-point (or gun-point) by the weakest of opponents. However that situation is basically a special case that is being used to justify the everyone-is-equal-in-skill idea.

To represent the idea of moves that any character can do versus what the specialist can accomplished using, I'll use example from Leverage TV show and how the roles can be described by a game:

Hitters
Anyone can ambush or take someone by surprise and succeed.
  • Hitters can succeed vs multiple opponents
  • Hitters can succeed vs prepared or alert opponents
  • Hitters can succeed vs drawn out fights
  • Hitters are tough and can't be taken out by surprise attacks
  • Hitters can identify the biggest physical threat in a situation and their weak points
Hackers
 Anyone can copy a drive, run a computer program or use software with a nice graphic interface.
  • Hackers can get into a system from outside
  • Hackers can write custom code that has custom results
  • Hackers can cover their tracks
  • Hackers can research secret info that would be in a database somewhere
  • Hackers can identify electronic defenses and weak points
Thief
Anyone can steal unattended objects when not watched, break into an empty building without an alarm system, and flip off power or cut telephone landlines.
  • Thieves can steal objects when other people are around without being noticed
  • Thieves can pickpocket objects
  • Thieves can crack safes and defeat security systems
  • Thieves can clamber around physical barriers
  • Thieves can identify architectural defenses and weak points
 Grifter
Anyone can lie, bluff, and take advantage of the kindness of strangers.
  • Grifters can fast talk their way into assistance or access from the moderately skeptical
  • Grifters can act out an elaborate fake personae with a complex backstory
  • Grifters can charm, seduce inspire or otherwise manipulate emotions
  • Grifters can research gossip or information about someone (stuff that might not hit a database)
  • Grifters can spot weaknesses in interpersonal social dynamics
Mastermind
Anyone can make a plan and try to act with authority.
  • Masterminds can identify the weak points of plans and build in contingencies
  • Masterminds can retool a plan on the ground when things change during an operation
  • Masterminds can take charge of a room or situation with the force of their personality
  • Masterminds can prepare an ace in the hole to salvage a fiasco
  • Masterminds can  read a situation and spot weak points in an organization's structure