// Copyright 2005 Jim Radford <radford@blackbean.org> All rights reserved. -*- c -*- 
function tableau(div,game){pile.prototype.init.call(this,div,game);this.accept_stacks=true;this.accept=function(cards){return(this.pile.length==0&&cards[0].rank==king?1:0)||(this.pile.length&&in_suit_order(cards[0],this.top())?3:0);};this.can_drag=function(index){return this.pile[index].face==up;}
this.splice=this.splice_and_turn_over;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=5;this.yoffset=0;this.maxstack=3;}
stock.prototype=new pile();function game(){pile_game.prototype.init.call(this,this.game);this.decks=1;this.stock=new stock("stock",this);this.tableau=[];for(var i=1;i<=7;i++)
this.tableau.push(new tableau("tableau"+i,this));this.deal=function(deck){this.stock.pile=deck;for(var n=0;n<7;n++){for(var c=0;c<7;c++){this.tableau[c].push(this.stock.pop());if(n>=3||c>=4)
this.tableau[c].top().face=up;}}};this.stock.onclick=wrap(this,function(){if(!this.stock.pile.length)return;this.push_state();for(var i=0;i<this.tableau.length;i++)
if(this.stock.pile.length){this.stock.top().face=up;this.stock.move_to_pile(this.stock.top_index(),1,this.tableau[i]);}});}
game.prototype=new pile_game();game.prototype.game="scorpion";game.prototype.is_complete=function(){var count=0;for(var i in this.tableau){var x;count+=x=score_order_by(in_suit_order,this.tableau[i].pile);}
this.stats.set("ordered",count);for(var i in this.tableau){if(this.tableau[i].pile.length!=0&&(this.tableau[i].pile.length!=13||!in_order_by(in_suit_order,this.tableau[i].pile)))
return NOT_COMPLETE;}
return WON;}
