// Copyright 2005 Jim Radford <radford@blackbean.org>, David Caldwell <david@porkrind.org> -*- c -*-
function good(div,game){generic_foundation.prototype.init.call(this,div,game,true);this.accept=function(card){return this.pile.length==0&&card.rank==this.start||this.pile.length&&in_suit_wrap_order(this.top(),card)?2:0;};}
good.prototype=new generic_foundation();function work(div,game){pile.prototype.init.call(this,div,game);this.accept_stacks=true;this.accept=function(card){return!card[0].not_allowed&&(this.pile.length==0||this.pile.length&&in_off_color_wrap_order(card[0],this.top()))?1:0;};this.can_drag=function(index){return index==0||index==this.top_index();}
this.xoffset=0;this.splice=function(start,n){var removed=pile.prototype.splice.call(this,start,n);if(!this.pile.length&&this.game.reserve.pile.length){this.push(this.game.reserve.pop());this.game.reserve.update();}
return removed;}
this.push=function(card){pile.prototype.push.call(this,card);card.not_allowed=this.top_index()!=0;}
this.update=function(force){pile.prototype.update.call(this,force);for(var c in this.pile)
this.pile[c].not_allowed=c!=0;}}
work.prototype=new pile();function reserve(div,game){pile.prototype.init.call(this,div,game);this.accept=function(card){return false;}
this.can_drag=function(index){return index==this.top_index();}
this.xoffset=0;this.yoffset=15;this.splice=this.splice_and_turn_over;}
reserve.prototype=new pile();function game(){pile_game.prototype.init.call(this,"canfield");this.good=new Array(0);this.work=new Array(0);for(var c=1;c<=4;c++)
this.good.push(new good("good"+c,this));for(var c=1;c<=4;c++)
this.work.push(new work("work"+c,this));for(var i in this.work)
this.work[i].game=this;this.deck=new pile("deck",this);this.play=new pile("play",this);this.reserve=new reserve("reserve",this);this.reserve.update=function(force){pile.prototype.update.call(this,force);for(var c in this.pile)
this.pile[c].not_allowed=0;}
this.deck.update=this.reserve.update;this.play.update=this.reserve.update;this.deal=function(deck){this.deck.pile=deck;for(var i=0;i<13;i++){var c;this.reserve.push(c=this.deck.pop());}
this.reserve.top().face=up;for(var x=0;x<4;x++){var c;this.work[x].push(c=this.deck.pop());c.face=up;}
this.good[0].push(this.deck.pop());this.good[0].top().face=up;for(var i in this.good)
this.good[i].start=this.good[0].top().rank;};this.create_deck(this.deck,this.play,3);}
game.prototype=new pile_game();game.prototype.is_complete=function(){return this.good[0].pile.length==13&&this.good[1].pile.length==13&&this.good[2].pile.length==13&&this.good[3].pile.length==13&&WON||NOT_COMPLETE;}
game.prototype.complete=function(){return this.complete_generic(this.good,[this.work,[this.reserve],[this.play]]);}