Swish Images

Clear[SwishColor]
SwishColor[i_,j_]:=Switch[{i,j},
{1,1},Blue,
{4,1},Blue,
{4,3}, Blue,
{1,3},Blue,
{1,2},Green,
{4,2},Green,
{2,2},Purple,
{3,2},Purple,
_,          Orange]
SwishShape[k_]:= Switch[k,
   1,Disk[#,1/5]&,
   3, {Disk[#,1/3],{White,Disk[#,1/5]}}&,
   4, Disk[#,1/3]&,
_,   Disk[#,1/40]& ]  
SwishCardPic[A_]:= Graphics[
Table[
{SwishColor[i,j],SwishShape[A[[i,j]]][{j,i}]},
{i,1,4},{j,1,3}],
Frame->True,
PlotRange->{{0.5,3.5},{0.5,4.5}},
FrameTicks->None,
ImageSize->"Tiny"
]

A1={
{1,1,4},
{1,0,1},
{0,1,3},
{1,3,1}
};
Show[
SwishCardPic[A1],
Axes->True,
Frame->True]

After expanding the representation we can order the cards in a canonical order and go from there.

Swish Cards

SwishCards={{{3,0,1},{0,0,0},{0,0,0},{0,0,0}},{{3,0,1},{0,0,0},{0,0,0},{0,0,0}},{{3,0,0},{0,0,0},{0,0,0},{0,0,1}},{{3,0,0},{0,0,0},{0,0,0},{0,0,1}},{{3,0,0},{0,0,0},{0,0,0},{1,0,0}},{{3,0,0},{0,0,0},{0,0,0},{1,0,0}},{{3,0,0},{0,0,0},{0,0,0},{0,1,0}},{{3,0,0},{0,0,0},{0,0,0},{0,1,0}},{{3,0,0},{0,0,1},{0,0,0},{0,0,0}},{{3,0,0},{0,0,1},{0,0,0},{0,0,0}},{{3,0,0},{0,0,0},{1,0,0},{0,0,0}},{{3,0,0},{0,0,0},{1,0,0},{0,0,0}},{{3,0,0},{0,1,0},{0,0,0},{0,0,0}},{{3,0,0},{0,1,0},{0,0,0},{0,0,0}},{{0,1,0},{0,0,0},{0,0,0},{0,3,0}},{{0,1,0},{0,0,0},{0,0,0},{0,3,0}},{{0,0,1},{0,0,0},{0,0,0},{0,3,0}},{{0,0,1},{0,0,0},{0,0,0},{0,3,0}},{{0,0,0},{0,0,0},{0,0,1},{0,3,0}},{{0,0,0},{0,0,0},{0,0,1},{0,3,0}},{{0,0,0},{0,0,0},{0,1,0},{0,3,0}},{{0,0,0},{0,0,0},{0,1,0},{0,3,0}},{{0,0,0},{0,1,0},{0,0,0},{0,3,0}},{{0,0,0},{0,1,0},{0,0,0},{0,3,0}},{{0,0,0},{0,0,0},{0,3,0},{0,0,1}},{{0,0,0},{0,0,0},{0,3,0},{0,0,1}},{{0,0,0},{0,0,0},{0,3,1},{0,0,0}},{{0,0,0},{0,0,0},{0,3,1},{0,0,0}},{{0,0,0},{0,0,0},{0,3,0},{0,1,0}},{{0,0,0},{0,0,0},{0,3,0},{0,1,0}},{{0,0,0},{0,1,0},{0,3,0},{0,0,0}},{{0,0,0},{0,1,0},{0,3,0},{0,0,0}},{{0,1,0},{0,0,0},{0,3,0},{0,0,0}},{{0,1,0},{0,0,0},{0,3,0},{0,0,0}},{{0,0,0},{0,0,0},{0,0,3},{0,1,0}},{{0,0,0},{0,0,0},{0,0,3},{0,1,0}},{{0,0,0},{0,0,0},{0,1,3},{0,0,0}},{{0,0,0},{0,0,0},{0,1,3},{0,0,0}},{{0,0,0},{0,0,0},{1,0,3},{0,0,0}},{{0,0,0},{0,0,0},{1,0,3},{0,0,0}},{{0,0,0},{1,0,0},{0,0,3},{0,0,0}},{{0,0,0},{1,0,0},{0,0,3},{0,0,0}},{{0,0,0},{0,0,1},{0,0,3},{0,0,0}},{{0,0,0},{0,0,1},{0,0,3},{0,0,0}},{{0,0,0},{0,0,0},{0,0,3},{1,0,0}},{{0,0,0},{0,0,0},{0,0,3},{1,0,0}},{{0,0,1},{0,0,0},{0,0,3},{0,0,0}},{{0,0,1},{0,0,0},{0,0,3},{0,0,0}},{{3,1,0},{0,0,0},{0,0,0},{0,0,0}},{{3,0,0},{0,0,0},{0,0,1},{0,0,0}},{{3,0,0},{1,0,0},{0,0,0},{0,0,0}},{{3,0,0},{0,0,0},{0,1,0},{0,0,0}},{{0,0,0},{0,0,0},{0,0,0},{0,3,1}},{{0,0,0},{0,0,1},{0,0,0},{0,3,0}},{{0,0,1},{0,0,0},{0,3,0},{0,0,0}},{{0,0,0},{0,0,1},{0,3,0},{0,0,0}},{{0,0,0},{0,0,0},{0,0,3},{0,0,1}},{{1,0,0},{0,0,0},{0,0,3},{0,0,0}},{{0,0,0},{0,1,0},{0,0,3},{0,0,0}},{{0,1,0},{0,0,0},{0,0,3},{0,0,0}}};

SwishCardsNew=Map[CanonicalStack,SwishCards];
GraphicsGrid[
Partition[
Map[SwishCardPic,SwishCardsNew],12],
ImageSize->"Medium"
]

Swish Graph

({{Stack+Card, ⟹, NewStacks }, {ReArrangeStacks, ⟹, ListOfStacks}, {DeadStack, ⟹, Deleted}, {Starts for each possible Card, ⟹, Purging Of duplicte Stacks}})

With  0 being blank, 1 being a dot, 3 a circle, and 3+1=4 a circle/dot combo.

Testing for a Swish and Incomplete Swish

A valid stack has:  one dot, one circle, and a number of filled circles, With our encoding this is a single “1”, a single “4”, and a number of “4”s and “0”s and nothing else.  First we need a way to test if something is a swish or could be going to become a swish.

SwishTest[TestStack_]:= Module[
{FlatStack=Normal[Flatten[TestStack]]},
{ZeroCount,OneCount,ThreeCount,FourCount}=Map[Count[FlatStack,#]&, {0,1,3,4}];
OtherCount=12-(ZeroCount+OneCount+ThreeCount+FourCount);
Which[
OtherCount>0,                             {False,FourCount,"Done"},                (* NOT a potential Swish *)
OneCount==ThreeCount==0, {True,  FourCount,   "Done"},              (* A complete Swish of length FourCount *)
OneCount==ThreeCount==1, {True,  FourCount,   "NotDone"},      (* A partial Swish of current length FourCount *)
True,                                                     {False, FourCount,   "Done"}                   (* Messed up it should not get here *)
]
]

Testing.

{test1,test2,test3,test4}={({{1, 0, 0}, {0, 3, 0}, {0, 0, 0}, {0, 0, 0}}),({{0, 0, 0}, {3, 1, 0}, {0, 0, 0}, {0, 0, 0}}), ({{0, 0, 3}, {0, 0, 0}, {0, 0, 0}, {0, 0, 1}}),({{3, 0, 0}, {0, 1, 0}, {0, 0, 0}, {0, 0, 0}})};
SwishTest[test1+test4]
SwishTest[test1+test2]
SwishTest[test1+test3]

Symmetry Related Variants

Each Stack (and card) has 4 possible equaivalet symmetry-related representations.  I need to make sure that I am always using a canonical representations. I am simply going to use the first stack in the default order for the 4 possibilities as the canonical representative of the equivalence class.

SymmetryClass[Stack_]:= Module[
{RevStack},
(* RevStack is the Flip around the long Edge *)
RevStack=Map[Reverse,Stack];
(* Union Removes Duplicates and Sorts into Canonical Order *)
Union[{Stack, RevStack, Reverse[Stack], Reverse[RevStack]}]
]
CanonicalStack[Stack_]:= SymmetryClass[Stack][[1]]

Testing

{test1,test2,test3,test4}={({{1, 0, 0}, {0, 3, 0}, {0, 0, 0}, {0, 0, 0}}),({{0, 0, 0}, {3, 1, 0}, {0, 0, 0}, {0, 0, 0}}), ({{0, 0, 3}, {0, 0, 0}, {0, 0, 0}, {0, 0, 1}}),({{3, 0, 0}, {0, 1, 0}, {0, 0, 0}, {0, 0, 0}})};
test=test1+test4
SwishCardPic[test]
Map[SwishCardPic,SymmetryClass[test]]
SwishCardPic[CanonicalStack[test]]

Symmetry Related Variants

Adding a card to an existing stack and splitting as required.

We need to be able to generate all possible “stacks” from a stack and a new card.  Since there are duplicate cards in the Deck I need to keep track of the cards that have been used to build a given stack.  I will keep track of the cards that have been used to build the stack as a sorted list of cards (in the real version 1…60) that have been used.  This is easy because this is what I need for the graph.

SwishAddCard[{Stack_,CardsInStack_},{CardNumber_, CardsInDeck_}] := Module[
{SymCards,TestStacks,Card=CardsInDeck[[CardNumber]],NewStacks,NewCardsInStack},
SymCards=SymmetryClass[Card];
TestStacks=Table[
CanonicalStack[Stack+SymCards[[i]]],
{i,1,Length[SymCards]}];
NewStacks=Select[TestStacks, SwishTest[#][[1]]&];
NewCardsInStack=Sort[Append[CardsInStack,CardNumber]];
Table[
{NewStacks[[i]],NewCardsInStack},
{i, Length[NewStacks]}]
]

Testing

TestDeck={({{1, 0, 0}, {0, 3, 0}, {0, 0, 0}, {0, 0, 0}}),({{0, 0, 0}, {3, 1, 0}, {0, 0, 0}, {0, 0, 0}}), ({{0, 0, 3}, {0, 0, 0}, {0, 0, 0}, {0, 0, 1}}),({{3, 0, 0}, {0, 1, 0}, {0, 0, 0}, {0, 0, 0}})};

TwoCardPartialSwishes=DeleteCases[
Apply[Union,Flatten[
Table[
SwishAddCard[{TestDeck[[i]],{i}},{j,TestDeck}],
{i,1,4},
{j,i+1,4}],1]],{}];
Map[MatrixForm,TwoCardPartialSwishes[[All,1]]]
Map[SwishCardPic,TwoCardPartialSwishes[[All,1]]]

Making a display graph

I need to process the output from the builder and make an image.

{n,nz}={12,24};
M=SparseArray[{},{n,n}];
Do[ 
{i,j}=RandomInteger[{1,n},2];
M[[i,j]]=1,
{nz}]

GraphPlot[M,
VertexLabeling->True
]

GraphPlot[M,
VertexLabeling->True,
VertexRenderingFunction-> (Inset[ ,#1]&)
]
GraphPlot3D[M,
VertexLabeling->True,
VertexRenderingFunction-> (Inset[ ,#1]&)]

Break

Clear[RandomSwishCard]
RandomSwishCard[]:=Module[
{Card},
Card=ConstantArray[0,{4,3}];
{n1,n2}=RandomSample[Range[0,11],2];
{i,j}=QuotientRemainder[n1,3]+1;
Card[[i,j]]=1;
{i,j}=QuotientRemainder[n2,3]+1;
Card[[i,j]]=3;
Card
]

Card=RandomSwishCard[];
Deck=Union[Table[ RandomSwishCard[],{3}]]

A valid stack has:  one dot, one circle, and a number of filled circles, With our encoding this is a single “1”, a single “4”, and a number of “4”s and “0”s and nothing else.  First we need a way to test if something is a swish or could be going to become a swish.

Each Stack (and card) has 4 possible equaivalet symettry-related representations.  I need to make sure that I am always using a canonical representations. I am simply going to use the first stack in the default order for the 4 possibilities as the canonical representative of the equivalence class.

SymmetryClass[Stack_]:= Module[
{RevStack},
(* RevStack is the Flip around the long Edge *)
RevStack=Map[Reverse,Stack];
(* Union Removes Duplicates and Sorts into Canonical Order *)
Union[{Stack, RevStack, Reverse[Stack], Reverse[RevStack]}]
]
CanonicalStack[Stack_]:= SymmetryClass[Stack][[1]]

{test1,test2,test3,test4}={({{1, 0, 0}, {0, 3, 0}, {0, 0, 0}, {0, 0, 0}}),({{0, 0, 0}, {3, 1, 0}, {0, 0, 0}, {0, 0, 0}}), ({{0, 0, 3}, {0, 0, 0}, {0, 0, 0}, {0, 0, 1}}),({{0, 0, 0}, {0, 0, 1}, {3, 0, 0}, {0, 0, 0}})};
Map[MatrixForm,SymmetryClass[test1]]
MatrixForm[CanonicalStack[test1]]

SwishAddSingleCard[{Stack_,CardsInStack_},{CardNumber_, CardsInDeck_}] := Module[
{SymCards,TestStacks,Card=CardsInDeck[[CardNumber]],NewStacks,NewCardsInStack},
SymCards=SymmetryClass[Card];
TestStacks=Table[
CanonicalStack[Stack+SymCards[[i]]],
{i,1,Length[SymCards]}];
NewStacks=Select[TestStacks, SwishTest[#][[1]]&];
NewCardsInStack=Sort[Append[CardsInStack,CardNumber]];
Table[
{NewStacks[[i]],NewCardsInStack},
{i, Length[NewStacks]}]
]

Deck={test1,test2,test3};

Test=SwishAddSingleCard[{test1,{1}},{2,Deck}];
Table[MatrixForm[Test[[i,1]]],{i,Length[Test]}]
Test[[All,2]]

I need to keep track of which cards have been added (or more particularly which cards are left to be added) which is a little complicated because there can be mpore than one copy of a card in the deck. I am going to use the “number” of the card in the deck to keep track,

SwishAddCards[{Stack_,CardsInStack_},CardsInDeck_]:=Module[
{Flag="NotDone",CardsLeft,NewStack, NewCardsInStack},
CardsLeft=Drop[CardsInDeck,CardsInStack];

NewStacks=SwishAddSingleCard[NewStack,CardsLeft[[1]]];

While[
And[Flag=="NotDone", nCurrent<nMax],
NewCard
Table[
SwishAddSingleCard[Stack,ListOCards[[i]]],
While[ ListOCards≠{}, 


]

Testing=SwishBuild[test1,test2];
Map[ MatrixForm, Testing]

Binomial[60,2]

Swic

SwishBuild[Testing[[1]],test3]
SwishBuild[Testing[[2]],test3]

4^11