// Copyright 2005 Jim Radford <radford@blackbean.org>, David Caldwell <david@porkrind.org> -*- c -*-
function temp(div,game){pile.prototype.init.call(this,div,game);this.accept=function(card){return this.pile.length==0&&this.game.freetemps()>=card.length?1:0;}
this.split_move=function(start,n,from){var to=[{from:from,to:this,fstart:start,n:1}];for(var i=1,p=0;p<this.game.temp.length;p++)
if(this.game.temp[p].pile.length==0&&this.game.temp[p]!=this&&i<n)
to.push({from:from,to:this.game.temp[p],fstart:start+i++,n:1});return to;}
this.can_drag=function(index){return true;}
this.xoffset=0;this.yoffset=0;this.accept_stacks=true;}
temp.prototype=new pile();function work(div,game){pile.prototype.init.call(this,div,game);this.valid_top_card=this.valid_top_card||function(card){return card.rank==king;};this.accept=function(card){return(this.pile.length&&this.card_order(card[0],this.top())||this.pile.length==0&&this.valid_top_card(card[0]))&&card.length<=this.drag_max(game,this)?(this.pile.length?3:2):0;};this.drag_max=this.drag_max||function(game,dest){return game.freetemps()+1;}
this.can_drag=function(index){if(this.pile.length-index>this.drag_max(game))
return false;for(var i=index;i<this.pile.length-1;i++)
if(!this.card_order(this.pile[i+1],this.pile[i]))
return false;return true;}
this.card_order=this.card_order||in_suit_order;this.xoffset=0;this.accept_stacks=true;}
work.prototype=new pile();function game(){pile_game.prototype.init.call(this,this.game);this.good=new Array(0);this.temp=new Array(0);this.work=new Array(0);for(var c=1;c<=4;c++){this.good.push(new generic_foundation("good"+c,this));this.temp.push(new temp("temp"+c,this));}
for(var c=1;document.getElementById("work"+c);c++)
this.work.push(new work("work"+c,this));this.deal=function(deck){this.deck=deck;for(var c in this.deck){this.deck[c].face=up;this.work[c%this.work.length].push(this.deck[c]);}};this.freetemps=function(){return empty_pile_count(this.temp);}}
game.prototype=new pile_game();game.prototype.game="sht";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;}
game.prototype.complete=function(){return this.complete_generic(this.good,[this.work,this.temp]);}