Index / Orange System / last update: January 2003

Orange System | Starbase Fluxx


___The Fluxx Table___
THE GOAL: *5 Keepers*
THE RULES: <Draw 2>, (play 1), (no hand limit) + <Brain Bonus>, (no Keeper
limit), <Secret Data>.
- DavidW has $Bread$, ($Chocolate$).
- Jacqueline has no keepers.
- Emily has $The Toaster$.
- Jota has ($hid$), ($hid$), $The Brain$, ($hid$).

[fluxx] It's now DavidW's turn.
[fluxx] DavidW draws a card.
[fluxx] You draw $Time$.
[fluxx] DavidW, Play a card.

Notes:


Starbase Fluxx (dbref #10324)

@dig Starbase Fluxx
@field #10324 = exit_0 : 10353
@field #10324 = nexits : 1
@zone #10324 = #10719
@desc #10324 = @tell("%#","This starbase is reserved for playing the card
 game called \"Fluxx\"."); @call(10633,"each_turn");

east (dbref #10353)

@open east;e;out;exit = #10325
@odrop #10353 = enters from the west.
@field #10353 = exitto : to Grand Gaming Central
@osucc #10353 = goes east.
@succe #10353 = You walk east...
@desc #10353 = @tell("%#","It's a portal connecting this starbase to
 Grand Gaming Central."); @call(10633,"each_turn");

Fluxx cards (dbref #11960)

@create Fluxx cards;cards;fc
@set #11960 = expert
@desc #11960 = A deck of special cards used in the game "Fluxx".
 Examine each of the following actions for more information;
 also "xx rules" for the basic rules of the game.

// The "cdab" is the "card abbreviation".
// Therefore, "the_cdab" is the abbreviation of whichever card a player is referring to.
@field #11960 = the_cdab : 
@field #11960 = the_discard :
@field #11960 = the_deck : 
@field #11960 = the_fulldeck : g01g02g03g04g05g06g07g08g09g10g11g12g13g14g15g16g17g18g19g20g21k01k02k03k04k05k06k07k08k09k10k11k12k13k14k15k16k17k18k19k20k21a01a02a03a04a05a06a07a08a09a10a11a12a13a14a15a16a17a18r01r02r03r04r05r06r07r08r09r10r11r12r13r14r15r16r17r18r19r20r21r22

// The Goal and the Rules on the table.
// NOTE: For rules-reset's sake, the tbl_ prefix is restricted
//       to resetable rules.
@field #11960 = the_goal :	// g01..g21
@field #11960 = tbl_drule :	// r02,r03,r04,r05
@field #11960 = tbl_dbonus :	// r21
@field #11960 = tbl_prule :	// r16,r17,r18,r19
@field #11960 = tbl_pbonus :	// r22
@field #11960 = tbl_pfinal :	// r06
@field #11960 = tbl_hrule :	// r08,r09,r10,r11
@field #11960 = tbl_hbonus :	// r01
@field #11960 = tbl_krule :	// r12,r13,r14
@field #11960 = tbl_kbonus :	// r15
@field #11960 = tbl_srule :	// r07,r20

// hands go from hand_0 to hand_X, where X = nplayers-1.
// likewise, keepers go from keep_0 to keep_X.
@field #11960 = hand_1 : a01g01k01r01
@field #11960 = whoord : 1	// order number of the %n player
@field #11960 = turnord : 1  // whose turn is it (order number)
@field #11960 = nplayers : 0

// Phase 0 = pre-game
// 1 = current player (turnord) draws
// 2 = current player plays
// 3 = current player discards to current hand limit
// 4 = current player discards to current keeper limit
// 5 = current player plays from hand-d2aue (draw 2 and use either)
// 6 = current player plays from hand-d3p2ot (draw 3 play 2 of them)
// 99 = the game is over; someone won the game.
@field #11960 = phase : 0

// the oh_k fields (see also fn_testwin)
// (oh_k means ordhas_k, ie: who has keeper XX?
// -- value is player order # if that player has it, or -1 if no one does.)
@field #11960 = oh_k01 : -1
@field #11960 = oh_k02 : -1
@field #11960 = oh_k03 : -1
@field #11960 = oh_k04 : -1
@field #11960 = oh_k05 : -1
@field #11960 = oh_k06 : -1
@field #11960 = oh_k07 : -1
@field #11960 = oh_k08 : -1
@field #11960 = oh_k09 : -1
@field #11960 = oh_k10 : -1
@field #11960 = oh_k11 : -1
@field #11960 = oh_k12 : -1
@field #11960 = oh_k13 : -1
@field #11960 = oh_k14 : -1
@field #11960 = oh_k15 : -1
@field #11960 = oh_k16 : -1
@field #11960 = oh_k17 : -1
@field #11960 = oh_k18 : -1
@field #11960 = oh_k19 : -1
@field #11960 = oh_k20 : -1
@field #11960 = oh_k21 : -1

// functions
@field #11960 = fn_beginturn :
 @s("ndrawn",0); @s("nplayed",0);
 @s("whoref_turnord",@g(@print("whoref_",turnord)));
 @s("whonam_turnord",@shortname(whoref_turnord));
 @s("hand_x",@print("hand_",turnord));
 @s("keep_x",@print("keep_",turnord));
 @s("tmp",@switch(@testflag(whoref_turnord,"male"),1,0));
 @s("tmp",@add(tmp,
  @switch(@testflag(whoref_turnord,"female"),2,0)));
 @s("his",@switch(tmp,0,"its",1,"his",2,"her",3,"his/her"));
 @s("_msg",@print("[fluxx] It's now ",@g("whonam_turnord"),"'s turn",
  @switch(tat_again,1," (again)"),"."));
 @switch(tat_count,0,@s("tat_again",0));
 @strloop(@substr("0123456789",0,nplayers),"z",
  @tell(@g("whoref_%z"),_msg));
 @call(11960,"fn_phase1");
 @call(11960,"fn_phase2");
---
ADD TEST
@field #11960 = fn_beginturn : @s("ndrawn",0); @s("nplayed",0); @s("whoref_turnord",@g(@print("whoref_",turnord))); @s("whonam_turnord",@shortname(whoref_turnord)); @s("hand_x",@print("hand_",turnord)); @s("keep_x",@print("keep_",turnord)); @s("tmp",@switch(@testflag(whoref_turnord,"male"),1,0)); @s("tmp",@add(tmp, @switch(@testflag(whoref_turnord,"female"),2,0))); @s("his",@switch(tmp,0,"its",1,"his",2,"her",3,"his/her")); @s("_msg",@print("[fluxx] It's now ",@g("whonam_turnord"),"'s turn", @switch(tat_again,1," (again)"),".")); @switch(tat_count,0,@s("tat_again",0)); @strloop(@substr("0123456789",0,nplayers),"z", @tell(@g("whoref_%z"),_msg)); @call(11960,"fn_phase1"); @call(11960,"fn_phase2");
===

@field #11960 = fn_calc_selord :
 @s("selord",99);
 @fieldloop(11960,"whoref_",@switch("%#","%v",
  @s("selord",@substr("%f",7))
 ));
---
TEST
@field #11960 = fn_calc_selord : @s("selord",99); @fieldloop(11960,"whoref_",@switch("%#","%v",@s("selord",@substr("%f",7))));
===

@field #11960 = fn_calc_thecdab :
 @s("the_cdab",@switch("%0",
 "bread","k01", {"choc","choclate"},"k02", "cookies","k03", "coffee","k04",
 "death","k05", {"donuts","doughnuts"},"k06",
 "love","k07", "milk","k08", "money","k09", "peace","k10",
 "taxes","k11", {"tv","television"},"k12",
 {"the brain","brain"},"k13", {"the eye","eye"},"k14",
 {"the moon","moon"},"k15", {"the pyramid","pyramid"},"k16",
 {"the rocket","rocket"},"k17", {"the sun","sun"},"k18",
 {"the toaster","toaster"},"k19", "time","k20", "war","k21",
 {"10 cards in hand","10 cards","1cih"},"g01",
 {"5 keepers","5k"},"g02", {"all you need is love","aynil"},"g03",
 {"chocolate cookies","cc"},"g04", {"chocolate milk","cm"},"g05",
 {"coffee and doughnuts","cad"},"g06", {"death and taxes","dat"},"g07",
 {"death by chocolate","dbc"},"g08", {"hippyism","hippy"},"g09",
 {"milk and cookies","mac"},"g10",
 {"money (no taxes)","money no taxes","m(t","mnt"},"g11",
 {"peace (no war)","peace no war","p(w","pnw"},"g12",
 {"rocket to the moon","rocket to moon","rttm"},"g13",
 {"the appliances","appliances","ta"},"g14",
 {"the brain (no tv)","the brain no tv","tb(t","tbnt"},"g15",
 {"the great seal","great seal","seal","tgs"},"g16",
 {"the mind's eye","the minds eye","mind's eye","minds eye","tme"},"g17",
 {"the sun & the moon","sun & moon","ts&tm","tsatm"},"g18",
 {"time is money","tim"},"g19",
 {"toast"},"g20", {"war and death","wad"},"g21",
 {"discard & draw","d&d","dad"},"a01",
 {"draw 2 and use 'em","d2aue"},"a02",
 {"draw 3 play 2 of them","draw 3 play 2","d3p2","d3p2ot"},"a03",
 {"everybody gets one","ego"},"a04",
 {"exchange keepers","exchange","ek"},"a05",
 {"pilfer the trash","pilfer trash","pilfer","ptt"},"a06",
 {"rules reset","rr"},"a07",
 {"scramble keepers","scramble","sk"},"a08",
 {"security breach","security","breach","sb"},"a09",
 {"steal a keeper","steal keeper","sak"},"a10",
 {"take another turn","tat"},"a11",
 {"taxation!","taxation","t!"},"a12",
 {"trade hands","trade","th"},"a13",
 {"trash a keeper","trash keeper","tak"},"a14",
 {"trash a new rule","trash a rule","trash new rule","trash rule","tanr"},"a15",
 {"trash hand limit","trash hand","thl"},"a16",
 {"trash keeper limit","tkl"},"a17",
 {"use what you take","uwyt"},"a18",
 {"brain bonus","brain b","bb"},"r01",
 {"draw 2","d2"},"r02", {"draw 3","d3"},"r03",
 {"draw 4","d4"},"r04", {"draw 5","d5"},"r05",
 {"final card random","final card","final","fcr"},"r06",
 {"government cover-up","government cover up","government coverup","gcu","gc"},"r07",
 {"hand limit 0","hand 0","hl0"},"r08", {"hand limit 1","hand 1","hl1"},"r09",
 {"hand limit 2","hand 2","hl2"},"r10", {"hand limit 3","hand 3","hl3"},"r11",
 {"keeper limit 2","keeper 2","kl2"},"r12", {"keeper limit 3","keeper 3","kl3"},"r13",
 {"keeper limit 4","keeper 4","kl4"},"r14", {"money bonus","money b","mb"},"r15",
 {"play 2","p2"},"r16", {"play 3","p3"},"r17",
 {"play 4","p4"},"r18", {"play all","pa"},"r19",
 {"secret data","sd"},"r20", {"tax bonus","tab","tax b"},"r21",
 {"time bonus","tib","time b"},"r22", {"hid","hidden"},"hid", "done","don", "xxx"));

@field #11960 = fn_calc_whoord :
 @s("whoord","99");
 @strloop(@substr("0123456789",0,@g("nplayers")),"z",
  @switch("%#",@g("whoref_%z"),@s("whoord","%z"))
 );
---
@field #11960 = fn_calc_whoord : @s("whoord","99"); @strloop(@substr("0123456789",0,@g("nplayers")),"z", @switch("%#",@g("whoref_%z"),@s("whoord","%z")));
===

// assume beginning of game, field whoord (the player ord to deal to)
@field #11960 = fn_dealhand :
 @s(@print("hand_",@g("whoord")),@substr(@g("the_deck"),0,9));
 @s("the_deck",@substr(@g("the_deck"),9));
 @s(@print("keep_",@g("whoord")),"");
---
@field #11960 = fn_dealhand : @s(@print("hand_",@g("whoord")),@substr(@g("the_deck"),0,9)); @s("the_deck",@substr(@g("the_deck"),9)); @s(@print("keep_",@g("whoord")),"");
===

// NOTE 1: Specifically, the turnord player draws a card.
// NOTE 2: This must be general enough not to increment ndraws.
@field #11960 = fn_drawcard :
 @switch(@strlen(@g("the_deck")),0,@print(
  @s("the_deck",@g("the_discard")), @s("the_discard",""),
  @call(11960,"fn_shuffle") ));
 @switch(@strlen(@g("the_deck")),0,
  @strloop(@substr("0123456789",0,@g("nplayers")),"x",@print(
  "[fluxx] ",@g("whonam_turnord"),
  " is entitled to draw a card, but the deck is empty."
  )),@print(
    @s("_cdab",@substr(@g("the_deck"),0,3)),
    @s("the_deck",@substr(@g("the_deck"),3)),
    @s(@g("hand_x"),
     @print(@g(@g("hand_x")),@g("_cdab"))),
    @strloop(@substr("0123456789",0,@g("nplayers")),"x",
     @switch("%x",@g("turnord"),
      @tell(@g("whoref_turnord"),
       @print("[fluxx] You draw ",@g(@print("cdna_",@g("_cdab"))),".")),
      @tell(@g("whoref_%x"),
       @print("[fluxx] ",@g("whonam_turnord")," draws a card."))
    ))
  )
 );
----
TEST
@field #11960 = fn_drawcard : @switch(@strlen(@g("the_deck")),0,@print( @s("the_deck",@g("the_discard")), @s("the_discard",""), @call(11960,"fn_shuffle") )); @switch(@strlen(@g("the_deck")),0, @strloop(@substr("0123456789",0,@g("nplayers")),"x",@print( "[fluxx] ",@g("whonam_turnord"), " is entitled to draw a card, but the deck is empty.")),@print( @s("_cdab",@substr(@g("the_deck"),0,3)), @s("the_deck",@substr(@g("the_deck"),3)), @s(@g("hand_x"), @print(@g(@g("hand_x")),@g("_cdab"))), @strloop(@substr("0123456789",0,@g("nplayers")),"x", @switch("%x",@g("turnord"), @tell(@g("whoref_turnord"), @print("[fluxx] You draw ",@g(@print("cdna_",@g("_cdab"))),".")), @tell(@g("whoref_%x"), @print("[fluxx] ",@g("whonam_turnord")," draws a card."))))));
====

// sets the field is_cardinhand to 1 or 0.
// ALSO sets the field off_cardinhand to the offset.
// assumes the_cdab and turnord are preset.
@field #11960 = fn_calc_is_cardinhand :
 @s("_h",@g(@g("hand_x")));
 @s("_n",@idiv(@strlen(@g("_h")),3));
 @s("_i",0);
 @s("is_cardinhand",0);
 @strloop(@substr(@g("_h"),0,@g("_n")),"x",@print(
  @switch(1,@eq(@g("the_cdab"),@substr(@g("_h"),@g("_i"),3)),@print(
   @s("is_cardinhand",1),
   @s("off_cardinhand",@g("_i"))
  )),
  @s("_i",@add(3,@g("_i")))
 ));
---
TEST
@field #11960 = fn_calc_is_cardinhand : @s("_h",@g(@g("hand_x"))); @s("_n",@idiv(@strlen(@g("_h")),3)); @s("_i",0); @s("is_cardinhand",0); @strloop(@substr(@g("_h"),0,@g("_n")),"x",@print( @switch(1,@eq(@g("the_cdab"),@substr(@g("_h"),@g("_i"),3)),@print( @s("is_cardinhand",1), @s("off_cardinhand",@g("_i")))), @s("_i",@add(3,@g("_i")))));
===

// Does turnord player have the_cdab in his keepers on the table?
// (either visible or hid)
@field #11960 = fn_calc_is_cardinkeep :
 @s("_k",@g(@g("keep_x")));
 @s("_n",@idiv(@strlen(@g("_k")),3));
 @s("_i",0);
 @s("is_cardinkeep",0);
 @strloop(@substr(@g("_k"),0,@g("_n")),"x",@print(
  @switch(1,@eq(@g("the_cdab"),@lc(@substr(@g("_k"),@g("_i"),3))),@print(
   @s("is_cardinkeep",1),
   @s("off_cardinkeep",@g("_i"))
  )),
  @s("_i",@add(3,@g("_i")))
 ));
---
TEST
@field #11960 = fn_calc_is_cardinkeep : @s("_k",@g(@g("keep_x"))); @s("_n",@idiv(@strlen(@g("_k")),3)); @s("_i",0); @s("is_cardinkeep",0); @strloop(@substr(@g("_k"),0,@g("_n")),"x",@print( @switch(1,@eq(@g("the_cdab"),@lc(@substr(@g("_k"),@g("_i"),3))),@print( @s("is_cardinkeep",1), @s("off_cardinkeep",@g("_i")))), @s("_i",@add(3,@g("_i")))));
===

// Does turnord player have the_card2 in his keepers on the table?
@field #11960 = fn_calc_is_card2visinkeep :
 @s("_k",@g(@g("keep_x")));
 @s("_n",@idiv(@strlen(@g("_k")),3));
 @s("_i",0);
 @s("is_card2visinkeep",0);
 @strloop(@substr(@g("_k"),0,@g("_n")),"x",@print(
  @switch(1,@eq(@g("the_card2"),@substr(@g("_k"),@g("_i"),3)),@print(
   @s("is_card2visinkeep",1),
   @s("off_card2visinkeep",@g("_i"))
  )),
  @s("_i",@add(3,@g("_i")))
 ));
---
TEST
@field #11960 = fn_calc_is_card2visinkeep : @s("_k",@g(@g("keep_x"))); @s("_n",@idiv(@strlen(@g("_k")),3)); @s("_i",0); @s("is_card2visinkeep",0); @strloop(@substr(@g("_k"),0,@g("_n")),"x",@print( @switch(1,@eq(@g("the_card2"),@substr(@g("_k"),@g("_i"),3)),@print( @s("is_card2visinkeep",1), @s("off_card2visinkeep",@g("_i")))), @s("_i",@add(3,@g("_i")))));
===

@field #11960 = fn_phase1 :
 @s("phase",1);
 @s("_n",@sub(@switch(@g("tbl_drule"),"r02",2,"r03",3,"r04",4,"r05",5,1),
  @g("ndrawn")));
 @switch(@lt(@g("_n"),0),1,@s("_n",0));
 @strloop(@substr("xxxxx",0,@g("_n")),"x",@call(11960,"fn_drawcard"));
---
TEST
@field #11960 = fn_phase1 : @s("phase",1); @s("_n",@sub(@switch(@g("tbl_drule"),"r02",2,"r03",3,"r04",4,"r05",5,1), @g("ndrawn"))); @switch(@lt(@g("_n"),0),1,@s("_n",0)); @strloop(@substr("xxxxx",0,@g("_n")),"x",@call(11960,"fn_drawcard"));
===

@field #11960 = fn_phase2 :
 @s("phase",2);
 @tell(@g("whoref_turnord"),@print("[fluxx] ",
  @g("whonam_turnord"),", Play a card."));
---
@field #11960 = fn_phase2 : @s("phase",2); @tell(@g("whoref_turnord"),@print("[fluxx] ", @g("whonam_turnord"),", Play a card."));
===

// PHASE 3: Player must discard down to current Hand Limit.
// If player has no cards, or no hand limit rule:
//  go to phase 4.
// Else if hand limit 0 rule and brain bonus doesn't apply:
//  auto-discard entire hand, then go to phase 4.
// Else if player has equal or less cards in hand than the limit:
//  go to phase 4.
// Else if player has limit+1 and brain bonus does apply:
//  announce option to either discard a card or "discard done".
// Else:
//  announce that player must discard card(s) from hand down to the limit.
@field #11960 = fn_phase3 :
 @s("phase",3);
 @s("the_card2","k13");
 @call(11960,"fn_calc_iscard2visinkeep");
 @s("_bbonus",@and(@eq(@g("tbl_hbonus"),"r01"),
  @eq(@g("is_card2visinkeep"),1)));
 @s("_hlim",@switch(@g("tbl_hrule"),"r08",0,"r09",1,"r10",2,"r11",3,99));
 @s("_nih",@idiv(@strlen(@g(@g("hand_x"))),3));
 @switch(1,
  @or(@eq(@g("_hlim"),99),@eq(@g("_nih"),0)),
   @call(11960,"fn_phase4"),
  @and(@eq(@g("_hlim"),0),@not(@g("_bbonus"))),@print(
   @s("the_discard",@print(@g(@g("hand_x")),@g("the_discard"))),
   @s(@g("hand_x"),""),
   @s("_msg",@print("[fluxx] ",@g("whonam_turnord"),
   " automatically discards ",@g("his"),
   " hand to comply with Hand Limit 0.")),
   @strloop(@substr("0123456789",0,@g("nplayers")),"x",
    @tell(@g("whoref_%x"),@g("_msg"))),
   @call(11960,"fn_phase4")),
  @lt(@g("_nih"),@add(1,@g("_hlim"))),
   @call(11960,"fn_phase4"),
  @and(@eq(@g("_nih"),@add(1,@g("_hlim"))),@g("_bbonus")),
   @tell(@g("whoref_turnord"),"[fluxx] You must now either discard a card,
    or, because of Brain Bonus, type \"discard done\" to not discard."),
  @tell(@g("whoref_turnord"),"[fluxx] You must now discard card(s) down to
   the current Hand Limit.")
 );
---
TEST
@field #11960 = fn_phase3 : @s("phase",3); @s("the_card2","k13"); @call(11960,"fn_calc_iscard2visinkeep"); @s("_bbonus",@and(@eq(@g("tbl_hbonus"),"r01"), @eq(@g("is_card2visinkeep"),1))); @s("_hlim",@switch(@g("tbl_hrule"),"r08",0,"r09",1,"r10",2,"r11",3,99)); @s("_nih",@idiv(@strlen(@g(@g("hand_x"))),3)); @switch(1, @or(@eq(@g("_hlim"),99),@eq(@g("_nih"),0)), @call(11960,"fn_phase4"), @and(@eq(@g("_hlim"),0),@not(@g("_bbonus"))),@print( @s("the_discard",@print(@g(@g("hand_x")),@g("the_discard"))), @s(@g("hand_x"),""), @s("_msg",@print("[fluxx] ",@g("whonam_turnord"), " automatically discards ",@g("his")," hand to comply with Hand Limit 0.")), @strloop(@substr("0123456789",0,@g("nplayers")),"x", @tell(@g("whoref_%x"),@g("_msg"))), @call(11960,"fn_phase4")), @lt(@g("_nih"),@add(1,@g("_hlim"))), @call(11960,"fn_phase4"), @and(@eq(@g("_nih"),@add(1,@g("_hlim"))),@g("_bbonus")), @tell(@g("whoref_turnord"),"[fluxx] You must now either discard a card, or, because of Brain Bonus, type \"discard done\" to not discard."), @tell(@g("whoref_turnord"),"[fluxx] You must now discard card(s) down to the current Hand Limit."));
===

@field #11960 = fn_phase3_discard :
 @call(11960,"fn_calc_is_cardinhand");
 @switch(1,
  @eq(@g("the_cdab"),"don"),@print(
   @s("the_card2","k13"),
   @call(11960,"fn_calc_iscard2visinkeep"),
   @s("_bbonus",@and(@eq(@g("tbl_hbonus"),"r01"),
    @eq(@g("is_card2visinkeep"),1))),
   @switch(@g("_bbonus"),1,
    @print(
     @s("_msg",@print("[fluxx] ",@g("whonam_turnord"),
      " uses Brain Bonus to keep an extra card in ",@g("his")," hand.")),
     @strloop(@substr("0123456789",0,@g("nplayers")),"x",
      @tell(@g("whoref_%x"),@g("_msg"))),
     @call(11960,"fn_phase4")
    ),
    @tell(@g("whoref_turnord"),
     "[fluxx] Sorry. You may not use \"discard done\" at this time.")
   )
  ),@not(@g("is_cardinhand")),
   "But you don't have that card in your hand.",
  @print(
   @s("the_discard",@print(@g("the_cdab"),@g("the_discard"))),
   @s(@g("hand_x"),@print(
    @substr(@g(@g("hand_x")),0,@g("off_cardinhand")),
    @substr(@g(@g("hand_x")),@add(@g("off_cardinhand"),3))
   )),
   @s("_msg",@print("[fluxx] ",@g("whonam_turnord")," discards ",
    @g(@print("cdna_",@g("the_cdab"))),".")),
   @strloop(@substr("0123456789",0,@g("nplayers")),"x",
    @tell(@g("whoref_%x"),@g("_msg"))),
   @call(11960,"fn_phase3")
 ));
---
TEST
@field #11960 = fn_phase3_discard : @call(11960,"fn_calc_is_cardinhand"); @switch(1, @eq(@g("the_cdab"),"don"),@print( @s("the_card2","k13"), @call(11960,"fn_calc_iscard2visinkeep"), @s("_bbonus",@and(@eq(@g("tbl_hbonus"),"r01"), @eq(@g("is_card2visinkeep"),1))), @switch(@g("_bbonus"),1, @print( @s("_msg",@print("[fluxx] ",@g("whonam_turnord"), " uses Brain Bonus to keep an extra card in ",@g("his")," hand.")), @strloop(@substr("0123456789",0,@g("nplayers")),"x", @tell(@g("whoref_%x"),@g("_msg"))), @call(11960,"fn_phase4")), @tell(@g("whoref_turnord"), "[fluxx] Sorry. You may not use \"discard done\" at this time."))),@not(@g("is_cardinhand")), "But you don't have that card in your hand.", @print( @s("the_discard",@print(@g("the_cdab"),@g("the_discard"))), @s(@g("hand_x"),@print( @substr(@g(@g("hand_x")),0,@g("off_cardinhand")), @substr(@g(@g("hand_x")),@add(@g("off_cardinhand"),3)))), @s("_msg",@print("[fluxx] ",@g("whonam_turnord")," discards ", @g(@print("cdna_",@g("the_cdab"))),".")), @strloop(@substr("0123456789",0,@g("nplayers")),"x", @tell(@g("whoref_%x"),@g("_msg"))), @call(11960,"fn_phase3")));
===

// If player has no keepers in play, or no keeper limit rule,
// or player has equal or less keepers in play than the limit:
//  go to phase 1 of next player's turn.
// Else if player has limit+1 keepers and money bonus does apply:
//  tell player to either discard a keeper or "discard done".
// Else:
//  tell player to discard keepers(s) from play down to the limit.
@field #11960 = fn_phase4 : @s("phase",4);
 @s("the_card2","k09");
 @call(11960,"fn_calc_iscard2visinkeep");
 @s("_mbonus",@and(@eq(@g("tbl_kbonus"),"r15"),
  @eq(@g("is_card2visinkeep"),1)));
 @s("_klim",@switch(@g("tbl_krule"),"r12",2,"r13",3,"r14",4,99));
 @s("_kip",@idiv(@strlen(@g(@g("keep_x"))),3));
 @switch(1,
  @or(@eq(@g("_klim"),99),@eq(@g("_kip"),0),
  @lt(@g("_kip"),@add(1,@g("_klim")))),@print(
   @switch(@g("tat_count"),0,
    @s("turnord",@mod(@add(1,@g("turnord")),@g("nplayers"))),
    @s("tat_count",@sub(@g("tat_count"),1))
   ),
   @call(11960,"fn_beginturn")
  ),
  @and(@eq(@g("_kip"),@add(1,@g("_klim"))),@g("_mbonus")),
   @tell(@g("whoref_turnord"),"[fluxx] You must now either discard a Keeper,
    or, because of Money Bonus, type \"discard done\" to not discard."),
  @tell(@g("whoref_turnord"),"[fluxx] You must now discard Keeper(s) down to
   the current Keeper Limit.")
 );
---
TEST
@field #11960 = fn_phase4 : @s("phase",4); @s("the_card2","k09"); @call(11960,"fn_calc_iscard2visinkeep"); @s("_mbonus",@and(@eq(@g("tbl_kbonus"),"r15"), @eq(@g("is_card2visinkeep"),1))); @s("_klim",@switch(@g("tbl_krule"),"r12",2,"r13",3,"r14",4,99)); @s("_kip",@idiv(@strlen(@g(@g("keep_x"))),3)); @switch(1, @or(@eq(@g("_klim"),99),@eq(@g("_kip"),0), @lt(@g("_kip"),@add(1,@g("_klim")))),@print( @switch(@g("tat_count"),0, @s("turnord",@mod(@add(1,@g("turnord")),@g("nplayers"))), @s("tat_count",@sub(@g("tat_count"),1))), @call(11960,"fn_beginturn")), @and(@eq(@g("_kip"),@add(1,@g("_klim"))),@g("_mbonus")), @tell(@g("whoref_turnord"),"[fluxx] You must now either discard a Keeper, or, because of Money Bonus, type \"discard done\" to not discard."), @tell(@g("whoref_turnord"),"[fluxx] You must now discard Keeper(s) down to the current Keeper Limit."));
===

@field #11960 = fn_phase4_discard :
 @call(11960,"fn_calc_is_cardinkeep");
 @switch(1,
  @eq(@g("the_cdab"),"don"),@print(
   @s("the_card2","k09"),
   @call(11960,"fn_calc_iscard2visinkeep"),
   @s("_mbonus",@and(@eq(@g("tbl_kbonus"),"r15"),
    @eq(@g("is_card2visinkeep"),1))),
   @switch(@g("_mbonus"),1,
    @print(
     @s("_msg",@print("[fluxx] ",@g("whonam_turnord"),
      " uses Money Bonus to keep an extra Keeper on the table.")),
     @strloop(@substr("0123456789",0,@g("nplayers")),"x",
      @tell(@g("whoref_%x"),@g("_msg"))),
     @switch(@g("tat_count"),0,
      @s("turnord",@mod(@add(1,@g("turnord")),@g("nplayers"))),
      @s("tat_count",@sub(@g("tat_count"),1))
     ),
     @call(11960,"fn_beginturn")
    ),
    @tell(@g("whoref_turnord"),
     "[fluxx] Sorry. You may not use \"discard done\" at this time.")
   )
  ),@not(@g("is_cardinkeep")),
   "[fluxx] But you don't have that Keeper in play.",
  @print(
   @s("the_discard",@print(@g("the_cdab"),@g("the_discard"))),
   @s(@g("keep_x"),@print(
    @substr(@g(@g("keep_x")),0,@g("off_cardinkeep")),
    @substr(@g(@g("keep_x")),@add(@g("off_cardinkeep"),3))
   )),
   @s("_msg",@print("[fluxx] ",@g("whonam_turnord")," discards ",
    @g(@print("cdna_",@g("the_cdab")))," from play.")),
   @strloop(@substr("0123456789",0,@g("nplayers")),"x",
    @tell(@g("whoref_%x"),@g("_msg"))),
   @call(11960,"fn_phase4")
 ));
---
TEST
@field #11960 = fn_phase4_discard : @call(11960,"fn_calc_is_cardinkeep"); @switch(1, @eq(@g("the_cdab"),"don"),@print( @s("the_card2","k09"), @call(11960,"fn_calc_iscard2visinkeep"), @s("_mbonus",@and(@eq(@g("tbl_kbonus"),"r15"), @eq(@g("is_card2visinkeep"),1))), @switch(@g("_mbonus"),1, @print( @s("_msg",@print("[fluxx] ",@g("whonam_turnord"), " uses Money Bonus to keep an extra Keeper on the table.")), @strloop(@substr("0123456789",0,@g("nplayers")),"x", @tell(@g("whoref_%x"),@g("_msg"))), @switch(@g("tat_count"),0, @s("turnord",@mod(@add(1,@g("turnord")),@g("nplayers"))), @s("tat_count",@sub(@g("tat_count"),1))), @call(11960,"fn_beginturn")), @tell(@g("whoref_turnord"), "[fluxx] Sorry. You may not use \"discard done\" at this time."))),@not(@g("is_cardinkeep")), "[fluxx] But you don't have that Keeper in play.", @print( @s("the_discard",@print(@g("the_cdab"),@g("the_discard"))), @s(@g("keep_x"),@print( @substr(@g(@g("keep_x")),0,@g("off_cardinkeep")), @substr(@g(@g("keep_x")),@add(@g("off_cardinkeep"),3)))), @s("_msg",@print("[fluxx] ",@g("whonam_turnord")," discards ", @g(@print("cdna_",@g("the_cdab")))," from play.")), @strloop(@substr("0123456789",0,@g("nplayers")),"x", @tell(@g("whoref_%x"),@g("_msg"))), @call(11960,"fn_phase4")));
===

// turnord player plays a card from his hand.
// We've already checked that he has it.
@field #11960 = fn_phase2_play :
 @call(11960,"fn_calc_is_cardinhand");
 @switch(0,@g("is_cardinhand"),
  "But you don't have that card in your hand.",
 @print(
  @switch(@substr(@g("the_cdab"),0,1),
   "g",@call(11960,"fn_playgoal"),
   "k",@call(11960,"fn_playkeeper"),
   "r",@call(11960,"fn_playrule"),
   "a",@call(11960,"fn_playaction")
  ),
  @s("nplayed",@add(1,@g("nplayed"))),
  @call(11960,"fn_testwin"),
  @switch(@g("phase"),2,@call(11960,"fn_phase2_play_pt2"))
 ));
----
TEST
@field #11960 = fn_phase2_play : @call(11960,"fn_calc_is_cardinhand"); @switch(0,@g("is_cardinhand"), "But you don't have that card in your hand.", @print(@switch(@substr(@g("the_cdab"),0,1), "g",@call(11960,"fn_playgoal"), "k",@call(11960,"fn_playkeeper"), "r",@call(11960,"fn_playrule"), "a",@call(11960,"fn_playaction")), @s("nplayed",@add(1,@g("nplayed"))), @call(11960,"fn_testwin"), @switch(@g("phase"),2,@call(11960,"fn_phase2_play_pt2"))));
====

// if he's out of cards, go to phase 3.
// else if "play all" is in effect, do nothing more (phase 2 continues).
// else if played more than the maxplay, go to phase 3.
// else if plays are max'd (or he's out of cards) go to phase 3.
// else if played equal to maxplay and time bonus applies, announce "play done" option.
// else if played equal to maxplay, go to phase 3.
// else if played equal to maxplay-1 and fcr applies, go to playrandom.
@field #11960 = fn_phase2_play_pt2 :
 @s("the_card2","k20");
 @call(11960,"fn_calc_iscard2visinkeep");
 @s("_n2",@switch(@g("tbl_prule"),"r16",2,"r17",3,"r18",4,"r19",99,1));
 @switch(1,
  @eq(@strlen(@g(@g("hand_x"))),0), @call(11960,"fn_phase3"),
  @eq(@g("_n2"),99), "",
  @gt(@g("nplayed"),@g("_n2")), @call(11960,"fn_phase3"),
  @and(@eq(@g("nplayed"),@g("_n2")),
   @eq(@g("tbl_pbonus"),"r22"),
   @eq(@g("is_card2visinkeep"),1)
  ), @print(
   @s("_msg",@print("[fluxx] ",@g("whonam_turnord"),
   " may now either play an extra card because of <Time Bonus>, or \"play done\" to pass.")),
   @strloop(@substr("0123456789",0,@g("nplayers")),"x",
    @tell(@g("whoref_%x"),@g("_msg")))
  ),
  @eq(@g("nplayed"),@g("_n2")), @call(11960,"fn_phase3"),
  @and(@eq(@g("nplayed"),@sub(@g("_n2"),1)),
   @eq(@g("tbl_pfinal"),"r06"),
   @or(@eq(@g("_n2"),2),@eq(@g("_n2"),3),@eq(@g("_n2"),4))
  ), @call(11920,"fn_playrandom")
 );


// PHASE 7: turnord player to select a card to give to ego_ord player
// from temporary \"hand4\". (!Everybody gets one!)
// -- ego_ord is the current target player to give at card to.
@field #11960 = fn_phase7_select :
 @call(11960,"fn_calc_thecdab");
 @call(11960,"fn_calc_is_cardinhand");
 @switch(@g("the_cdab"),
  "xxx",@tell("%#","[fluxx] I don't know that card. Select again."),
  "don",@tell("%#","[fluxx] You may not select \"done\" right now. Select again."),
  "hid",@tell("%#","[fluxx] You may not select \"hid\" right now. Select again."),
  @switch(@g("is_cardinhand"),
   0,@tell("%#","[fluxx] That card in not in \"hand4\". Select again."),
   @print(
    @s("hand_y",@print("hand_",@g("ego_ord"))),
    @s(@g("hand_y"),@print(@g(@g("hand_y")),@g("the_cdab"))),
    @s(@g("hand_x"),@print(
     @substr(@g(@g("hand_x")),0,@g("off_cardinhand")),
     @substr(@g(@g("hand_x")),@add(3,@g("off_cardinhand")))
    )),
    @s("_msg1",@print("[fluxx] You give ",@g(@print("cdna_",@g("the_cdab")))," to ",
     @shortname(@g(@print("whoref_",@g("ego_ord")))),".")),
    @s("_msg2",@print("[fluxx] %n gives ",@g(@print("cdna_",@g("the_cdab"))),
     " to you.")),
    @s("_msg3",@print("[fluxx] %n gives a card to ",
     @shortname(@g(@print("whoref_",@g("ego_ord")))),".")),
    @strloop(@substr("0123456789",0,@g("nplayers")),"z",@switch("%z",
     @g("turnord"),@tell("%#",@g("_msg1")),
     @g("ego_ord"),@tell(@g("whoref_%z"),@g("_msg2")),
     @tell(@g("whoref_%z"),@g("_msg3"))
    )),
    @s("ego_ord",@add(1,@g("ego_ord")),
    @switch(@lt(@g("ego_ord"),@g("nplayers")),
     1,@tell("%#",@print("[fluxx] %n, Select a card from \"hand4\" to give to ",
      @shortname(@g(@print("whoref_",@g("ego_ord")))),".")),
     @s("phase",@sub(@substr(@g("phasestack"),0,3),100)),
     @s("phasestack",@substr(@g("phasestack"),3))
    )
   )
  )
 );
---
TEST
@field #11960 = fn_phase7_select : @call(11960,"fn_calc_thecdab"); @call(11960,"fn_calc_is_cardinhand"); @switch(@g("the_cdab"), "xxx",@tell("%#","[fluxx] I don't know that card. Select again."), "don",@tell("%#","[fluxx] You may not select \"done\" right now. Select again."), "hid",@tell("%#","[fluxx] You may not select \"hid\" right now. Select again."), @switch(@g("is_cardinhand"), 0,@tell("%#","[fluxx] That card in not in \"hand4\". Select again."), @print( @s("hand_y",@print("hand_",@g("ego_ord"))), @s(@g("hand_y"),@print(@g(@g("hand_y")),@g("the_cdab"))), @s(@g("hand_x"),@print( @substr(@g(@g("hand_x")),0,@g("off_cardinhand")), @substr(@g(@g("hand_x")),@add(3,@g("off_cardinhand"))))), @s("_msg1",@print("[fluxx] You give ",@g(@print("cdna_",@g("the_cdab")))," to ", @shortname(@g(@print("whoref_",@g("ego_ord")))),".")), @s("_msg2",@print("[fluxx] %n gives ",@g(@print("cdna_",@g("the_cdab"))), " to you.")), @s("_msg3",@print("[fluxx] %n gives a card to ", @shortname(@g(@print("whoref_",@g("ego_ord")))),".")), @strloop(@substr("0123456789",0,@g("nplayers")),"z",@switch("%z", @g("turnord"),@tell("%#",@g("_msg1")), @g("ego_ord"),@tell(@g("whoref_%z"),@g("_msg2")), @tell(@g("whoref_%z"),@g("_msg3")))), @s("ego_ord",@add(1,@g("ego_ord")), @switch(@lt(@g("ego_ord"),@g("nplayers")), 1,@tell("%#",@print("[fluxx] %n, Select a card from \"hand4\" to give to ", @shortname(@g(@print("whoref_",@g("ego_ord")))),".")), @s("phase",@sub(@substr(@g("phasestack"),0,3),100)), @s("phasestack",@substr(@g("phasestack"),3))))));
===

// PHASE 8: turnord player to select another player with whom
// to exchange a Keeper. (!Exchange Keepers!)
// -- should set the value of ek_ord to the chosen player's ord#.
// -- continue to phase 9 (select a keeper to give)
@field #11960 = fn_phase8_select :
 @call(11960,"fn_calc_selord");
 @switch(@g("selord"),
  99,@tell("%#","[fluxx] That's not the name of a player."),
  @g("turnord"),@tell("%#","[fluxx] You can't exchange Keepers with yourself. Select another player."),
  @switch(@strlen(@g(@print("keep_",@g("selord")))),
   0,@tell("%#",@print("[fluxx] But ",
    @shortname(@g(@print("whoref_",@g("selord")))),
    " has no Keepers in play. Select another player.")),
   @print(
    @s("ek_ord",@g("selord")),
    @tell("%#",@print("[fluxx] ...You select ",
     @shortname(@g(@print("whoref_",@g("ek_ord")))),"..."),
    @call(11960,"fn_phase9")
   )
  )
 ));
---
TEST
@field #11960 = fn_phase8_select : @call(11960,"fn_calc_selord"); @switch(@g("selord"), 99,@tell("%#","[fluxx] That's not the name of a player."), @g("turnord"),@tell("%#","[fluxx] You can't exchange Keepers with yourself. Select another player."), @switch(@strlen(@g(@print("keep_",@g("selord")))), 0,@tell("%#",@print("[fluxx] But ", @shortname(@g(@print("whoref_",@g("selord")))), " has no Keepers in play. Select another player.")), @print( @s("ek_ord",@g("selord")), @tell("%#",@print("[fluxx] ...You select ", @shortname(@g(@print("whoref_",@g("ek_ord")))),"..."), @call(11960,"fn_phase9")))));
===

// PHASE 9: turnord selects a Keeper to give to ek_ord player.
// -- if he has only one Keeper, auto select it and continue to phase 10.
// -- otherwise, prompt him to select a Keeper.
@field #11960 = fn_phase9 :
 @s("phase",9);
 @switch(@strlen(@g("keep_x")),3,
  @print(
   @tell("%#",@print("[fluxx] ...Your only Keeper is ",
    @g(@print("cdna_",@g("keep_x")),"...")),
   @s("ek_card1",@g("keep_x")),
   @call(11960,"fn_phase10")
  ),
  @tell("%#",@print("[fluxx] Select one of your Keepers in play
   to give to ",@shortname(@g(@print("whoref_",@g("ek_ord")))),"."))
 );
---
TEST
@field #11960 = fn_phase9 : @s("phase",9); @switch(@strlen(@g("keep_x")),3, @print( @tell("%#",@print("[fluxx] ...Your only Keeper is ", @g(@print("cdna_",@g("keep_x")),"...")), @s("ek_card1",@g("keep_x")), @call(11960,"fn_phase10")), @tell("%#",@print("[fluxx] Select one of your Keepers in play to give to ",@shortname(@g(@print("whoref_",@g("ek_ord")))),".")));
===

// PHASE 9: turnord selects a Keeper to give to ek_ord player.
// -- set value of ek_card1, continue to phase 10.
@field #11960 = fn_phase9_select : 
 @call(11960,"fn_calc_thecdab");
 @s("_k",@g(@print("keep_",@g("turnord"))));
 @s("_n",@idiv(@strlen(@g("_k")),3));
 @switch(@g("the_cdab"),
  "xxx",@tell("%#","[fluxx] I don't know that card. Select again."),
  "hid",@tell("%#","[fluxx] Refer to your own Keepers by name. Select again."),
  "don",@tell("%#","[fluxx] You may not select \"done\" right now. Select again."),
  @print(
   @s("_i",0),
   @s("ek_card1",""),
   @strloop(@substr(@g("_k"),0,@g("_n")),"x",@print(
    @switch(1,@eq(@g("the_cdab"),@lc(@substr(@g("_k"),@g("_i"),3))),@print(
     @s("ek_card1",@g("the_cdab")),
     @s("ek_card1off",@g("_i"))
    )),
    @s("_i",@add(3,@g("_i")))
   )),
   @switch(@g("ek_card1"),
    @g("the_cdab"),@print(
     @tell("%#",@print("[fluxx] ...You select your ",
      @g(@print("cdna_",@g("the_cdab"))),"...")),
     @call(11960,"fn_phase10")
    ),
    @tell("%#",@print("[fluxx] You don't have ",
     @g(@print("cdna_",@g("the_cdab"))),". Select again."))
   )
  )
 );
---
TEST
@field #11960 = fn_phase9_select : @call(11960,"fn_calc_thecdab"); @s("_k",@g(@print("keep_",@g("turnord")))); @s("_n",@idiv(@strlen(@g("_k")),3)); @switch(@g("the_cdab"), "xxx",@tell("%#","[fluxx] I don't know that card. Select again."), "hid",@tell("%#","[fluxx] Refer to your own Keepers by name. Select again."), "don",@tell("%#","[fluxx] You may not select \"done\" right now. Select again."), @print( @s("_i",0), @s("ek_card1",""), @strloop(@substr(@g("_k"),0,@g("_n")),"x",@print( @switch(1,@eq(@g("the_cdab"),@lc(@substr(@g("_k"),@g("_i"),3))),@print( @s("ek_card1",@g("the_cdab")), @s("ek_card1off",@g("_i")))), @s("_i",@add(3,@g("_i"))))), @switch(@g("ek_card1"), @g("the_cdab"),@print( @tell("%#",@print("[fluxx] ...You select your ", @g(@print("cdna_",@g("the_cdab"))),"...")), @call(11960,"fn_phase10")), @tell("%#",@print("[fluxx] You don't have ", @g(@print("cdna_",@g("the_cdab"))),". Select again.")))));
===

// PHASE 10: turnord selects a Keeper to take from ek_ord player.
// -- if the ek_ord player only has one Keeper, autoselect it
//    as ek_card2/ek_card2off, and go to phase10_pt2.
// -- otherwise, prompt turnord player to select the Keeper.
@field #11960 = fn_phase10 :
 @s("phase",10);
 @s("_k",@g(@print("keep_",@g("ek_ord"))));
 @switch(@strlen(@g("_k")),3,@print(
   @s("ek_card2",@lc(@g("_k"))), @s("ek_card2off",0),
   @tell("%#",@print("[fluxx] ...",@shortname(@g(print("whoref_",@g("ek_ord")))),
    " only has ",@switch( @substr(@g("_k"),0,1),"K","$hid$",
    @g(@print("cdna_",@g("_k"))) ),"...")),
   @call(11960,"fn_phase10_pt2)
  ),
  @tell("%#",@print("[fluxx] %n, Select a Keeper to take from ",
   @shortname(@g(@print("whoref_",@g("ek_ord")))),"."))
 );
---
TEST
@field #11960 = fn_phase10 : @s("phase",10); @s("_k",@g(@print("keep_",@g("ek_ord")))); @switch(@strlen(@g("_k")),3,@print( @s("ek_card2",@lc(@g("_k"))), @s("ek_card2off",0), @tell("%#",@print("[fluxx] ...",@shortname(@g(print("whoref_",@g("ek_ord")))), " only has ",@switch( @substr(@g("_k"),0,1),"K","$hid$", @g(@print("cdna_",@g("_k"))) ),"...")), @call(11960,"fn_phase10_pt2)), @tell("%#",@print("[fluxx] %n, Select a Keeper to take from ", @shortname(@g(@print("whoref_",@g("ek_ord")))),".")));
===

// PHASE 10: turnord selects a Keeper to take from ek_ord player.
// - the actual keeper exchange happens here.
// - We should already know:
// -- ek_card1 is the card abbrev. of turnord's keeper
// -- ek_card2 is the card abbrev. of ek_ord's keeper
// -- ek_card1off is offset of turnord's keeper in his keepers.
// -- ek_card2off is offset of ek_ord's keeper in his keepers.
// - We must calc here:
// -- ek_card1na1 is the real name of turnord's keeper
// -- ek_card1na2 is the visible name of turnord's keeper
// -- ek_card2na1 is the real name of ek_ord's keeper
// -- ek_card2na2 is the visible name of turnord's keeper
// - TODO if Secret Data in play, go to phase 22 to manage keeper revelations.
// - TODO otherwise pop the phase stack (ie: goback to phase 2, 5, or 6). 
@field #11960 = fn_phase10_pt2 :
 @s("ek_card1na1",@g(@print("cdna_",@g("ek_card1"))));
 @s("ek_card2na1",@g(@print("cdna_",@g("ek_card2"))));
 @s("ek_card1na2",@switch(@substr(@g(@print("keep_",@g("turnord"))),
  @g("ek_card1off"),1),"K","$hid",@g("ek_card1na1")));
 @s("ek_card2na2",@switch(@substr(@g(@print("keep_",@g("ek_ord"))),
  @g("ek_card2off"),1),"K","$hid",@g("ek_card2na1")));
 @s("ek_card1",@substr(@g(@print("keep_",@g("turnord"))),@g("ek_card1off"),3));
 @s("ek_card2",@substr(@g(@print("keep_",@g("ek_ord"))),@g("ek_card2off"),3));
 @s(@print("keep_",@g("turnord")),@print(
  @substr(@g(@print("keep_",@g("turnord"))),0,@g("ek_card1off")),
  @substr(@g(@print("keep_",@g("turnord"))),@add(3,@g("ek_card1off"))),
  @g("ek_card2")
  ));
 @s(@print("keep_",@g("ek_ord")),@print(
  @substr(@g(@print("keep_",@g("ek_ord"))),0,@g("ek_card2off")),
  @substr(@g(@print("keep_",@g("ek_ord"))),@add(3,@g("ek_card2off"))),
  @g("ek_card1")
  ));
 @s("_msg1",@print("[fluxx] ",@g("whonam_turnord"),"'s ",@g("ek_card1na1"),
  " and ",@shortname(@g(@print("whoref_",@g("ek_ord")))),
  "'s ",@g("ek_card2na1")," are exchanged."));
 @s("_msg2",@print("[fluxx] ",@g("whonam_turnord"),"'s ",@g("ek_card1na2"),
  " and ",@shortname(@g(@print("whoref_",@g("ek_ord")))),
  "'s ",@g("ek_card2na2")," are exchanged."));
 @strloop(@substr("0123456789",0,@g("nplayers")),"z",@switch(
  "%z",{@g("turnord"),@g("ek_ord")},
   @tell(@g("whoref_%z"),@g("_msg1")),
  @tell(@g("whoref_%z"),@g("_msg2"))
 ));
 @s("phase",2); 
---
TEST
@field #11960 = fn_phase10_pt2 : @s("ek_card1na1",@g(@print("cdna_",@g("ek_card1")))); @s("ek_card2na1",@g(@print("cdna_",@g("ek_card2")))); @s("ek_card1na2",@switch(@substr(@g(@print("keep_",@g("turnord"))), @g("ek_card1off"),1),"K","$hid",@g("ek_card1na1"))); @s("ek_card2na2",@switch(@substr(@g(@print("keep_",@g("ek_ord"))), @g("ek_card2off"),1),"K","$hid",@g("ek_card2na1"))); @s("ek_card1",@substr(@g(@print("keep_",@g("turnord"))),@g("ek_card1off"),3)); @s("ek_card2",@substr(@g(@print("keep_",@g("ek_ord"))),@g("ek_card2off"),3)); @s(@print("keep_",@g("turnord")),@print( @substr(@g(@print("keep_",@g("turnord"))),0,@g("ek_card1off")), @substr(@g(@print("keep_",@g("turnord"))),@add(3,@g("ek_card1off"))), @g("ek_card2"))); @s(@print("keep_",@g("ek_ord")),@print( @substr(@g(@print("keep_",@g("ek_ord"))),0,@g("ek_card2off")), @substr(@g(@print("keep_",@g("ek_ord"))),@add(3,@g("ek_card2off"))), @g("ek_card1"))); @s("_msg1",@print("[fluxx] ",@g("whonam_turnord"),"'s ",@g("ek_card1na1"), " and ",@shortname(@g(@print("whoref_",@g("ek_ord")))), "'s ",@g("ek_card2na1")," are exchanged.")); @s("_msg2",@print("[fluxx] ",@g("whonam_turnord"),"'s ",@g("ek_card1na2"), " and ",@shortname(@g(@print("whoref_",@g("ek_ord")))), "'s ",@g("ek_card2na2")," are exchanged.")); @strloop(@substr("0123456789",0,@g("nplayers")),"z",@switch( "%z",{@g("turnord"),@g("ek_ord")}, @tell(@g("whoref_%z"),@g("_msg1")), @tell(@g("whoref_%z"),@g("_msg2")))); @s("phase",2); 
===

// PHASE 10: turnord selects a Keeper to take from ek_ord player.
// -- verify and set ek_card2, continue to fn_phase10_pt2.
// -- note: ek_card2 should not be "hid"; convert to the actual cdab here.
// count the number of hid keepers
// if _nhid = 0 then complain
// else choose a hid keeper at random and select it
@field #11960 = fn_phase10_select :
 @call(11960,"fn_calc_thecdab");
 @s("_k",@g(@print("keep_",@g("ek_ord"))));
 @s("_n",@idiv(@strlen(@g("_k")),3));
 @switch(@g("the_cdab"),
  "xxx",@tell("%#","[fluxx] I don't know that card. Select again."),
  "don",@tell("%#","[fluxx] You may not select \"done\" right now. Select again"),
  "hid",@print(
   @s("_nhid",0),
   @strloop(@g("_k"),"x",@switch("%x","K",
    @s("_nhid",@add(1,@g("_nhid"))) )),
   @switch(@g("_nhid"),0,
    @tell("%#",@print("[fluxx] But ",
     @shortname(@g(@print("whoref_",@g("ek_ord")))),
     "has no hidden Keepers. Select again.")),
    @print(
     @s("_j",@add(1,@rand(@g("_nhid")))),
     @s("_nhid",0), @s("_i",0),
     @strloop(@g("_k"),"x",@print(
      @switch("%x","K",@print(
       @s("_nhid",@add(1,@g("nhid"))),
       @switch(@g("_nhid"),@g("_j"),@print(
        @s("ek_card2",@lc(@substr(@g("_k"),@g("_i"),3))),
        @s("ek_card2off",@g("_i"))
       ))
      )),
      @s("_i",@add(1,@g("_i")))
     )),
     @tell("%#","...You select one of ",
      @shortname(@g(@print("whoref_",@g("ek_ord")))),
      "'s hidden Keepers at random...")),
     @call(11960,"fn_phase10_pt2")
   ))
  ),
  @print(
   @s("_i",0),
   @s("ek_card2",""),
   @strloop(@substr(@g("_k"),0,@g("_n")),"x",@print(
    @switch(1,@eq(@g("the_cdab"),@substr(@g("_k"),@g("_i"),3)),@print(
     @s("ek_card2",@g("the_cdab")),
     @s("ek_card2off",@g("_i"))
    )),
    @s("_i",@add(3,@g("_i")))
   )),
   @switch(@g("ek_card2"),
    @g("the_cdab"),@print(
     @tell("%#",@print("[fluxx] ...You select ",
      @shortname(@g(@print("whoref_",@g("ek_ord")))),
      "'s ",@g(@print("cdna_",@g("the_cdab"))),"...")),
     @call(11960,"fn_phase10_pt2")
    ),
    @tell("%#",@print("[fluxx] You don't see ",
     @g(@print("cdna_",@g("the_cdab")))," amongst ",
     @shortname(@g(@print("whoref_",@g("ek_ord")))),
     "'s Keepers. Select again."))
   )
  )
 );
---
TEST
@field #11960 = fn_phase10_select : @call(11960,"fn_calc_thecdab"); @s("_k",@g(@print("keep_",@g("ek_ord")))); @s("_n",@idiv(@strlen(@g("_k")),3)); @switch(@g("the_cdab"), "xxx",@tell("%#","[fluxx] I don't know that card. Select again."), "don",@tell("%#","[fluxx] You may not select \"done\" right now. Select again"), "hid",@print( @s("_nhid",0), @strloop(@g("_k"),"x",@switch("%x","K", @s("_nhid",@add(1,@g("_nhid"))))), @switch(@g("_nhid"),0, @tell("%#",@print("[fluxx] But ", @shortname(@g(@print("whoref_",@g("ek_ord")))), "has no hidden Keepers. Select again.")), @print( @s("_j",@add(1,@rand(@g("_nhid")))), @s("_nhid",0), @s("_i",0), @strloop(@g("_k"),"x",@print( @switch("%x","K",@print( @s("_nhid",@add(1,@g("nhid"))), @switch(@g("_nhid"),@g("_j"),@print( @s("ek_card2",@lc(@substr(@g("_k"),@g("_i"),3))), @s("ek_card2off",@g("_i")))))), @s("_i",@add(1,@g("_i"))))), @tell("%#","...You select one of ", @shortname(@g(@print("whoref_",@g("ek_ord")))), "'s hidden Keepers at random...")), @call(11960,"fn_phase10_pt2")))), @print( @s("_i",0), @s("ek_card2",""), @strloop(@substr(@g("_k"),0,@g("_n")),"x",@print( @switch(1,@eq(@g("the_cdab"),@substr(@g("_k"),@g("_i"),3)),@print( @s("ek_card2",@g("the_cdab")), @s("ek_card2off",@g("_i")))), @s("_i",@add(3,@g("_i"))))), @switch(@g("ek_card2"), @g("the_cdab"),@print( @tell("%#",@print("[fluxx] ...You select ", @shortname(@g(@print("whoref_",@g("ek_ord")))), "'s ",@g(@print("cdna_",@g("the_cdab"))),"...")), @call(11960,"fn_phase10_pt2")), @tell("%#",@print("[fluxx] You don't see ", @g(@print("cdna_",@g("the_cdab")))," amongst ", @shortname(@g(@print("whoref_",@g("ek_ord")))), "'s Keepers. Select again.")))));
===

// PHASE 11: Select a card from top 3 cards of discard pile. (!Pilfer the Trash!)
@field #11960 = fn_phase11_select :
---
TODO
===

// 12," to select a Keeper to take from any other player. (!Steal a Keeper!)",
@field #11960 = fn_phase12_select :
---
TODO
===

// 13,@print(" paused. ",@shortname(@print("whoref_",@g("tax_ord"))),
//  " must select a card to give to ",@g("whonam_turnord"),". (!Taxation!)"),
@field #11960 = fn_phase13_select :
---
TODO
===

// PHASE 14: Select a player with whom to trade hands. (!Trade hand!)",
@field #11960 = fn_phase14_select : 
 @call(11960,"fn_calc_selord");
 @switch(@g("selord"),
  99,@tell("%#","[fluxx] That's not the name of a player."),
  @g("turnord"),@tell("%#","[fluxx] No, select *another* player."),
  @print(
   @s("_tmp",@g(@print("hand_",@g("turnord")))),
   @s(@print("hand_",@g("turnord")),@g(@print("hand_",@g("selord")))),
   @s(@print("hand_",@g("selord")),@g("_tmp")),
   @s("_msg",@print("[fluxx] %n trades hands with ",
    @shortname(@g(@print("whoref_",@g("selord")))),"."),
   @strloop(@substr("0123456789",0,@g("nplayers")),"z",
    @tell(@g("whoref_%z"),@g("_msg"))),
   @s("phase",@sub(@substr(@g("phasestack"),0,3),100)),
   @s("phasestack",@substr(@g("phasestack"),3))
 ));
---
TEST
@field #11960 = fn_phase14_select : @call(11960,"fn_calc_selord"); @switch(@g("selord"), 99,@tell("%#","[fluxx] That's not the name of a player."), @g("turnord"),@tell("%#","[fluxx] No, select *another* player."), @print( @s("_tmp",@g(@print("hand_",@g("turnord")))), @s(@print("hand_",@g("turnord")),@g(@print("hand_",@g("selord")))), @s(@print("hand_",@g("selord")),@g("_tmp")), @s("_msg",@print("[fluxx] %n trades hands with ", @shortname(@g(@print("whoref_",@g("selord")))),"."), @strloop(@substr("0123456789",0,@g("nplayers")),"z", @tell(@g("whoref_%z"),@g("_msg"))), @s("phase",@sub(@substr(@g("phasestack"),0,3),100)), @s("phasestack",@substr(@g("phasestack"),3))));
===

// 15," to select a Keeper that's in play to discard. (!Trash a Keeper!)",
@field #11960 = fn_phase15_select : 
---
TODO
===

// 16," to select a rule that's in play to discard. (!Trash a New Rule!)",
@field #11960 = fn_phase16_select : 
 @call(11960,"fn_calc_thecdab");
 @switch(@g("the_cdab"),
  "xxx",@tell("%#","[fluxx] I don't know that card. Select again."),
  "don",@tell("%#","[fluxx] You may not select \"done\" right now. Select again."),
  "hid",@tell("%#","[fluxx] You may not select \"hid\" right now. Select again."),
  ...TODO...
 );
---
TODO
===

// 17," to select a player from whom to take a card at random. (!Use what you take!)",
@field #11960 = fn_phase17_select : 
---
TODO
===

// 18,@print(" paused. ",@shortname(@print("whoref_",@g("sd_ord"))),
//  " may either select a Keeper to hide, or \"select done\" to hide no Keeper. (<Secret Data>)"),
@field #11960 = fn_phase18_select : 
---
TODO
===

// 19," to either \"select draw\" to draw an extra card,
// or \"select done\" to pass the opportunity. (<Tax Bonus>)",
@field #11960 = fn_phase19_select : 
---
TODO
===

// 20,@print(" paused. ",@shortname(@print("whoref_",@g("hl_ord"))),
//  " must discard card(s) down to the new Hand Limit."),
// 21,@print(" paused. ",@shortname(@print("whoref_",@g("kl_ord"))),
//  " must discard Keeper(s) down to the new Keeper Limit."),

// 22,@print(" paused. ",@shortname(@print("whoref_",@g("kup_ord"))),
//  " must select a hidden Keeper to reveal.")
@field #11960 = fn_phase22_select :
---
TODO
===

// tell all players about the play
// move action to discard
// remove action from hand
@field #11960 = fn_playaction :
 @s("_msg",@print("[fluxx] ",@g("whonam_turnord"),
  " plays the action ",@g(@print("cdna_",@g("the_cdab"))),"."));
 @strloop(@substr("0123456789",0,@g("nplayers")),"x",
  @tell(@g("whoref_%x"),@g("_msg")));
 @s("the_discard",@print(@g("the_cdab"),@g("the_discard")));
 @s(@g("hand_x"),@print(
  @substr(@g(@g("hand_x")),0,@g("off_cardinhand")),
  @substr(@g(@g("hand_x")),@add(@g("off_cardinhand"),3))
 ));
 @switch(@g("the_cdab"),
  "a01",@call(11960,"fn_action_dad"), "a02",@call(11960,"fn_action_d2aue"),
  "a03",@call(11960,"fn_action_d3p2ot"), "a04",@call(11960,"fn_action_ego"),
  "a05",@call(11960,"fn_action_ek"), "a06",@call(11960,"fn_action_ptt"),
  "a07",@call(11960,"fn_action_rr"), "a08",@call(11960,"fn_action_sk"),
  "a09",@call(11960,"fn_action_sb"), "a10",@call(11960,"fn_action_sak"),
  "a11",@call(11960,"fn_action_tat"), "a12",@call(11960,"fn_action_taxation"),
  "a13",@call(11960,"fn_action_th"), "a14",@call(11960,"fn_action_tak"),
  "a15",@call(11960,"fn_action_tanr"), "a16",@call(11960,"fn_action_thl"),
  "a17",@call(11960,"fn_action_tkl"), "a18",@call(11960,"fn_action_uwyt")
 );
---
TEST
@field #11960 = fn_playaction : @s("_msg",@print("[fluxx] ",@g("whonam_turnord"), " plays the action ",@g(@print("cdna_",@g("the_cdab"))),".")); @strloop(@substr("0123456789",0,@g("nplayers")),"x", @tell(@g("whoref_%x"),@g("_msg"))); @s("the_discard",@print(@g("the_cdab"),@g("the_discard"))); @s(@g("hand_x"),@print( @substr(@g(@g("hand_x")),0,@g("off_cardinhand")), @substr(@g(@g("hand_x")),@add(@g("off_cardinhand"),3)))); @switch(@g("the_cdab"), "a01",@call(11960,"fn_action_dad"), "a02",@call(11960,"fn_action_d2aue"), "a03",@call(11960,"fn_action_d3p2ot"), "a04",@call(11960,"fn_action_ego"), "a05",@call(11960,"fn_action_ek"), "a06",@call(11960,"fn_action_ptt"), "a07",@call(11960,"fn_action_rr"), "a08",@call(11960,"fn_action_sk"), "a09",@call(11960,"fn_action_sb"), "a10",@call(11960,"fn_action_sak"), "a11",@call(11960,"fn_action_tat"), "a12",@call(11960,"fn_action_taxation"), "a13",@call(11960,"fn_action_th"), "a14",@call(11960,"fn_action_tak"), "a15",@call(11960,"fn_action_tanr"), "a16",@call(11960,"fn_action_thl"), "a17",@call(11960,"fn_action_tkl"), "a18",@call(11960,"fn_action_uwyt"));
===

// DISCARD & DRAW
@field #11960 = fn_action_dad :
 @s("_nih",@idiv(@strlen(@g(@g("hand_x"))),3));
 @s("_msg",@print("[fluxx] ",@g("whonam_turnord"),
  " plays the action !Discard & draw!. ",@g("whonam_turnord"),
  " then discards the remaining ",@g("_nih"),
  " from ",@g("his")," hand, and will draw that many from the deck."));
 @strloop(@substr("0123456789",0,@g("nplayers")),"x",
  @tell(@g("whoref_%x"),@g("_msg")));
 @s("the_discard",@print(@g(@g("hand_x")),@g("the_discard")));
 @s(@g("hand_x"),"");
 @strloop(@substr(@g("the_fulldeck"),0,@g("_nih")),"x",
  @call(11960,"fn_drawcard"));
---
TEST
===

// DRAW 2 AND USE EM
@field #11960 = fn_action_d2aue :
 @s("_msg",@print("[fluxx] ",@g("whonam_turnord"),
  " plays the action !Draw 2 and use 'em!. ",@g("whonam_turnord"),
  " sets ",@g("his")," hand aside and will now draw 2 cards
  into a temporary hand."));
 @strloop(@substr("0123456789",0,@g("nplayers")),"x",
  @tell(@g("whoref_%x"),@g("_msg")));
 @s("hand_x",@print("hand-d2aue_",@g("turnord")));
 ...
 @call(11960,"fn_drawcard");
 @call(11960,"fn_drawcard");
 @s("phasestack",@print(@add(100,@g("phase")),@g("phasestack")));
 @s("phase",5);
---
TODO
===

// DRAW 3 PLAY 2 OF THEM
@field #11960 = fn_action_d3p2ot : TODO
---
===

// EVERYBODY GETS ONE
@field #11960 = fn_action_ego :
 @s("_msg",@print("[fluxx] ",@g("whonam_turnord"),
  " plays the action !Everybody gets one!. ",@g("whonam_turnord"),
  " sets ",@g("his")," hand aside and will now draw ",@g("nplayers"),
  " cards into a temporary hand (\"hand4\"), and select one card for each player."));
 @strloop(@substr("0123456789",0,@g("nplayers")),"x",
  @tell(@g("whoref_%x"),@g("_msg")));
 @s("hand_x","hand4");
 @strloop(@substr("0123456789",0,@g("nplayers")),"x",
  @call(11960,"fn_drawcard"));
 @s("phasestack",@print(@add(100,@g("phase")),@g("phasestack")));
 @s("phase",7); @s("ego_ord",0);
 @tell("%#","[fluxx] %n, Select a card from \"hand4\" to give to ",
  @shortname(@g("whoref_0")),".");
---
TEST
@field #11960 = fn_action_ego : @s("_msg",@print("[fluxx] ",@g("whonam_turnord"), " plays the action !Everybody gets one!. ",@g("whonam_turnord"), " sets ",@g("his")," hand aside and will now draw ",@g("nplayers"), " cards into a temporary hand (\"hand4\"), and select one card for each player.")); @strloop(@substr("0123456789",0,@g("nplayers")),"x", @tell(@g("whoref_%x"),@g("_msg"))); @s("hand_x","hand4"); @strloop(@substr("0123456789",0,@g("nplayers")),"x", @call(11960,"fn_drawcard")); @s("phasestack",@print(@add(100,@g("phase")),@g("phasestack"))); @s("phase",7); @s("ego_ord",0); @tell("%#","[fluxx] %n, Select a card from \"hand4\" to give to ", @shortname(@g("whoref_0")),".");
===

// EXCHANGE KEEPERS
// -- check if a) turnord has Keepers, b) someone else has Keepers.
// -- If only one other player has Keepers, autochoose him and go phase9
// -- else prompt him to choose a player, and set phase to 8.
// "_tmp1" :: does turnord have any keepers?
// "_tmp2" :: does anyone else have any keepers?
// "_numord" :: how many *other* players have keepers?
// "_tmpord" :: the *other* player (assuming only 1 other has keepers)
@field #11960 = fn_action_ek :
 @s("_tmp1",0); @s("_tmp2",0); @s("_numord",0); @s("_tmpord",99);
 @strloop(@substr("0123456789",0,@g("nplayers")),"x",
  @switch(@gt(@strlen(@g("keep_%x")),0),1,@print(
   @switch("%x",@g("turnord"),1,
    @s("_tmp1",1),
   @print(
    @s("_tmp2",1), @s("_numord",@add(1,@g("_numord"))),
    @s("_tmpord","%x")
   )
 )));
 @s("_msg",@print("[fluxx] ",@g("whonam_turnord"),
  " plays the action !Exchange Keepers!.",
  @switch(0,
   @g("_tmp1"),@print(
    " But since ",@g("whonam_turnord"),
    " has no Keepers in play, this has no effect."
   ),
   @g("_tmp2"),
    " But since no one else has Keepers in play, this has no effect."
 )));
 @strloop(@substr("0123456789",0,@g("nplayers")),"x",
  @tell(@g("whoref_%x"),@g("_msg")));
 @switch(@eq(1,@g("_tmp1"),@g("_tmp2")),1,
  @switch(@g("_numord"),1,
   @print(
    @s("ek_ord",@g("_tmpord"),
    @tell("%#",@print("[fluxx] ...",
     @shortname(@g(@print("whoref_",@g("ek_ord")))),
     "is your only opponent who has a Keeper in play...")),
    @call(11960,"fn_phase9")
   ),@print(
    @s("phase",8),
    @tell("%#","[fluxx] Select another player with whom to exchange a Keeper.")
   )
  )
 );
---
TEST
@field #11960 = fn_action_ek : @s("_tmp1",0); @s("_tmp2",0); @s("_numord",0); @s("_tmpord",99); @strloop(@substr("0123456789",0,@g("nplayers")),"x", @switch(@gt(@strlen(@g("keep_%x")),0),1,@print( @switch("%x",@g("turnord"),1, @s("_tmp1",1), @print( @s("_tmp2",1), @s("_numord",@add(1,@g("_numord"))), @s("_tmpord","%x"))))); @s("_msg",@print("[fluxx] ",@g("whonam_turnord"), " plays the action !Exchange Keepers!.", @switch(0, @g("_tmp1"),@print( " But since ",@g("whonam_turnord"), " has no Keepers in play, this has no effect."), @g("_tmp2"), " But since no one else has Keepers in play, this has no effect."))); @strloop(@substr("0123456789",0,@g("nplayers")),"x", @tell(@g("whoref_%x"),@g("_msg"))); @switch(@eq(1,@g("_tmp1"),@g("_tmp2")),1, @switch(@g("_numord"),1, @print( @s("ek_ord",@g("_tmpord"), @tell("%#",@print("[fluxx] ...", @shortname(@g(@print("whoref_",@g("ek_ord")))), "is your only opponent who has a Keeper in play...")), @call(11960,"fn_phase9")),@print( @s("phase",8), @tell("%#","[fluxx] Select another player with whom to exchange a Keeper."))));
===

// PILFER THE TRASH
@field #11960 = fn_action_ptt : TODO
---
===

// RULES RESET
// - note that all hid keepers are revealed.
@field #11960 = fn_action_rr :
 @s("_m2","");
 @fieldloop(11960,"tbl_",@switch("%v","","",@print(
  @s("_m2",@print(@g("_m2"),", ",@g("cdna_%v"))),
  @s("the_discard",@print("%v",@g("the_discard"))),
  @s("%f","")
 )));
 @s("_msg",@print("[fluxx] ",@g("whonam_turnord"),
  " plays the action !Rules Reset!. The following rule(s) are discarded: ",
  @switch(@g("_m2"),"","none",@substr(@g("_m2"),2)),"."
 ));
 @strloop(@substr("0123456789",0,@g("nplayers")),"x",
  @tell(@g("whoref_%x"),@g("_msg")));
 @fieldloop(11960,"keep_",@s("%f",@lc("%v")));
---
TEST
@field #11960 = fn_action_rr : @s("_m2",""); @fieldloop(11960,"tbl_",@switch("%v","","",@print( @s("_m2",@print(@g("_m2"),", ",@g("cdna_%v"))), @s("the_discard",@print("%v",@g("the_discard"))), @s("%f","")))); @s("_msg",@print("[fluxx] ",@g("whonam_turnord"), " plays the action !Rules Reset!. The following rule(s) are discarded: ", @switch(@g("_m2"),"","none",@substr(@g("_m2"),2)),".")); @strloop(@substr("0123456789",0,@g("nplayers")),"x", @tell(@g("whoref_%x"),@g("_msg"))); @fieldloop(11960,"keep_",@s("%f",@lc("%v")));
===

// SCRAMBLE KEEPERS
// - rule clarification if Secret Data (r20) is in play: 
//   (deal out all Keepers face up, then ask all players
//   to select a card to hide, or "select done" to hide none.)
//   (The alternative: we will deal out
//   all the Keepers face down, then ask all players to select a card
//   to keep hidden, or "select done" to reveal all.)
@field #11960 = fn_action_sk :
 @s("_allk","");
 @fieldloop(11960,"keep_",@s("_allk",@print(@g("_allk"),"%v")));
 @switch(@g("tbl_srule"),"r20",@s("_allk",@lc(@g("_allk"))));
 @s("_s","");
 @s("_n",@div(@strlen(@g("_allk")),3));
 @strloop(@substr(@g("the_fulldeck"),0,@g("_n")),"x",
 @print(
  @s("_j",@rand(@g("_n"))),
  @s("_n",@sub(@g("_n"),1)),
  @s("_s",@print(
   @g("_s"), @substr(@g("_allk"),@mul(@g("_j"),3),3)
  )),
  @s("_allk",@print(
   @substr(@g("_allk"),0,@mul(@g("_j"),3)),
   @substr(@g("_allk"),@add(3,@mul(@g("_j"),3)))
  ))
 ));
 @s("_allk",@g("_s")); @s("_s","");
 @fieldloop(11960,"keep_",@print(
  @s("%f",@substr(@g("_allk"),0,@strlen("%v"))),
  @s("_allk",@substr(@g("_allk"),@strlen("%v")))
 ));
 @s("_msg",@print("[fluxx] %n plays the action !Scramble Keepers!.
 All the Keepers in play are shuffled and redealt.",
 @switch(@g("tbl_srule"),"r20","%c[fluxx] Clarification on how
 !Scramble Keepers! works when <Secret Data> is in play. First,
 all Keepers are dealt faceup. However, each player (in turn) may now either
 select a Keeper to hide, or \"select done\" to pass the opportunity.")));
 @strloop(@substr("0123456789",0,@g("nplayers")),"z",
  @tell(@g("whoref_%z"),@g("_msg")));
 ...more TODO, re: hiding Keepers...
---
TEST
===

// SECURITY BREACH
@field #11960 = fn_action_sb :
 @s("_msg",@print("[fluxx] %n plays the action !Security Breach!.",
  @switch(@g("tbl_srule"),
   "r07"," <Government Cover-up> is discarded. All hidden Keepers are revealed.",
   "r20"," <Secret Data> is discarded. All hidden Keepers are revealed.",
   "This has no effect.")
 ));
 @strloop(@substr("0123456789",0,@g("nplayers")),"z",
  @tell(@g("whoref_%z"),@g("_msg")));
 @switch(@g("tbl_srule"),{"r07","r20"},@print(
  @s("the_discard",@print(@g("tbl_srule"),@g("the_discard"))),
  @s("tbl_srule",""),
  @fieldloop(11960,"keep_",@s("%f",@lc("%v")))
 ));
---
TEST
===

// STEAL A KEEPER
@field #11960 = fn_action_sak :
---
TODO
===

// TAKE ANOTHER TURN
// - note: play this more than once in a turn, earn multiple turns.
// - tat_count is normally 0, and always refers to the turnord player.
// - tat_again is normally 0, but set to 1 to let fn_beginturn know
//   that it's the same player again.
// - TODO: followup on using tat_count.
@field #11960 = fn_action_tat :
 @strloop(@substr("0123456789",0,@g("nplayers")),"z",
  @tell(@g("whoref_%z"),
  "[fluxx] %n plays the action !Take another turn!."
 ));
 @s("tat_count",@add(1,@g("tat_count")));
 @s("tat_again",1);
---
TEST
@field #11960 = fn_action_tat : @strloop(@substr("0123456789",0,@g("nplayers")),"z", @tell(@g("whoref_%z"), "[fluxx] %n plays the action !Take another turn!.")); @s("tat_count",@add(1,@g("tat_count"))); @s("tat_again",1);
===

// TAXATION!
@field #11960 = fn_action_taxation : 
 @strloop(@substr("0123456789",0,@g("nplayers")),"z",
  @tell(@g("whoref_%z"),"[fluxx] %n plays the action !Taxation!
  Each player must now (in turn) select a card from his or her hand
  to give to %n."));
 @s("tax_ord",0);
 @s("phasestack",@print(@add(100,@g("phase")),@g("phasestack")));
 @s("phase",13);
 @call(11960,"fn_phase13");
---
TEST
@field #11960 = fn_action_taxation : @strloop(@substr("0123456789",0,@g("nplayers")),"z", @tell(@g("whoref_%z"),"[fluxx] %n plays the action !Taxation! Each player must now (in turn) select a card from his or her hand to give to %n.")); @s("tax_ord",0); @s("phasestack",@print(@add(100,@g("phase")),@g("phasestack"))); @s("phase",13); @call(11960,"fn_phase13");
===

// Phase 13: TAXATION!
// We want to cycle thru the players and...
// - recognize when we're done and pop the stack.
// - skip the turnord player
// - autoskip other players with no cards
// - autoselect other players with 1 card
// - prompt other players to select a card
// CAUTION: This function is recursive!
@field #11960 = fn_phase13 :
 @s("tax_ordnam",@shortname(@g("whoref_",@g("tax_ord"))));
 @switch(1,
  @eq(@g("tax_ord"),@g("nplayers"),@print(
   @s("phase",@sub(@substr(@g("phasestack"),0,3),100)),
   @s("phasestack",@substr(@g("phasestack"),3))
  ),
  @eq(@g("tax_ord"),@g("turnord")),@print(
   @s("tax_ord",@add(1,@g("tax_ord"))),
   @call(11960,"fn_phase13")
  ),@eq(@strlen(@g(@print("hand_",@g("tax_ord")))),0),@print(
   @strloop(@substr("0123456789",0,@g("nplayers")),"z",
    @tell(@g("whoref_%z"),@print(
    "[fluxx] ",@g("tax_ordnam")," has no cards to give."
   ))),
   @s("tax_ord",@add(1,@g("tax_ord"))),
   @call(11960,"fn_phase13")
  ),@eq(@strlen(@g(@print("hand_",@g("tax_ord")))),3),@print(
   @s("_cdna",@g(@print("cdna_",@g(@print("hand_",@g("tax_ord")))))),
   @strloop(@substr("0123456789",0,@g("nplayers")),"z",
    @tell(@g("whoref_%z"),@switch("%z",
     @g("turnord"),@print(
      "[fluxx] ",@g("tax_ordnam")," gives ",@g("_cdna")," to you."),
     @g("tax_ord"),@print(
      "[fluxx] You automatically give your last card, ",
      @g("_cdna"),", to ",@g("whonam_turnord"),"."),
     @print(
      "[fluxx] ",@g("tax_ordnam"),
      " gives a card to ",@g("whonam_turnord"),".")
    ))
   ),
   @s(@print("hand_",@g("turnord")),@print(
    @g(@print("hand_",@g("turnord"))),
    @g(@print("hand_",@g("tax_ord")))
   )),
   @s(@print("hand_",@g("tax_ord")),""),
   @s("tax_ord",@add(1,@g("tax_ord"))),
   @call(11960,"fn_phase13")
  ),
  @tell(@g(@print("whoref_",@g("tax_ord"))),@print("[fluxx] ",
   @g("tax_ordnam"),", Select a card to give to ",
   @g("whonam_turnord"),"."
  ))
 );
---
TEST
@field #11960 = fn_phase13 : @s("tax_ordnam",@shortname(@g("whoref_",@g("tax_ord")))); @switch(1, @eq(@g("tax_ord"),@g("nplayers"),@print( @s("phase",@sub(@substr(@g("phasestack"),0,3),100)), @s("phasestack",@substr(@g("phasestack"),3))), @eq(@g("tax_ord"),@g("turnord")),@print( @s("tax_ord",@add(1,@g("tax_ord"))), @call(11960,"fn_phase13")),@eq(@strlen(@g(@print("hand_",@g("tax_ord")))),0),@print( @strloop(@substr("0123456789",0,@g("nplayers")),"z", @tell(@g("whoref_%z"),@print( "[fluxx] ",@g("tax_ordnam")," has no cards to give."))), @s("tax_ord",@add(1,@g("tax_ord"))), @call(11960,"fn_phase13")),@eq(@strlen(@g(@print("hand_",@g("tax_ord")))),3),@print( @s("_cdna",@g(@print("cdna_",@g(@print("hand_",@g("tax_ord")))))), @strloop(@substr("0123456789",0,@g("nplayers")),"z", @tell(@g("whoref_%z"),@switch("%z", @g("turnord"),@print( "[fluxx] ",@g("tax_ordnam")," gives ",@g("_cdna")," to you."), @g("tax_ord"),@print( "[fluxx] You automatically give your last card, ", @g("_cdna"),", to ",@g("whonam_turnord"),"."), @print( "[fluxx] ",@g("tax_ordnam"), " gives a card to ",@g("whonam_turnord"),".")))), @s(@print("hand_",@g("turnord")),@print( @g(@print("hand_",@g("turnord"))), @g(@print("hand_",@g("tax_ord"))))), @s(@print("hand_",@g("tax_ord")),""), @s("tax_ord",@add(1,@g("tax_ord"))), @call(11960,"fn_phase13")), @tell(@g(@print("whoref_",@g("tax_ord"))),@print("[fluxx] ", @g("tax_ordnam"),", Select a card to give to ", @g("whonam_turnord"),".")));
===

// TRADE HANDS
@field #11960 = fn_action_th :
 @strloop(@substr("0123456789",0,@g("nplayers")),"z",
  @tell(@g("whoref_%z"),"[fluxx] %n plays the action !Trade hands!"));
 @tell("%#","%n, Select a player to trade hands with.");
 @s("phasestack",@print(@add(100,@g("phase")),@g("phasestack")));
 @s("phase",14);
---
TEST
@field #11960 = fn_action_th : @strloop(@substr("0123456789",0,@g("nplayers")),"z", @tell(@g("whoref_%z"),"[fluxx] %n plays the action !Trade hands!")); @tell("%#","%n, Select a player to trade hands with."); @s("phasestack",@print(@add(100,@g("phase")),@g("phasestack"))); @s("phase",14);
===

// TRASH A KEEPER
@field #11960 = fn_action_tak :
---
TODO
===

// TRASH A NEW RULE
// _nr = number of new rules on the table?
// _rf = the rule found (tbl_ fieldname)
// _rv = the rule found (card abbrev)
@field #11960 = fn_action_tanr :
 @s("_nr",0);
 @fieldloop(11960,"tbl_",@switch(@strlen("%v"),3,@print(
  @s("_nr",@add(1,@g("_nr"))), @s("_rf","%f"), @s("_rv","%v")
 )));
 @s("_msg",@print("[fluxx] %n plays the action !Trash a New Rule!",
  @switch(@g("_ok"),0," Since there are no New Rule cards currently in
  play, this has no effect.",1,@print(" Since ",
  @g(@print("cdab_",@g("_rv"))),
  " is the only New Rule currently in play, it is discarded.")
 )));
 @strloop(@substr("0123456789",0,@g("nplayers")),"z",
  @tell(@g("whoref_%z"),@g("_msg")));
 @switch(@g("_ok"),0,"",1,@print(
  @s("the_discard",@print(@g("_rv"),@g("the_discard"))),
  @s(@g("_rf"),""),
  @switch(@g("_rf"),"tbl_srule",@fieldloop(11960,
   "keep_",@s("%f",@lc("%v"))))
 ),@print(
  @tell("%#","%n, Select a rule that's in play to discard."),
  @s("phasestack",@print(@add(100,@g("phase")),@g("phasestack"))),
  @s("phase",16)
 ));
---
TEST
@field #11960 = fn_action_tanr : @s("_nr",0); @fieldloop(11960,"tbl_",@switch(@strlen("%v"),3,@print( @s("_nr",@add(1,@g("_nr"))), @s("_rf","%f"), @s("_rv","%v")))); @s("_msg",@print("[fluxx] %n plays the action !Trash a New Rule!", @switch(@g("_ok"),0," Since there are no New Rule cards currently in play, this has no effect.",1,@print(" Since ", @g(@print("cdab_",@g("_rv"))), " is the only New Rule currently in play, it is discarded.")))); @strloop(@substr("0123456789",0,@g("nplayers")),"z", @tell(@g("whoref_%z"),@g("_msg"))); @switch(@g("_ok"),0,"",1,@print( @s("the_discard",@print(@g("_rv"),@g("the_discard"))), @s(@g("_rf"),""), @switch(@g("_rf"),"tbl_srule",@fieldloop(11960, "keep_",@s("%f",@lc("%v"))))),@print( @tell("%#","%n, Select a rule that's in play to discard."), @s("phasestack",@print(@add(100,@g("phase")),@g("phasestack"))), @s("phase",16)));
===

// TRASH HAND LIMIT
@field #11960 = fn_action_thl :
 @switch(@g("tbl_hrule"),
  "",@s("_m2","This has no effect."),
  @print(
   @s("_m2",@print("The rule ",
    @g(@print("cdna_",@g("tbl_hrule")))," is trashed."),
   @s("the_discard",@print(@g("tbl_hrule"),@g("the_discard"))),
   @s("tbl_hrule","")
 ));
 @s("_msg",@print("[fluxx] ",@g("whonam_turnord"),
  " plays the action !Trash Hand Limit!. ",@g("_m2")));
 @strloop(@substr("0123456789",0,@g("nplayers")),"x",
  @tell(@g("whoref_%x"),@g("_msg")));
---
TEST
@field #11960 = fn_action_thl : @switch(@g("tbl_hrule"), "",@s("_m2","This has no effect."), @print( @s("_m2",@print("The rule ", @g(@print("cdna_",@g("tbl_hrule")))," is trashed."), @s("the_discard",@print(@g("tbl_hrule"),@g("the_discard"))), @s("tbl_hrule",""))); @s("_msg",@print("[fluxx] ",@g("whonam_turnord"), " plays the action !Trash Hand Limit!. ",@g("_m2"))); @strloop(@substr("0123456789",0,@g("nplayers")),"x", @tell(@g("whoref_%x"),@g("_msg")));
===

// TRASH KEEPER LIMIT
@field #11960 = fn_action_tkl :
 @switch(@g("tbl_krule"),
  "",@s("_m2","This has no effect."),
  @print(
   @s("_m2",@print("The rule ",
    @g(@print("cdna_",@g("tbl_krule")))," is trashed."),
   @s("the_discard",@print(@g("tbl_krule"),@g("the_discard"))),
   @s("tbl_krule","")
 ));
 @s("_msg",@print("[fluxx] ",@g("whonam_turnord"),
  " plays the action !Trash Keeper Limit!. ",@g("_m2")));
 @strloop(@substr("0123456789",0,@g("nplayers")),"x",
  @tell(@g("whoref_%x"),@g("_msg")));
---
TEST
@field #11960 = fn_action_tkl : @switch(@g("tbl_krule"), "",@s("_m2","This has no effect."), @print( @s("_m2",@print("The rule ", @g(@print("cdna_",@g("tbl_krule")))," is trashed."), @s("the_discard",@print(@g("tbl_krule"),@g("the_discard"))), @s("tbl_krule",""))); @s("_msg",@print("[fluxx] ",@g("whonam_turnord"), " plays the action !Trash Keeper Limit!. ",@g("_m2"))); @strloop(@substr("0123456789",0,@g("nplayers")),"x", @tell(@g("whoref_%x"),@g("_msg")));
===

// USE WHAT YOU TAKE
// - 1st, count number of other players with cards
// - If no such player, this card has no effect
// - If only one such player, autochoose that player, continue with ???
// - Else, ask turnord to select a player with cards.
@field #11960 = fn_action_uwyt :
---
TODO
===

// tell all players about the play
// move old goal to discard
// put goal on table
// remove goal from hand
@field #11960 = fn_playgoal :
 @s("_msg",@print("[fluxx] ",@g("whonam_turnord"),
  " plays the goal ",@g(@print("cdna_",@g("the_cdab"))),
  @switch(@strlen(@g("the_goal")),3,@print(
  ", replacing ",@g(@print("cdna_",@g("the_goal")))
  )),"."));
 @strloop(@substr("0123456789",0,@g("nplayers")),"x",
  @tell(@g("whoref_%x"),@g("_msg")));
 @s("the_discard",@print(@g("the_goal"),@g("the_discard")));
 @s("the_goal",@g("the_cdab"));
 @s(@g("hand_x"),@print(
  @substr(@g(@g("hand_x")),0,@g("off_cardinhand")),
  @substr(@g(@g("hand_x")),@add(@g("off_cardinhand"),3))
 ));
---
TEST
@field #11960 = fn_playgoal : @s("_msg",@print("[fluxx] ",@g("whonam_turnord"), " plays the goal ",@g(@print("cdna_",@g("the_cdab"))), @switch(@strlen(@g("the_goal")),3,@print(", replacing ",@g(@print("cdna_",@g("the_goal"))))),".")); @strloop(@substr("0123456789",0,@g("nplayers")),"x", @tell(@g("whoref_%x"),@g("_msg"))); @s("the_discard",@print(@g("the_goal"),@g("the_discard"))); @s("the_goal",@g("the_cdab")); @s(@g("hand_x"),@print( @substr(@g(@g("hand_x")),0,@g("off_cardinhand")), @substr(@g(@g("hand_x")),@add(@g("off_cardinhand"),3))));
===

// tell all players about the play
// append keeper to player's keepers on table
// remove keeper from hand
// TODO: if 2 or more hid Keepers while Secret Data:
//  then player must select a Keeper to reveal.
@field #11960 = fn_playkeeper :
 @s("_msg",@print("[fluxx] ",@g("whonam_turnord"),
  @switch(@strlen(@g("tbl_srule")),3," plays a Keeper face down.",@print(
  " plays the Keeper ",@g(@print("cdna_",@g("the_cdab"))),"."))));
 @strloop(@substr("0123456789",0,@g("nplayers")),"x",
  @tell(@g("whoref_%x"),@g("_msg")));
 @s(@g("keep_x"),@print(@g(@g("keep_x")),
  @switch(@strlen(@g("tbl_srule")),3,@uc(@g("the_cdab")),@g("the_cdab"))));
 @s(@g("hand_x"),@print(
  @substr(@g(@g("hand_x")),0,@g("off_cardinhand")),
  @substr(@g(@g("hand_x")),@add(@g("off_cardinhand"),3))
 ));
---
TEST
@field #11960 = fn_playkeeper : @s("_msg",@print("[fluxx] ",@g("whonam_turnord"), @switch(@strlen(@g("tbl_srule")),3," plays a Keeper face down.",@print( " plays the Keeper ",@g(@print("cdna_",@g("the_cdab"))),".")))); @strloop(@substr("0123456789",0,@g("nplayers")),"x", @tell(@g("whoref_%x"),@g("_msg"))); @s(@g("keep_x"),@print(@g(@g("keep_x")), @switch(@strlen(@g("tbl_srule")),3,@uc(@g("the_cdab")),@g("the_cdab")))); @s(@g("hand_x"),@print( @substr(@g(@g("hand_x")),0,@g("off_cardinhand")), @substr(@g(@g("hand_x")),@add(@g("off_cardinhand"),3))));
===

// tell all players about the play
// move old conflicting rule to discard
// put rule on table
// remove rule from hand
// if new rule is r07 (Govt Cover-Up), hide all keepers in play.
@field #11960 = fn_playrule :
 @s("_slot",@switch(@g("the_cdab"),
  {"r02","r03","r04","r05"},"tbl_drule", "r21","tbl_dbonus",
  {"r16","r17","r18","r19"},"tbl_prule", "r22","tbl_pbonus",
  "r06","tbl_pfinal", {"r08","r09","r10","r11"},"tbl_hrule",
  "r01","tbl_hbonus", {"r12","r13","r14"},"tbl_krule",
  "r15","tbl_kbonus", {"r07","r20"},"tbl_srule"
  ));
 @s("_msg",@print("[fluxx] ",@g("whonam_turnord"),
  " plays the new rule ",@g(@print("cdna_",@g("the_cdab"))),
  @switch(@strlen(@g(@g("_slot"))),3,@print(
  ", replacing ",@g(@print("cdna_",@g(@g("_slot"))))
  )),".",
  @switch(@g("the_cdab"),"r07"," All Keepers are now hidden.")
 ));
 @strloop(@substr("0123456789",0,@g("nplayers")),"x",
  @tell(@g("whoref_%x"),@g("_msg")));
 @s("the_discard",@print(@g(@g("_slot")),@g("the_discard")));
 @s(@g("_slot"),@g("the_cdab"));
 @s(@g("hand_x"),@print(
  @substr(@g(@g("hand_x")),0,@g("off_cardinhand")),
  @substr(@g(@g("hand_x")),@add(@g("off_cardinhand"),3))
 ));
 @switch(@g("the_cdab"),"r07",@fieldloop(11960,"keep_",
  @s("%f",@uc("%v")) ));
---
TEST
@field #11960 = fn_playrule : @s("_slot",@switch(@g("the_cdab"), {"r02","r03","r04","r05"},"tbl_drule", "r21","tbl_dbonus", {"r16","r17","r18","r19"},"tbl_prule", "r22","tbl_pbonus", "r06","tbl_pfinal", {"r08","r09","r10","r11"},"tbl_hrule", "r01","tbl_hbonus", {"r12","r13","r14"},"tbl_krule", "r15","tbl_kbonus", {"r07","r20"},"tbl_srule")); @s("_msg",@print("[fluxx] ",@g("whonam_turnord"), " plays the new rule ",@g(@print("cdna_",@g("the_cdab"))), @switch(@strlen(@g(@g("_slot"))),3,@print( ", replacing ",@g(@print("cdna_",@g(@g("_slot")))))),".", @switch(@g("the_cdab"),"r07"," All Keepers are now hidden."))); @strloop(@substr("0123456789",0,@g("nplayers")),"x", @tell(@g("whoref_%x"),@g("_msg"))); @s("the_discard",@print(@g(@g("_slot")),@g("the_discard"))); @s(@g("_slot"),@g("the_cdab")); @s(@g("hand_x"),@print( @substr(@g(@g("hand_x")),0,@g("off_cardinhand")), @substr(@g(@g("hand_x")),@add(@g("off_cardinhand"),3)))); @switch(@g("the_cdab"),"r07",@fieldloop(11960,"keep_", @s("%f",@uc("%v"))));
===

 // assume field the_cdab.
@field #11960 = fn_readcard :
 @switch(@g("the_cdab"),"xxx","[fluxx] I don't know that card.",
  "don","[fluxx] \"done\" isn't an actual card.",
 @tell("%#",@print("** ",
  @switch(@substr(@g("the_cdab"),0,1),"a","ACTION: ",
   "g","GOAL: ","k","KEEPER: ","r","NEW RULE: "),
  @g(@print("cdna_",@g("the_cdab"))),
  " **%c",@g(@print("cdtx_",@g("the_cdab")))
 )));
---
TEST
@field #11960 = fn_readcard : @switch(@g("the_cdab"),"xxx","[fluxx] I don't know that card.",   "don","[fluxx] \"done\" isn't an actual card.", @tell("%#",@print("** ", @switch(@substr(@g("the_cdab"),0,1),"a","ACTION: ", "g","GOAL: ","k","KEEPER: ","r","NEW RULE: "), @g(@print("cdna_",@g("the_cdab"))), " **%c",@g(@print("cdtx_",@g("the_cdab"))) )));
===

@field #11960 = fn_readdiscard :
 @switch(0,
  @gt(@g("phase"),0),
   "This is the pre-game phase. No hands have been dealt yet.",
  @print(
   @s("_n",@div(@strlen(@g("the_discard")),3)),
   @s("_off",0),
   @tell("%#",@print("Discards (from top to bottom):",@substr(
    @strloop(@substr(@g("the_fulldeck"),0,@g("_n")),"x",@print(
     @s("_ab",@substr(@g("the_discard"),@g("_off"),3)),
     ", ",@g(@print("cdna_",@g("_ab"))),
     @s("_off",@add(3,@g("_off")))
    ))
   ,1)))
 ));
---
TEST
@field #11960 = fn_readdiscard : @switch(0, @gt(@g("phase"),0), "This is the pre-game phase. No hands have been dealt yet.", @print( @s("_n",@div(@strlen(@g("the_discard")),3)), @s("_off",0), @tell("%#",@print("Discards (from top to bottom):",@substr( @strloop(@substr(@g("the_fulldeck"),0,@g("_n")),"x",@print( @s("_ab",@substr(@g("the_discard"),@g("_off"),3)), ", ",@g(@print("cdna_",@g("_ab"))), @s("_off",@add(3,@g("_off"))))),1)))));
===

@field #11960 = fn_readhand :
 @call(11960,"fn_calc_whoord");
 @switch(0,
  @gt(@g("phase"),0),
   "This is the pre-game phase. No hands have been dealt yet.",
  @lt(@g("whoord"),99),
   "You have no hand. You haven't joined the game.",
  @print(
   @s("the_hand",@g(@print("hand_",@g("whoord")))),
   @s("_n",@div(@strlen(@g("the_hand")),3)),
   @s("_off",0),
   @tell("%#",@print("Your hand:",@substr(
    @strloop(@substr(@g("the_fulldeck"),0,@g("_n")),"x",@print(
     @s("_ab",@substr(@g("the_hand"),@g("_off"),3)),
     ", ",@g(@print("cdna_",@g("_ab"))),
     @s("_off",@add(3,@g("_off")))
    ))
   ,1)))
 ));
---
TEST
@field #11960 = fn_readhand : @call(11960,"fn_calc_whoord"); @switch(0, @gt(@g("phase"),0), "This is the pre-game phase. No hands have been dealt yet.", @lt(@g("whoord"),99), "You have no hand. You haven't joined the game.", @print( @s("the_hand",@g(@print("hand_",@g("whoord")))), @s("_n",@div(@strlen(@g("the_hand")),3)), @s("_off",0), @tell("%#",@print("Your hand:",@substr( @strloop(@substr(@g("the_fulldeck"),0,@g("_n")),"x",@print( @s("_ab",@substr(@g("the_hand"),@g("_off"),3)), ", ",@g(@print("cdna_",@g("_ab"))), @s("_off",@add(3,@g("_off"))))),1)))));
===

@field #11960 = fn_readtable :
 @print("THE GOAL: ",
 @switch(@g("the_goal"),"","(none)",@g(@print("cdna_",@g("the_goal")))),
 "%cTHE RULES: ",
 @switch(@g("tbl_drule"),"","(draw 1)",@g(@print("cdna_",@g("tbl_drule")))),
 @switch(@g("tbl_dbonus"),"r21"," + <Tax Bonus>"),", ",
 @switch(@g("tbl_prule"),"","(play 1)",@g(@print("cdna_",@g("tbl_prule")))),
 @switch(@g("tbl_pbonus"),"r22"," + <Time Bonus>"),
 @switch(@g("tbl_pfinal"),"r06"," + <Final Card Random>"),", ",
 @switch(@g("tbl_hrule"),"","(no hand limit)",@g(@print("cdna_",@g("tbl_hrule")))),
 @switch(@g("tbl_hbonus"),"r01"," + <Brain Bonus>"),", ",
 @switch(@g("tbl_krule"),"","(no Keeper limit)",@g(@print("cdna_",@g("tbl_krule")))),
 @switch(@g("tbl_kbonus"),"r15"," + <Money Bonus>"),
 @switch(@g("tbl_srule"),"r07"," + <Government Cover-Up>","r20"," + <Secret Data>"),".",
 @strloop(@substr("0123456789",0,@g("nplayers")),"z",@print(
  "%c- ",@shortname(@g("whoref_%z"))," has",

  @switch(@g("keep_%z"),""," no Keepers",@print(
   @s("_n",@idiv(@strlen(@g("keep_%z")),3)),
   @s("_off",0),
   @substr(@strloop(@substr(@g("the_fulldeck"),0,@g("_n")),"y",@print(
    @s("_ab",@substr(@g("keep_%z"),@g("_off"),3)),", ",
    @switch(@substr(@g("_ab"),0,1),"K",@print(
     "(",
     @switch(@or(@eq("%z",@g("whoord")),@eq(@g("phase"),99)),
      1,@g(@print("cdna_",@g("_ab"))),"$hid$"),
     ")"),
     @g(@print("cdna_",@g("_ab")))
    ),
    @s("_off",@add(3,@g("_off")))
   )),1)
  )),

  "; ",@idiv(@strlen(@g("hand_%z")),3)," card(s) in hand."))
 );
 @print("%cTHE PHASE: ",@call(11960,@print("fn_phna_",@g("phase"))));


// Phase names
@field #11960 = fn_phna_0: Pre-game.
@field #11960 = fn_phna_1: @print(@g("whonam_turnord"),", Draw a card.")
@field #11960 = fn_phna_2: @print(@g("whonam_turnord"),", Play a card.")
@field #11960 = fn_phna_3: @print(@g("whonam_turnord"),", Discard card(s) down to Hand Limit.")
@field #11960 = fn_phna_4: @print(@g("whonam_turnord"),", Discard Keeper(s) down to Keeper Limit.")
@field #11960 = fn_phna_5: @print(@g("whonam_turnord"),", Play card from \"hand2\". (!Draw 2 and use 'em!)")
@field #11960 = fn_phna_6: @print(@g("whonam_turnord"),", Play card from \"hand3\". (!Draw 3 play 2 of them!)")
@field #11960 = fn_phna_7: @print(@g("whonam_turnord"),", Select a card to give to ",@shortname(@print("whoref_",@g("ego_ord")))," from \"hand4\". (!Everybody gets one!)")
@field #11960 = fn_phna_8: @print(@g("whonam_turnord"),", Select a player with whom to exchange a Keeper. (!Exchange Keepers!)")
@field #11960 = fn_phna_9: @print(@g("whonam_turnord"),", Select a Keeper to give to ",@shortname(@print("whoref_",@g("ek_ord"))),".")
@field #11960 = fn_phna_10: @print(@g("whonam_turnord"),", Select a Keeper to take from ",@shortname(@print("whoref_",@g("ek_ord"))),".")
@field #11960 = fn_phna_11: @print(@g("whonam_turnord"),", Select a card from top 3 cards of discard pile. (!Pilfer the Trash!)")
@field #11960 = fn_phna_12: @print(@g("whonam_turnord"),", Select a Keeper to take from any other player. (!Steal a Keeper!)")
@field #11960 = fn_phna_13: @print(@g("whonam_turnord"),"'s turn. ",@shortname(@print("whoref_",@g("tax_ord"))),", Select a card to give to ",@g("whonam_turnord"),". (!Taxation!)")
@field #11960 = fn_phna_14: @print(@g("whonam_turnord"),", Select a player with whom to trade hands. (!Trade hand!)")
@field #11960 = fn_phna_15: @print(@g("whonam_turnord"),", Select a Keeper that's in play to discard. (!Trash a Keeper!)")
@field #11960 = fn_phna_16: @print(@g("whonam_turnord"),", Select a rule that's in play to discard. (!Trash a New Rule!)")
@field #11960 = fn_phna_17: @print(@g("whonam_turnord"),", Select a player from whom to take a card at random. (!Use what you take!)")
@field #11960 = fn_phna_18: @print(@g("whonam_turnord"),"'s turn. ",@shortname(@print("whoref_",@g("sd_ord"))),", Either select a Keeper to hide, or \"select done\" to hide no Keeper. (<Secret Data>)")
@field #11960 = fn_phna_19: @print(@g("whonam_turnord"),", Either \"select draw\" to draw an extra card, or \"select done\" to pass the opportunity. (<Tax Bonus>)")
@field #11960 = fn_phna_20: @print(@g("whonam_turnord"),"'s turn. ",@shortname(@print("whoref_",@g("hl_ord"))),", Discard card(s) down to the new Hand Limit.")
@field #11960 = fn_phna_21: @print(@g("whonam_turnord"),"'s turn. ",@shortname(@print("whoref_",@g("kl_ord"))),", Discard Keeper(s) down to the new Keeper Limit.")
@field #11960 = fn_phna_22: @print(@g("whonam_turnord"),"'s turn. ",@shortname(@print("whoref_",@g("kup_ord"))),", Select a hidden Keeper to reveal.")
@field #11960 = fn_phna_99: @print("Post-game. ",@g("winners")," won the game!")

@field #11960 = fn_shuffle :
 @s("_s","");
 @s("_n",@div(@strlen(@g("the_deck")),3));
 @strloop(@substr(@g("the_fulldeck"),0,@g("_n")),"x",
 @print(
  @s("_j",@rand(@g("_n"))),
  @s("_n",@sub(@g("_n"),1)),
  @s("_s",@print(
   @g("_s"), @substr(@g("the_deck"),@mul(@g("_j"),3),3)
  )),
  @s("the_deck",@print(
   @substr(@g("the_deck"),0,@mul(@g("_j"),3)),
   @substr(@g("the_deck"),@add(3,@mul(@g("_j"),3)))
  ))
 ));
 @s("the_deck",@g("_s")); @s("_s","");
---
@field #11960 = fn_shuffle : @s("_s",""); @s("_n",@div(@strlen(@g("the_deck")),3)); @strloop(@substr(@g("the_fulldeck"),0,@g("_n")),"x", @print( @s("_j",@rand(@g("_n"))), @s("_n",@sub(@g("_n"),1)), @s("_s",@print( @g("_s"), @substr(@g("the_deck"),@mul(@g("_j"),3),3) )), @s("the_deck",@print( @substr(@g("the_deck"),0,@mul(@g("_j"),3)), @substr(@g("the_deck"),@add(3,@mul(@g("_j"),3))) )) )); @s("the_deck",@g("_s")); @s("_s","");
===

// (oh_k means ordhas_k, ie: who has keeper XX?
// -- value is player order # if that player has it, or -1 if no one does.)
@field #11960 = fn_testwin :
 @fieldloop(11960,"oh_k",@s("%f","-1"));
 @strloop(@substr("0123456789",0,@g("nplayers")),"z",@print(
  @s("_nk",@idiv(@strlen(@g("keep_%z")),3)),
  @s("_i",0),
  @strloop(@substr(@g("keep_%z"),0,@g("_nk")),"y",@print(
   @s(@print("oh_",@substr(@g("keep_%z"),@g("_i"),3)),"%z"),
   @s("_i",@add(3,@g("_i")))
  ))
 ));
 @s("winners",""); @s("nwinners",0);
 @strloop(@substr("0123456789",0,@g("nplayers")),"z",@print(
  @s("won",0),
  @switch(@g("the_goal"),
  // 10 cards in hand
  "g01", @switch(@gt(@strlen(@g("hand_%z")),29),1,@s("won",1)),
  // 5 Keepers
  "g02", @switch(@gt(@strlen(@g("keep_%z")),14),1,@s("won",1)),
  // All you need is love (only k07)
  "g03", @switch(@lc(@g("keep_%z")),"k07",@s("won",1)),
  // Chocolate Cookies (k02 + k03)
  "g04", @switch(@eq("%z",@g("oh_k02"),@g("oh_k03")),1,@s("won",1)),
  // Chocolate Milk (k02 + k08)
  "g05", @switch(@eq("%z",@g("oh_k02"),@g("oh_k08")),1,@s("won",1)),
  // Coffee and Doughnuts (k04 + k06)
  "g06", @switch(@eq("%z",@g("oh_k04"),@g("oh_k06")),1,@s("won",1)),
  // Death and Taxes (k05 + k11)
  "g07", @switch(@eq("%z",@g("oh_k05"),@g("oh_k11")),1,@s("won",1)),
  // Death by Chocolate (k05 + k02)
  "g08", @switch(@eq("%z",@g("oh_k05"),@g("oh_k02")),1,@s("won",1)),
  // Hippyism (k10 + k07)
  "g09", @switch(@eq("%z",@g("oh_k10"),@g("oh_k07")),1,@s("won",1)),
  // Milk and Cookies (k08 + k03)
  "g10", @switch(@eq("%z",@g("oh_k08"),@g("oh_k03")),1,@s("won",1)),
  // Money (no Taxes) (k09 + no one with k11)
  "g11", @switch(@and(@eq("%z",@g("oh_k09")),@eq("-1",@g("oh_k11"))),1,@s("won",1)),
  // Peace (no War) (k10 + no one with k21)
  "g12", @switch(@and(@eq("%z",@g("oh_k10")),@eq("-1",@g("oh_k21"))),1,@s("won",1)),
  // Rocket to the Moon (k17 + k15)
  "g13", @switch(@eq("%z",@g("oh_k17"),@g("oh_k15")),1,@s("won",1)),
  // The Appliances (k19 + k12)
  "g14", @switch(@eq("%z",@g("oh_k19"),@g("oh_k12")),1,@s("won",1)),
  // The Brain (no TV) (k13 + no one with k12)
  "g15", @switch(@and(@eq("%z",@g("oh_k13")),@eq("-1",@g("oh_k12"))),1,@s("won",1)),
  // The Great Seal (k14 + k16)
  "g16", @switch(@eq("%z",@g("oh_k14"),@g("oh_k16")),1,@s("won",1)),
  // The Mind's Eye (k14 + k13)
  "g17", @switch(@eq("%z",@g("oh_k14"),@g("oh_k13")),1,@s("won",1)),
  // The Sun & the Moon (k18 + k15)
  "g18", @switch(@eq("%z",@g("oh_k18"),@g("oh_k15")),1,@s("won",1)),
  // Time is Money (k20 + k09)
  "g19", @switch(@eq("%z",@g("oh_k20"),@g("oh_k09")),1,@s("won",1)),
  // Toast (k01 + k19)
  "g20", @switch(@eq("%z",@g("oh_k01"),@g("oh_k19")),1,@s("won",1)),
  // War and Death (k21 + k05)
  "g21", @switch(@eq("%z",@g("oh_k21"),@g("oh_k05")),1,@s("won",1))),
  @switch(@g("won"),1,@s("winners",@print(
   @s("nwinners",@add(1,@g("nwinners"))),
   @g("winners")," and ",@shortname(@g("whoref_%z")) )))
 ));
 @switch(@gt(@g("nwinners"),0),1,@print(
  @s("phase",99),
  @s("winners",@substr(@g("winners"),5)),
  @s("_msg",@print("[fluxx] *** The game is over! ",
   @g("winners"),@switch(@g("nwinners"),1," has"," have"),
   " just won the game! ***")),
  @strloop(@substr("0123456789",0,@g("nplayers")),"z",
   @tell(@g("whoref_%z"),@g("_msg")))
 ));
---
TEST
@field #11960 = fn_testwin : @fieldloop(11960,"oh_k",@s("%f","-1")); @strloop(@substr("0123456789",0,@g("nplayers")),"z",@print( @s("_nk",@idiv(@strlen(@g("keep_%z")),3)), @s("_i",0), @strloop(@substr(@g("keep_%z"),0,@g("_nk")),"y",@print( @s(@print("oh_",@substr(@g("keep_%z"),@g("_i"),3)),"%z"), @s("_i",@add(3,@g("_i"))))))); @s("winners",""); @s("nwinners",0); @strloop(@substr("0123456789",0,@g("nplayers")),"z",@print( @s("won",0), @switch(@g("the_goal"), "g01", @switch(@gt(@strlen(@g("hand_%z")),29),1,@s("won",1)), "g02", @switch(@gt(@strlen(@g("keep_%z")),14),1,@s("won",1)), "g03", @switch(@lc(@g("keep_%z")),"k07",@s("won",1)), "g04", @switch(@eq("%z",@g("oh_k02"),@g("oh_k03")),1,@s("won",1)), "g05", @switch(@eq("%z",@g("oh_k02"),@g("oh_k08")),1,@s("won",1)), "g06", @switch(@eq("%z",@g("oh_k04"),@g("oh_k06")),1,@s("won",1)), "g07", @switch(@eq("%z",@g("oh_k05"),@g("oh_k11")),1,@s("won",1)), "g08", @switch(@eq("%z",@g("oh_k05"),@g("oh_k02")),1,@s("won",1)), "g09", @switch(@eq("%z",@g("oh_k10"),@g("oh_k07")),1,@s("won",1)), "g10", @switch(@eq("%z",@g("oh_k08"),@g("oh_k03")),1,@s("won",1)), "g11", @switch(@and(@eq("%z",@g("oh_k09")),@eq("-1",@g("oh_k11"))),1,@s("won",1)), "g12", @switch(@and(@eq("%z",@g("oh_k10")),@eq("-1",@g("oh_k21"))),1,@s("won",1)), "g13", @switch(@eq("%z",@g("oh_k17"),@g("oh_k15")),1,@s("won",1)), "g14", @switch(@eq("%z",@g("oh_k19"),@g("oh_k12")),1,@s("won",1)), "g15", @switch(@and(@eq("%z",@g("oh_k13")),@eq("-1",@g("oh_k12"))),1,@s("won",1)), "g16", @switch(@eq("%z",@g("oh_k14"),@g("oh_k16")),1,@s("won",1)), "g17", @switch(@eq("%z",@g("oh_k14"),@g("oh_k13")),1,@s("won",1)), "g18", @switch(@eq("%z",@g("oh_k18"),@g("oh_k15")),1,@s("won",1)), "g19", @switch(@eq("%z",@g("oh_k20"),@g("oh_k09")),1,@s("won",1)), "g20", @switch(@eq("%z",@g("oh_k01"),@g("oh_k19")),1,@s("won",1)), "g21", @switch(@eq("%z",@g("oh_k21"),@g("oh_k05")),1,@s("won",1))), @switch(@g("won"),1,@s("winners",@print( @s("nwinners",@add(1,@g("nwinners"))), @g("winners")," and ",@shortname(@g("whoref_%z"))))))); @switch(@gt(@g("nwinners"),0),1,@print(@s("phase",99), @s("winners",@substr(@g("winners"),5)), @s("_msg",@print("[fluxx] *** The game is over! ",@g("winners"),@switch(@g("nwinners"),1," has"," have"), " just won the game! ***")), @strloop(@substr("0123456789",0,@g("nplayers")),"z", @tell(@g("whoref_%z"),@g("_msg")))));
===

@field fluxx = basicrules :
 SETUP:  Each player is dealt 3 cards. One player is randomly chosen
 to go first. Players take turns in the order they joined the game
 until someone wins. When the deck is exhausted, the discards are shuffled
 and returned to the deck.
 %cPLAYER'S TURN:  1. Draw the number of cards currently required. /
 2. Play the number of cards currently required. / 3. Discard down to
 the current Hand Limit (if any). / 4. Discard Keepers down to the current
 Keeper Limit (if any).
 %cHOW TO WIN:  First player to satisfy the current Goal immediately
 wins, even if it's during someone else's turn. The game begins with no
 Goal, so no one can win until someone plays a Goal.
 %cTHE FOUR CARD TYPES:
 %c-- !ACTION!: When you play an Action, do whatever it says.
 %c-- *GOAL*: When you play a Goal, it becomes the new goal of the game.
 Any previous Goal is discarded.
 %c-- $KEEPER$: Keepers are played face up in front of you.
 %c-- <NEW RULE>: A rule goes into effect as soon as you play it.
 All players must *immediately* conform to the new rule.
 Any older rule that contradicts it is discarded.

// cdna_X = card #X's name
// cdtx_X = card #X's text
// cdty_X = card #X's type (a=Action,g=Goal,k=Keeper,r=New Rule)

// Actions
@field fluxx = cdna_a01 : !Discard & draw!
@field fluxx = cdna_a02 : !Draw 2 and use 'em!
@field fluxx = cdna_a03 : !Draw 3 play 2 of them!
@field fluxx = cdna_a04 : !Everybody gets one!
@field fluxx = cdna_a05 : !Exchange Keepers!
@field fluxx = cdna_a06 : !Pilfer the Trash!
@field fluxx = cdna_a07 : !Rules Reset!
@field fluxx = cdna_a08 : !Scramble Keepers!
@field fluxx = cdna_a09 : !Security breach!
@field fluxx = cdna_a10 : !Steal a Keeper!
@field fluxx = cdna_a11 : !Take another turn!
@field fluxx = cdna_a12 : !Taxation!
@field fluxx = cdna_a13 : !Trade hands!
@field fluxx = cdna_a14 : !Trash a Keeper!
@field fluxx = cdna_a15 : !Trash a New Rule!
@field fluxx = cdna_a16 : !Trash Hand Limit!
@field fluxx = cdna_a17 : !Trash Keeper Limit!
@field fluxx = cdna_a18 : !Use what you take!
@field fluxx = cdtx_a01 : Discard your entire hand, then draw as many cards as you discarded. / Do not count this card when determining how many replacement cards to draw.
@field fluxx = cdtx_a02 : Set your hand aside. Draw 2 cards and play them both, then continue with your turn. / This card, and all cards played because of it, are counted as a single play.
@field fluxx = cdtx_a03 : Set your hand aside. Draw 3 cards and play 2 of them. Discard the third and continue with your turn. / This card, and all cards played because of it, are counted as a single play.
@field fluxx = cdtx_a04 : Count the number of players in the game (including yourself). Draw that many cards, and give one to each player. / You decide who gets which card.
@field fluxx = cdtx_a05 : Give one of your keepers to an opponent, and take a Keeper of your choice from that player in return. / If you have no Keepers, or if you are the only player with any Keepers, do nothing.
@field fluxx = cdtx_a06 : Look at the top 3 cards of the discard pile and put the one you like best in your hand.
@field fluxx = cdtx_a07 : Reset to Basic Rules. / Discard all New Rule cards, and leave only the original Basic Rules card in play. Do not discard the current Goal. If any Keepers were hidden, reveal them.
@field fluxx = cdtx_a08 : Gather up everyone's Keepers, shuffle them together, and deal them back out at random. Each player should receive the same number of Keepers he or she started with.
@field fluxx = cdtx_a09 : Discard Government Cover-up or Secret Data if either is in play. / Reveal all Keepers in play.
@field fluxx = cdtx_a10 : Steal a Keeper from another player and add it to your collection of Keepers.
@field fluxx = cdtx_a11 : Take another turn as soon as you finish this one.
@field fluxx = cdtx_a12 : Each player must choose a card from his or her hand and give it to you.
@field fluxx = cdtx_a13 : Trade your hand for the hand of one of your opponents. / This is one of those times when you can get something for nothing.
@field fluxx = cdtx_a14 : Take a Keeper from any player and put it on the discard pile.
@field fluxx = cdtx_a15 : Select one of the New Rules card in play and place it in the discard pile.
@field fluxx = cdtx_a16 : If a Hand Limit rule is in force, discard it.
@field fluxx = cdtx_a17 : If a Keeper Limit is in force, discard it.
@field fluxx = cdtx_a18 : Take a card at random from another player's hand and play it.

// Goals
@field fluxx = cdna_g01 : *10 cards in hand*
@field fluxx = cdna_g02 : *5 Keepers*
@field fluxx = cdna_g03 : *All you need is love*
@field fluxx = cdna_g04 : *Chocolate Cookies*
@field fluxx = cdna_g05 : *Chocolate Milk*
@field fluxx = cdna_g06 : *Coffee and Doughnuts*
@field fluxx = cdna_g07 : *Death and Taxes*
@field fluxx = cdna_g08 : *Death by Chocolate*
@field fluxx = cdna_g09 : *Hippyism*
@field fluxx = cdna_g10 : *Milk and Cookies*
@field fluxx = cdna_g11 : *Money (no Taxes)*
@field fluxx = cdna_g12 : *Peace (no War)*
@field fluxx = cdna_g13 : *Rocket to the Moon*
@field fluxx = cdna_g14 : *The Appliances*
@field fluxx = cdna_g15 : *The Brain (no TV)*
@field fluxx = cdna_g16 : *The Great Seal*
@field fluxx = cdna_g17 : *The Mind's Eye*
@field fluxx = cdna_g18 : *The Sun & the Moon*
@field fluxx = cdna_g19 : *Time is Money*
@field fluxx = cdna_g20 : *Toast*
@field fluxx = cdna_g21 : *War and Death*
@field fluxx = cdtx_g01 : If someone has 10 or more cards in his or her hand, then the player with the most cards in hand wins.
@field fluxx = cdtx_g02 : If someone has 5 or more Keepers in play, then the player with the most Keepers in play wins.
@field fluxx = cdtx_g03 : The player who has Love on the table wins, if (and only if) that player has no other Keepers on the table.
@field fluxx = cdtx_g04 : The player who has both Chocolate and Cookies on the table wins.
@field fluxx = cdtx_g05 : The player who has both Chocolate and Milk on the table wins.
@field fluxx = cdtx_g06 : The player who has both Coffee and Doughnuts on the table wins.
@field fluxx = cdtx_g07 : The player who has both Death and Taxes on the table wins.
@field fluxx = cdtx_g08 : The player who has both Chocolate and Death on the table wins.
@field fluxx = cdtx_g09 : The player who has both Peace and Love on the table wins.
@field fluxx = cdtx_g10 : The player who has both Milk and Cookies on the table wins.
@field fluxx = cdtx_g11 : If no one has Taxes on the table (visible or hid), then the player who has Money in play wins.
@field fluxx = cdtx_g12 : If no one has War on the table (visible or hid), then the player who has Peace in play wins.
@field fluxx = cdtx_g13 : The player who has both the Rocket and the Moon on the table wins.
@field fluxx = cdtx_g14 : The player who has both the Toaster and Television on the table wins.
@field fluxx = cdtx_g15 : If no one has Television on the table (visible or hid), then the player who has the Brain in play wins.
@field fluxx = cdtx_g16 : The player who has both the Eye and the Pyramid on the table wins.
@field fluxx = cdtx_g17 : The player who has both the Eye and the Brain on the table wins.
@field fluxx = cdtx_g18 : The player who has both the Sun and the Moon on the table wins.
@field fluxx = cdtx_g19 : The player who has both Time and Money on the table wins.
@field fluxx = cdtx_g20 : The player who has both Bread and the Toaster on the table wins.
@field fluxx = cdtx_g21 : The player who has both War and Death on the table wins.

// Keepers
@field fluxx = cdna_k01 : $Bread$
@field fluxx = cdna_k02 : $Chocolate$
@field fluxx = cdna_k03 : $Cookies$
@field fluxx = cdna_k04 : $Coffee$
@field fluxx = cdna_k05 : $Death$
@field fluxx = cdna_k06 : $Doughnuts$
@field fluxx = cdna_k07 : $Love$
@field fluxx = cdna_k08 : $Milk$
@field fluxx = cdna_k09 : $Money$
@field fluxx = cdna_k10 : $Peace$
@field fluxx = cdna_k11 : $Taxes$
@field fluxx = cdna_k12 : $Television$
@field fluxx = cdna_k13 : $The Brain$
@field fluxx = cdna_k14 : $The Eye$
@field fluxx = cdna_k15 : $The Moon$
@field fluxx = cdna_k16 : $The Pyramid$
@field fluxx = cdna_k17 : $The Rocket$
@field fluxx = cdna_k18 : $The Sun$
@field fluxx = cdna_k19 : $The Toaster$
@field fluxx = cdna_k20 : $Time$
@field fluxx = cdna_k21 : $War$

// New Rules
@field fluxx = cdna_r01 : <Brain Bonus>
@field fluxx = cdna_r02 : <Draw 2>
@field fluxx = cdna_r03 : <Draw 3>
@field fluxx = cdna_r04 : <Draw 4>
@field fluxx = cdna_r05 : <Draw 5>
@field fluxx = cdna_r06 : <Final Card Random>
@field fluxx = cdna_r07 : <Government Cover-Up>
@field fluxx = cdna_r08 : <Hand Limit 0>
@field fluxx = cdna_r09 : <Hand Limit 1>
@field fluxx = cdna_r10 : <Hand Limit 2>
@field fluxx = cdna_r11 : <Hand Limit 3>
@field fluxx = cdna_r12 : <Keeper Limit 2>
@field fluxx = cdna_r13 : <Keeper Limit 3>
@field fluxx = cdna_r14 : <Keeper Limit 4>
@field fluxx = cdna_r15 : <Money Bonus>
@field fluxx = cdna_r16 : <Play 2>
@field fluxx = cdna_r17 : <Play 3>
@field fluxx = cdna_r18 : <Play 4>
@field fluxx = cdna_r19 : <Play All>
@field fluxx = cdna_r20 : <Secret Data>
@field fluxx = cdna_r21 : <Tax Bonus>
@field fluxx = cdna_r22 : <Time Bonus>
@field fluxx = cdtx_r01 : If a player has The Brain showing, and a Hand Limit is in effect, that player may hold 1 additional card in his or her hand. / Ignore this rule if the Brain is hid because of Secret Data or Government Cover-Up.
@field fluxx = cdtx_r02 : Draw 2 cards per turn. / The person who played this card should immediately draw extra cards (if needed) so that they have drawn 2 cards this turn.
@field fluxx = cdtx_r03 : Draw 3 cards per turn. / The person who played this card should immediately draw extra cards (if needed) so that they have drawn 3 cards this turn.
@field fluxx = cdtx_r04 : Draw 4 cards per turn. / The person who played this card should immediately draw extra cards (if needed) so that they have drawn 4 cards this turn.
@field fluxx = cdtx_r05 : Draw 5 cards per turn. / The person who played this card should immediately draw extra cards (if needed) so that they have drawn 5 cards this turn.
@field fluxx = cdtx_r06 : The final card you play must be chosen at random from your hand. / Ignore this rule unless Play 2, Play 3, or Play 4 is in force.
@field fluxx = cdtx_r07 : All Keepers must be hidden. / Turn your Keepers over. When you play a new Keeper, don't show it to anyone, just put it face down on the table. Only you may look at your Keepers.
@field fluxx = cdtx_r08 : If it isn't your turn, you shouldn't have any cards in your hand. If you do, discard them immediately. / During your turn, you may ignore the Hand Limit, as long as you discard all of your cards when you end your turn.
@field fluxx = cdtx_r09 : If it isn't your turn, you should only have 1 card in your hand. If you have extra cards, discard them immediately. / During your turn, you may ignore the Hand Limit, as long as you discard all but 1 of your cards when you end your turn.
@field fluxx = cdtx_r10 : If it isn't your turn, you should only have 2 cards in your hand. If you have extra cards, discard them immediately. / During your turn, you may ignore the Hand Limit, as long as you discard all but 2 of your cards when you end your turn.
@field fluxx = cdtx_r11 : If it isn't your turn, you should only have 3 cards in your hand. If you have extra cards, discard them immediately. / During your turn, you may ignore the Hand Limit, as long as you discard all but 3 of your cards when you end your turn.
@field fluxx = cdtx_r12 : If it isn't your turn, you can only have 2 Keepers in play. Discard any extras immediately. / You may play new Keepers during your turn as long as you discard all but 2 at the end of your turn.
@field fluxx = cdtx_r13 : If it isn't your turn, you can only have 3 Keepers in play. Discard any extras immediately. / You may play new Keepers during your turn as long as you discard all but 3 at the end of your turn.
@field fluxx = cdtx_r14 : If it isn't your turn, you can only have 4 Keepers in play. Discard any extras immediately. / You may play new Keepers during your turn as long as you discard all but 4 at the end of your turn.
@field fluxx = cdtx_r15 : If a player has Money showing, and a Keeper Limit is in effect, that player may have 1 additional Keeper in play. / Ignore this rule if Money is hidden because of Secret Data or Government Cover-Up.
@field fluxx = cdtx_r16 : Play 2 cards per turn. / If you have fewer than 2 cards in your hand, play all your cards.
@field fluxx = cdtx_r17 : Play 3 cards per turn. / If you have fewer than 3 cards in your hand, play all your cards.
@field fluxx = cdtx_r18 : Play 4 cards per turn. / If you have fewer than 4 cards in your hand, play all your cards.
@field fluxx = cdtx_r19 : Play all of the cards in your hand each turn.
@field fluxx = cdtx_r20 : Everyone may hide one Keeper. / When you play a new Keeper, you may place it face down without showing it to anyone as long as you then reveal your old secret Keeper (if any).
@field fluxx = cdtx_r21 : If a player has Taxes showing, that player may draw 1 extra card per turn. / Ignore this rule if Taxes is hidden because of Secret Data or Government Cover-Up.
@field fluxx = cdtx_r22 : If a player has Time showing, that player may play 1 extra card per turn. / Ignore this rule if Time is hidden because of Secret Data or Government Cover-Up.

join fluxx (dbref #11961)

@action join fluxx = Fluxx cards : nowhere
@field #11961 = varobj : 11960
// if the phase isn't 0, it's too late to join.
// if already 10 players, the game is full.
// also check if already in the game.
// otherwise, add player to next in list and increment nplayers.
@desc #11961 = If you'd like to play a game of Fluxx,
 type "join fluxx".
 You can only join a game during the pre-game phase.
 and there's a maximum of ten players in a game.
 When everyone's ready to begin, one player should type "start fluxx".
---
@desc #11961 = If you'd like to play a game of Fluxx, type "join fluxx". You can only join a game during the pre-game phase. and there's a maximum of ten players in a game. When everyone's ready to begin, one player should type "start fluxx".
===
@succ #11961 =
 @s("_tmp",0);
 @strloop(@substr("0123456789",0,@g("nplayers")),"z",
  @switch("%#",@g("whoref_%z"),@s("_tmp",1)));
 @switch(0,
 @eq(@g("phase"),0),
  "Sorry. You can only join the game during the pre-game phase.",
 @lt(@g("nplayers"),10),
  "Sorry. The game is full. 10 players maximum.",
 @eq(@g("_tmp"),0),
  "You are already in the game.",
 @print(
  @s(@print("whoref_",@g("nplayers")),"%#"),
  @s("nplayers",@add(1,@g("nplayers"))),
  @strloop(@substr("0123456789",0,@g("nplayers")),"z",
   @tell(@g("whoref_%z"),"[fluxx] %n has joined the game."))
 ));
---
@succ #11961 = @s("_tmp",0); @strloop(@substr("0123456789",0,@g("nplayers")),"z", @switch("%#",@g("whoref_%z"),@s("_tmp",1))); @switch(0, @eq(@g("phase"),0), "Sorry. You can only join the game during the pre-game phase.", @lt(@g("nplayers"),10), "Sorry. The game is full. 10 players maximum.", @eq(@g("_tmp"),0), "You are already in the game.", @print( @s(@print("whoref_",@g("nplayers")),"%#"), @s("nplayers",@add(1,@g("nplayers"))), @strloop(@substr("0123456789",0,@g("nplayers")),"z", @tell(@g("whoref_%z"),"[fluxx] %n has joined the game.")) ));
===

leave fluxx (dbref #11962)

@action leave fluxx = Fluxx cards : nowhere
@field #11962 = varobj : 11960
@desc #11962 = Type "leave fluxx" to leave the game. If a player leaves
 the game after the game has started, all of his or her cards in hand
 and Keepers in play are discarded.
@succ #11962 =
 @s("_tmp",0);
 @strloop(@substr("0123456789",0,@g("nplayers")),"z",
  @switch("%#",@g("whoref_%z"),@s("_tmp",1)));
 @switch(0,
 @eq(@g("phase"),0),
  "Sorry. You can only leave the game during the pre-game phase.",
 @eq(@g("_tmp"),1),
  "But you weren't in the game.",
 @print(
  @strloop(@substr("0123456789",0,@g("nplayers")),"z",@print(
   @tell(@g("whoref_%z"),"[fluxx] %n has left the game.")
  )),
  @s("nplayers",@sub(@g("nplayers"),1)),
 ));
---
===

stat fluxx (dbref #11995)

@action stat fluxx = Fluxx cards : nowhere
@field #11995 = varobj : 11960
@desc #11995 = Type "stat fluxx" to list who's playing fluxx.
@succ #11995 = @print("Fluxx players (",@g("nplayers"),"):");
 @strloop(@substr("0123456789",0,@g("nplayers")),"z",@print(
  " ",@shortname(@g("whoref_%z")) ));
---
@succ #11995 = @print("Fluxx players (",@g("nplayers"),"):"); @strloop(@substr("0123456789",0,@g("nplayers")),"z",@print(" ",@shortname(@g("whoref_%z")) ));
===

start fluxx (dbref #11963)

@action start fluxx = Fluxx cards : nowhere
// 1) put all cards in deck
// 2) shuffle deck
// 3) give three cards to each player
// 4) Announce the running order (the order in which they joined).
// 5) Announce who goes first.
// NOTE: the field "hand_x" has a value like "hand_0" or "hand_1";
// it is the name of the turnord's hand field, but not the field itself.
@field #11963 = varobj : 11960
@desc #11963 = One player must type "start fluxx" to begin the game,
 after everyone who wants to play has typed "join fluxx". Turn order
 is the same as the order that people joined. One player is randomly
 chosen to go first.
@succ #11963 =
 @s("the_deck",@g("the_fulldeck"));
 @s("the_discard",""); @fieldloop(11960,"tbl_",@s("%f",""));
 @call(11960,"fn_shuffle");
 @strloop(@substr("0123456789",0,@g("nplayers")),"z",@print(
  @s("whoord","%z"),
  @call(11960,"fn_dealhand")
 ));
 @s("turnord",@rand(@g("nplayers")));
 @s("whoref_turnord",@g(@print("whoref_",@g("turnord"))));
 @s("whonam_turnord",@shortname(@g("whoref_turnord")));
 @s("tat_count",0); @s("tat_again",0);
 @s("_msg",@print("[fluxx] The game begins! 
 Three cards are dealt to each player.
 Type \"xx hand\" to look at your hand at any time.
 Turns will be taken in the
 same order that players joined the game:",
  @strloop(@substr("0123456789",0,@g("nplayers")),"z",
   @print(" ",@shortname(@g("whoref_%z")))),
  ". ",@g("whonam_turnord")," will go first."));
 @strloop(@substr("0123456789",0,@g("nplayers")),"z",
  @tell(@g("whoref_%z"),@g("_msg")));
 @call(11960,"fn_beginturn");
---
TEST
@succ #11963 = @s("the_deck",@g("the_fulldeck")); @s("the_discard",""); @fieldloop(11960,"tbl_",@s("%f","")); @call(11960,"fn_shuffle"); @strloop(@substr("0123456789",0,@g("nplayers")),"z",@print( @s("whoord","%z"), @call(11960,"fn_dealhand"))); @s("turnord",@rand(@g("nplayers"))); @s("whoref_turnord",@g(@print("whoref_",@g("turnord"))));  @s("whonam_turnord",@shortname(@g("whoref_turnord"))); @s("tat_count",0); @s("tat_again",0); @s("_msg",@print("[fluxx] The game begins! Three cards are dealt to each player. Type \"xx hand\" to look at your hand at any time. Turns will be taken in the same order that players joined the game:", @strloop(@substr("0123456789",0,@g("nplayers")),"z", @print(" ",@shortname(@g("whoref_%z")))), ". ",@g("whonam_turnord")," will go first.")); @strloop(@substr("0123456789",0,@g("nplayers")),"z", @tell(@g("whoref_%z"),@g("_msg"))); @call(11960,"fn_beginturn");
===

xx * (dbref #11992)

@action xx * = Fluxx cards : nowhere
@set #11992 = puzzle
@field #11992 = varobj : 11960
@desc #11992 = Examines something within the Fluxx game. You may examine
 the "table", your "hand", the "rules", the "deck", the "discard" pile,
 a player (eg: xx Floyd), or an individual card (eg: xx bread).
@succe #11992 =
 @call(11960,"fn_calc_whoord");
 @switch("%0",
 {"table","board"},@call(11960,"fn_readtable"),
 "hand",@call(11960,"fn_readhand"),
 {"discard","discards","discard pile"},@call(11960,"fn_readdiscard"),
 "rules",@call(11960,"basicrules"),
 @print(@call(11960,"fn_calc_thecdab"),
 @call(11960,"fn_readcard")));
--- TEST @succe #11992 = @call(11960,"fn_calc_whoord"); @switch("%0", {"table","board"},@call(11960,"fn_readtable"), "hand",@call(11960,"fn_readhand"), {"discard","discards","discard pile"},@call(11960,"fn_readdiscard"), "rules",@call(11960,"basicrules"), @print(@call(11960,"fn_calc_thecdab"), @call(11960,"fn_readcard"))); ===

play * (dbref #12040)

@action play *;fluxx-play * = Fluxx cards : nowhere
@set #12040 = puzzle
@field #12040 = varobj : 11960
@desc #12040 = Plays a card in the game Fluxx. Cards can be referred
 to by their full names, or by most reasonable abbreviations.
 Don't type any of the !!,**,$$,<> that surround the card names.
 So, to play the !Draw 2 and use 'em! card, you'd type either of:
 %c   play draw 2 and use 'em
 %c   play d2aue
 %cNOTE: "tb" is ambiguous and disallowed since it could mean either
 <Time Bonus> or <Tax Bonus>; their abbreviations are "tib" and "tab"
 respectively.
@succ #12040 =
 @call(11960,"fn_calc_whoord");
 @call(11960,"fn_calc_thecdab");
 @switch(1,
  @gt(@g("whoord"),9),
   "Sorry. Only players can play cards.",
  @eq(@g("phase"),0),
   "[fluxx] How can you play a card before any cards have been dealt?",
  @eq("xxx",@g("the_cdab")),
   "[fluxx] I don't know that card.",
  @eq(@g("whoord"),@g("turnord")),@switch(@g("phase"),
   2,@call(11960,"fn_phase2_play"),
   5,@call(11960,"fn_phase5_play"),
   6,@call(11960,"fn_phase6_play"),
   "[fluxx] You can't play a card right now."
  ),
  "[fluxx] You can't play a card right now."
 );
---
TEST
@succ #12040 = @call(11960,"fn_calc_whoord"); @call(11960,"fn_calc_thecdab"); @switch(1, @gt(@g("whoord"),9), "Sorry. Only players can play cards.", @eq(@g("phase"),0), "[fluxx] How can you play a card before any cards have been dealt?", @eq("xxx",@g("the_cdab")), "[fluxx] I don't know that card.", @eq(@g("whoord"),@g("turnord")),@switch(@g("phase"), 2,@call(11960,"fn_phase2_play"), 5,@call(11960,"fn_phase5_play"), 6,@call(11960,"fn_phase6_play"), "[fluxx] You can't play a card right now."), "[fluxx] You can't play a card right now.");
===
  @eq(@g("phase"),2),@print(
   @call(11960,"fn_calc_is_cardinhand"),
   @switch(0,
    @g("is_cardinhand"),
     "But you don't have that card in your hand.",
    @call(11960,"fn_playcard")
   )
  ),

discard * (dbref #9371)

@action discard * = Fluxx cards : nowhere
@set #9371 = puzzle
@field #9371 = varobj : 11960
@desc #9371 = In the game of Fluxx, use this command to discard a card,
 either from your hand or the table. You may only discard a card when
 you are directed to do so within the game. Examples:
 %c   discard bread%c   discard peace no war
---
@desc #9371 = In the game of Fluxx, use this command to discard a card, either from your hand or the table. You may only discard a card when you are directed to do so within the game. Examples:%c   discard bread%c   discard peace no war
===
@succ #9371 =
 @call(11960,"fn_calc_whoord");
 @call(11960,"fn_calc_thecdab");
 @switch(1,
  @gt(@g("whoord"),9),
   "Sorry. Only players can discard cards.",
  @eq(@g("phase"),0),
   "[fluxx] How can you discard a card before any cards have been dealt?",
  @eq("xxx",@g("the_cdab")),
   "[fluxx] I don't know that card.",
  @and(@eq(@g("phase"),20),@eq(@g("hl_ord"),@g("whoord"))),
   @call(11960,"fn_phase20_discard"),
  @and(@eq(@g("phase"),21),@eq(@g("kl_ord"),@g("whoord"))),
   @call(11960,"fn_phase21_discard"),
  @eq(@g("whoord"),@g("turnord")),@switch(@g("phase"),
   3,@call(11960,"fn_phase3_discard"),
   4,@call(11960,"fn_phase4_discard"),
   "[fluxx] Sorry. You can't discard anything right now."
  ),
  "[fluxx] Sorry. You can't discard anything right now."
 );
---
TEST
@succ #9371 = @call(11960,"fn_calc_whoord"); @call(11960,"fn_calc_thecdab"); @switch(1, @gt(@g("whoord"),9), "Sorry. Only players can discard cards.", @eq(@g("phase"),0), "[fluxx] How can you discard a card before any cards have been dealt?", @eq("xxx",@g("the_cdab")), "[fluxx] I don't know that card.", @eq(@g("whoord"),@g("turnord")),@switch(@g("phase"), 3,@call(11960,"fn_phase3_discard"), 4,@call(11960,"fn_phase4_discard"),"[fluxx] Sorry. You can't discard anything right now."), "[fluxx] Sorry. You can't discard anything right now.");
===

select * (dbref #11912)

@action select *;choose *;pick * = Fluxx cards : nowhere
@set #11912 = puzzle
@field #11912 = varobj : 11960
@desc #11912 = In the game of Fluxx, use this command to select a card
 (or a player) when directed to do so. You may need to use this command
 after certain Action cards are played. Example:
 %c   [fluxx] Guest1 plays Pilfer the Trash. The top 3 cards of the discard
 pile are: Chocolate, Play 3, Money Bonus. Guest1, SELECT one of these cards
 for your hand.
 %c   select chocolate
---
@desc #11912 = In the game of Fluxx, use this command to select a card (or a player) when directed to do so. You may need to use this command after certain Action cards are played. Example:%c   [fluxx] Guest1 plays Pilfer the Trash. The top 3 cards of the discard pile are: Chocolate, Play 3, Money Bonus. Guest1, SELECT one of these cards for your hand.%c   select chocolate
===
@succ #11912 =
 @call(11960,"fn_calc_whoord");
 @switch(1,
  @gt(@g("whoord"),9),
   "Sorry. Only Fluxx players can \"select\".",
  @and(@eq(@g("phase"),13),@eq(@g("tax_ord"),@g("whoord"))),
   @call(11960,"fn_phase13_select"),
  @and(@eq(@g("phase"),18),@eq(@g("sd_ord"),@g("whoord"))),
   @call(11960,"fn_phase18_select"),
  @and(@eq(@g("phase"),22),@eq(@g("kup_ord"),@g("whoord"))),
   @call(11960,"fn_phase22_select"),
  @eq(@g("whoord"),@g("turnord")),@switch(@g("phase"),
   7,@call(11960,"fn_phase7_select"),
   8,@call(11960,"fn_phase8_select"),
   9,@call(11960,"fn_phase9_select"),
   10,@call(11960,"fn_phase10_select"),
   11,@call(11960,"fn_phase11_select"),
   12,@call(11960,"fn_phase12_select"),
   14,@call(11960,"fn_phase14_select"),
   15,@call(11960,"fn_phase15_select"),
   16,@call(11960,"fn_phase16_select"),
   17,@call(11960,"fn_phase17_select"),
   19,@call(11960,"fn_phase19_select"),
   "[fluxx] \"select\" isn't a valid option right now."
  ),
  "[fluxx] \"select\" isn't a valid option right now."
 );
---
TEST
@succ #11912 = @call(11960,"fn_calc_whoord"); @switch(1, @gt(@g("whoord"),9), "Sorry. Only Fluxx players can \"select\".", @and(@eq(@g("phase"),13),@eq(@g("tax_ord"),@g("whoord"))), @call(11960,"fn_phase13_select"), @and(@eq(@g("phase"),18),@eq(@g("sd_ord"),@g("whoord"))), @call(11960,"fn_phase18_select"), @and(@eq(@g("phase"),22),@eq(@g("kup_ord"),@g("whoord"))), @call(11960,"fn_phase22_select"), @eq(@g("whoord"),@g("turnord")),@switch(@g("phase"), 7,@call(11960,"fn_phase7_select"), 8,@call(11960,"fn_phase8_select"), 9,@call(11960,"fn_phase9_select"), 10,@call(11960,"fn_phase10_select"), 11,@call(11960,"fn_phase11_select"), 12,@call(11960,"fn_phase12_select"), 14,@call(11960,"fn_phase14_select"), 15,@call(11960,"fn_phase15_select"), 16,@call(11960,"fn_phase16_select"), 17,@call(11960,"fn_phase17_select"), 19,@call(11960,"fn_phase19_select"), "[fluxx] \"select\" isn't a valid option right now."), "[fluxx] \"select\" isn't a valid option right now.");
===

end fluxx (dbref #11999)

@action end fluxx = Fluxx cards : nowhere
@field #11999 = varobj : 11960
@desc #11999 = This command ends and resets the current game of Fluxx.
 All players leave the game. Caution: Anyone can use this command,
 not just a player in the game.
@succ #11999 =
 @strloop(@substr("0123456789",0,@g("nplayers")),"z",
  @tell(@g("whoref_%z"),
  "[fluxx] %n ends the game! All cards are returned to the deck.
  All players leave fluxx. Type \"join fluxx\" if you want to play another game."
 ));
 @s("phase",0);
 @fieldloop(11960,"hand",@s("%f",""));
 @fieldloop(11960,"keep_",@s("%f",""));
 @fieldloop(11960,"tbl_",@s("%f",""));
 @fieldloop(11960,"whoref_",@s("%f",""));
 @s("the_goal",""); @s("the_discard","");
 @s("the_deck",@g("the_fulldeck")); @s("nplayers",0);
---
TEST
@succ #11999 = @strloop(@substr("0123456789",0,@g("nplayers")),"z", @tell(@g("whoref_%z"),"[fluxx] %n ends the game! All cards are returned to the deck. All players leave fluxx. Type \"join fluxx\" if you want to play another game.")); @s("phase",0); @fieldloop(11960,"hand",@s("%f","")); @fieldloop(11960,"keep_",@s("%f","")); @fieldloop(11960,"tbl_",@s("%f","")); @fieldloop(11960,"whoref_",@s("%f","")); @s("the_goal",""); @s("the_discard",""); @s("the_deck",@g("the_fulldeck")); @s("nplayers",0);
===