// Copyright 2005 Jim Radford <radford@blackbean.org> All rights reserved. -*- c -*- 
function in_maze_order(card1,card2){return in_suit_order(card1,card2)||card1.rank==queen&&card2.rank==ace;}
function segment(div,game){pile.prototype.init.call(this,div,game);this.accept=function(card){var prev=game.snake[(game.snake.length+this.i-1)%game.snake.length];var next=game.snake[(game.snake.length+this.i+1)%game.snake.length];return this.pile.length==0&&(prev.pile.length&&in_maze_order(prev.top(),card)||next.pile.length&&in_maze_order(card,next.top()));}
this.can_drag=function(index){return true;}
this.xoffset=0;this.yoffset=0;}
segment.prototype=new pile();function game(){pile_game.prototype.init.call(this,this.game);this.snake=[];for(var c=1;c<=54;c++){var seg=new segment("snake"+c,this);seg.i=c-1;this.snake.push(seg);}
this.deal=function(deck){this.deck=deck;for(var c=0;c<52;c++){this.deck[c].face=up;var slot=c>=16?c+2:c>=8?c+1:c;if(this.deck[c].rank!=13)
this.snake[slot].push(this.deck[c]);}};}
game.prototype=new pile_game();game.prototype.game="maze";game.prototype.is_complete=function(){var complete=WON;var pile=[];var me=this,next=function(i){while(++i<me.snake.length&&me.snake[i].pile.length==0);return i;}
for(var i=next(-1),j=next(i),f=1;j<this.snake.length;j=next(i=j),f=0){if(f&&this.snake[i].top().rank!=ace)complete=NOT_COMPLETE;if(!in_maze_order(this.snake[i].top(),this.snake[j].top()))
complete=NOT_COMPLETE;if(f&&this.snake[i].top())pile.unshift(this.snake[i].top());pile.unshift(this.snake[j].top());}
count=complete==WON?48:score_order_by(in_suit_order,pile);this.stats.set("ordered",count);return complete;}
cardset_default=cardsets[theme].small;
