1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| // Generated by CoffeeScript 1.7.1
(function() {
var People, genre, genres, peoples, sharers, _i, _len,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
People = (function() {
function People(n) {
this.n = n;
this.money = (Math.random() * 5000) + 5000;
this.interest = genres[Math.round(Math.random())];
}
People.prototype.buy = function() {
var game, seller;
while (__indexOf.call(this.games, game) >= 0) {
game = ["Proprietary adventure", "Free adventure", "Proprietary sandbox", "Free sandbox", "Proprietary " + this.interest, "Free " + this.interest][Math.floor(Math.random() * 7)];
}
seller = sharers[Math.round(Math.random() * sharers[game].length)];
peoples[seller.n].money += seller.price;
this.money -= seller.price;
if (game[0] === 'F' && (Math.round(Math.random() * 5)) === 5) {
sharers[game].push([this.n, Math.round(Math.random() * 5 === 5) ? Math.round(Math.random() * 499 + 1) : 0]);
}
return this.games.push(game);
};
return People;
})();
sharers = [];
genres = ['sandbox', 'adventure'];
peoples = [
{
money: 500000,
money: 500000
}
];
for (_i = 0, _len = genres.length; _i < _len; _i++) {
genre = genres[_i];
sharers["Proprietary " + genre] = [peoples[0]];
sharers["Free " + genre] = [peoples[1]];
}
(function() {
var i, _results;
i = 0;
_results = [];
while (i < 100) {
_results.push(peoples[i] = new People(i++));
}
return _results;
})();
while (true) {
peoples[Math.floor(Math.random() * peoples.length)].buy();
if (peoples[0].money === -500000) {
console.log("Free");
break;
}
if (peoples[0].money === -500000) {
console.log("Proprietary");
break;
}
}
}).call(this); |
Partager