// Copyright 2005 Jim Radford <radford@blackbean.org>, David Caldwell <david@porkrind.org> All rights reserved. -*- c -*- 
add_option("turn_3","boolean",false,"Turn over 3 cards at once");add_option("redeal","boolean",true,"Allow deck to be turned back over once all cards have been dealt");function work(div,game){pile.prototype.init.call(this,div,game);this.accept_stacks=true;this.accept=function(card){return this.pile.length==0&&card[0].rank==king||this.pile.length&&in_off_color_order(card[0],this.top())?1:0;};this.can_drag=function(index){return this.pile[index].face==up;}
this.xoffset=0;this.splice=this.splice_and_turn_over;}
work.prototype=new pile();function game(){pile_game.prototype.init.call(this,this.name);this.good=new Array(0);this.work=new Array(0);for(var c=1;c<=4;c++)
this.good.push(new generic_foundation("good"+c,this,true));for(var c=1;c<=7;c++)
this.work.push(new work("work"+c,this));this.deck=new pile("deck",this);this.play=new pile("play",this);this.create_deck(this.deck,this.play,options.turn_3?3:1,options.redeal);}
game.prototype=new pile_game();game.prototype.name="klondike";game.prototype.deal=function(deck){this.deck.pile=deck;for(var y=0;y<7;y++)
for(var x=y;x<7;x++){var c;this.work[x].push(c=this.deck.pop());c.face=x==y?up:down;}};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.can_complete=function(){for(var w in work)
for(var c in work[w].pile)
if(work[w].pile[c].face==down)
return false;return true;}
game.prototype.complete=function(){return this.complete_generic(this.good,[this.work,[this.play]]);}
