jmud-0.11/
jmud-0.11/bin/
jmud-0.11/doc/
jmud-0.11/rec/
jmud-0.11/rec/mun/
jmud-0.11/rec/mun/grecia/
jmud-0.11/rec/mun/gunnar/
jmud-0.11/rec/qua/
jmud-0.11/src/bool/
jmud-0.11/src/clone/
jmud-0.11/src/integer/
jmud-0.11/src/misc/
jmud-0.11/src/string/
jmud-0.11/src/util/bit/
jmud-0.11/src/util/color/
jmud-0.11/src/util/file/
jmud-0.11/src/util/jgp/adaptor/
jmud-0.11/src/util/jgp/algorithm/
jmud-0.11/src/util/jgp/container/
jmud-0.11/src/util/jgp/functor/
jmud-0.11/src/util/jgp/interfaces/
jmud-0.11/src/util/jgp/predicate/
jmud-0.11/src/util/log/
jmud-0.11/src/util/state/
jmud-0.11/trash/
class Sheet {

    static private         Dice d10             = new Dice(10);
    static private final   int  THRESHOLD       = 4; // tab[4] = 8
    static private         int  difficultyTab[] = {
	4,  // 0
	5,  
	6,
	7,  
	8,  // 4 => THRESHOLD
	9,
	11, 
	15,
	18,
	19,
	23,
	27, 
	29, 
	31,
	36,
	39,
	41, 
	45,
	48,
	49,
	53,
	57, 
	59,
	61,
	66,
	69,
	71, 
	75, 
	78,
	79,
	83,
	87, 
	89, 
	91,
	96,
	99  
    };

    static public int getDifficulty(int difference) {
	if (difference < -9)
	    return 1;
	
	if (difference < -2)
	    return 2;
	
	if (difference < 0)
	    return difference + 4;
	
	if (difference >= difficultyTab.length)
	    return 100;
	
	return difficultyTab[difference];
    }


    static public int getBonus(int result, int difference) {
	int i = (THRESHOLD > difference) ? THRESHOLD : difference;
	
	while (i < difficultyTab.length && result >= difficultyTab[i])
	    ++i;
	
	return i - THRESHOLD;
    }
    
    static public int getEffect(int difference, int bonus) {
	difference += bonus;
	return difference < 0 ? 0 : difference + 1;
    }
    
    static public int roll(int difficulty) {
	final int FALHA   = 0;
	final int CRITICA = -1;
	
	d10.roll();
	
	if (d10.getFace() == 1)
		return (d10.roll() == 1) ? ((difficulty == 1) ? FALHA : CRITICA) : FALHA;
	
	int result = d10.getFace();
	while (d10.getFace() == 10)
	    result += d10.roll();
	
	return result;
    }
}