You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
784 B
JavaScript

const EMPTY = "empty"
const FILL = "fill"
const POUR = "pour"
const UNKNOWN = "unknown"
class Action {
constructor({ kind = UNKNOWN, target, src } = {}) {
this.kind = kind
this.target = target
this.src = src
}
isEmpty() {
return this.kind === EMPTY;
}
isFill() {
return this.kind === FILL;
}
isPour() {
return this.kind === POUR;
}
string() {
if (this.kind === POUR) {
return `${this.kind} ${this.src}${this.target}`
}
return `${this.kind} ${this.target}`
}
}
module.exports = {
fill(index) {
return new Action({ kind: FILL, target: index })
},
empty(index) {
return new Action({ kind: EMPTY, target: index })
},
pour(src, target) {
return new Action({ kind: POUR, target, src })
},
}