Don't Eat the Last Cake!

1
2
3
function Player() {}
Player.prototype.firstmove = function (cakes) { return cakes % 4 != 2 && cakes != 1 }
Player.prototype.move = function (cakes, last) { return cakes % 4 == 0 ? (last == 3 ? 2 : 3) : (cakes + 2) % 4 }