below is my code. I want that Player1,2 will be objects of proto RPSPlayer and that each one would have separate 'history' array. But now, somehow every time i run Player1.play() and Player2.play() they both updates the same 'history' array and shares it. Thanks!
function RPSPlayer() {}
RPSPlayer.prototype.numOfWins = 0;
RPSPlayer.prototype.history = [];
RPSPlayer.prototype.myCurrPick;
RPSPlayer.prototype.getW = function () {return this.numOfWins;};
RPSPlayer.prototype.choose = function (item) {
this.history.push(item);
};
Player1 = new RPSPlayer();
Player1.play = function(){
var randomnumber=Math.floor(Math.random()*3);
if(randomnumber==0){this.currPick = "rock";}
else if(randomnumber==1){this.currPick = "paper";}
else{this.currPick = "scissors";}
this.choose(this.currPick);
return this.currPick;
};
Player2 = new RPSPlayer();
Player2.play = function(){
this.choose("rock");
this.currPick = "rock";
return "rock";
};