// Copyright 2005 David Caldwell <david@porkrind.org> All rights reserved. -*- c -*- 
add_option("variation","enum","normal","Queens can be played on Kings","king_stop","A King on the foundation stops further building","wrap","Aces can be played on Kings and vice versa");add_option("decks","number",1,"Number of decks to use");function foundation(div,game){pile.prototype.init.call(this,div,game);this.accept_stacks=false;this.accept=function(card){return(options.variation!="king_stop"||this.top().rank!=king)&&(in_numeric_order(this.top(),card)||in_numeric_order(card,this.top()))||(options.variation=="wrap"&&(this.top().rank==king&&card.rank==ace||card.rank==king&&this.top().rank==ace));};this.xoffset=this.yoffset=0;this.can_drag=function(index){return false;}}
foundation.prototype=new pile();function tableau(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;}
tableau.prototype=new pile();function stock(div,game){pile.prototype.init.call(this,div,game);this.accept=function(card){return false;};this.can_drag=function(index){return false;};this.xoffset=1;this.yoffset=1;this.maxstack=52-35-1;}
stock.prototype=new pile();function game(){pile_game.prototype.init.call(this,this.game);this.decks=options.decks;this.stock=new stock("stock",this);this.foundation=new foundation("foundation",this);this.tableau=[];for(var i=0;doc.id("tableau"+i);i++)
this.tableau.push(new tableau("tableau"+i,this));this.deal=function(deck){this.stock.pile=deck;for(var c=0;c<5*this.tableau.length;c++){this.tableau[c%this.tableau.length].push(this.stock.pop());this.tableau[c%this.tableau.length].top().face=up;}
this.foundation.push(this.stock.pop());this.foundation.top().face=up;};var me=this;this.stock.onclick=function(){if(!me.stock.pile.length)return;me.push_state();me.stock.top().face=up;me.stock.move_to_pile(me.stock.top_index(),1,me.foundation);};}
game.prototype=new pile_game();game.prototype.game="golf";game.prototype.is_complete=function(){for(var i in this.tableau)
if(this.tableau[i].pile.length&&this.foundation.accept(this.tableau[i].top()))
return NOT_COMPLETE;for(var i in this.tableau)
if(this.tableau[i].pile.length)
return this.stock.pile.length==0&&GAME_OVER;return WON;}
