Pig
Trying to play pig
by danShumway
JavaScript
//----------------Used to calculate average values-------------
function roll_safe(count, points){
var value = Math.floor(Math.random()*6) + 1;
if(value == 1){
return [count, points];
} else {
return roll_safe(count+1, points + value);
}
};
//-----------------different AIs I tested against-----------------
function reroll(points, opponent, score, goal, constant){
return (points < constant && score + points < goal);
}
function flip(points, score, opponent, goal, constant){
//How many turns away from winning am I?
var turns = (goal - score)/constant;
//How many turns away from my winning is my opponent?
var o_turns = (goal - opponent)/constant;
var necessaryPace = (goal - score)/(o_turns);
//If I'm less, I want to slightly decrease my standard deviation.
//If I'm more, I want to increase my standard deviation.
return (points < Math.max(necessaryPace, constant) && score + points < goal);
}
function desparate(points, score, opponent, goal, constant){
return ((points < constant || points + score < opponent) && points + score < goal);
}
function desparate_counter(points, opponent, score, goal, constant){
return ((points < constant || points + score < opponent) && points + score < goal);
}
//The one that won out.
function opponentReroll(points, opponent, score, goal, constant){
//How many turns away from winning am I?
var turns = (goal - score)/constant;
//How many turns away from my winning is my opponent?
var o_turns = (goal - opponent)/constant;
var necessaryPace = (goal - score)/(o_turns);
//If I'm less, I want to slightly decrease my standard deviation.
//If I'm more, I want to increase my standard deviation.
return (points < Math.max(necessaryPace, constant) && score + points < goal);
}
function roll(points, risk, alt){
var value = Math.floor(Math.random()*6+1);
if(value == 1){
return -1000000; //You lose.
}
...