44 lines
924 B
R
44 lines
924 B
R
getProbabilitiy <- function(x, numbers){
|
|
positions = match(numbers, x$numbers)
|
|
probs = x$probs[positions]
|
|
|
|
probs[is.na(probs)] = 0
|
|
|
|
return(probs)
|
|
}
|
|
|
|
|
|
# comparerFun(x, y); which both x & y as Die, or one of them as numeric
|
|
compareDie <- function(x, y, comparerFun){
|
|
if(class(x) == "Die" & class(y) == "Die"){
|
|
return(combineDice(x, y, comparerFun))
|
|
}
|
|
|
|
if(class(x) %in% c("numeric", "integer")){
|
|
die = y
|
|
constant = x
|
|
|
|
xNumbers = constant
|
|
yNumbers = die$numbers
|
|
|
|
} else if(class(y) %in% c("numeric", "integer")){
|
|
die = x
|
|
constant = y
|
|
|
|
xNumbers = die$numbers
|
|
yNumbers = constant
|
|
|
|
} else{
|
|
stop("Can only compare two die or a die and a number")
|
|
}
|
|
|
|
if(length(constant) != 1){
|
|
stop("Length of constant must be 1")
|
|
}
|
|
|
|
matchResults = comparerFun(xNumbers, yNumbers)
|
|
probTrue = sum(die$probs[matchResults])
|
|
|
|
z = makeDie(c(F,T), probs=c(1-probTrue, probTrue))
|
|
}
|
|
|