//Join this card to a stack with a card of higher rank
    public void Join(CardSolitaire other, bool lerp = false)
    {
        //link greater card to us
        other.lesserCard = this;
        //link ourselves to the greater card
        greaterCard = other;
        //update column index
        row = other.row + 1;
        //set this card to be a child of the previous card
        transform.parent = greaterCard.transform;
        //align this card to the one above it
        Vector3 pos = new Vector3(0, -1, 0.125f);

        if (lerp)
        {
            Move(pos + transform.parent.position, 0.5f);
        }
        else
        {
            transform.localPosition = pos;
        }

        if (greaterCard == null)
        {
            SetSortingLayerName("Row0");
        }
        else
        {
            SetSortingLayerName((greaterCard.GetSortingOrderLayerName().StartsWith("Row") ? "Row" + row : "PickedUp"));

            if (GetSortingOrderLayerName().Equals("PickedUp") && greaterCard != null)
            {
                SetSortOrder(greaterCard.GetTopSortOrder() + 3);                   //set this card to be the layer above the card it's on top of
            }
        }

        CheckForCompleteStack();          //check if the newly formed stack is complete
    }
    //LayoutGame() positions the initial tableau of cards, a.k.a. the "mine"
    void LayoutGame()
    {
        //Create an empty GameObject to serve as an anchor for the tableau
        if (layoutAnchor == null)
        {
            GameObject tGO = new GameObject("_LayoutAnchor");
            //^ Create an empty GameObject named _LayoutAnchor in the Hierarchy
            layoutAnchor = tGO.transform;                   //grab its Tranform
            layoutAnchor.transform.position = layoutCenter; //position it
        }

        CardSolitaire cp;

        //initialize first row of cards array
        slotPositions   = new Transform[10];
        firstRowOfCards = new CardSolitaire[slotPositions.Length];
        int slotCards = 0;

        //follow the layout
        foreach (SlotDef tSD in layout.slotDefs)
        {
            //^Iterate through all the SlotDefs in the layout.slotDefs as tSD
            cp = Draw();           //pull a card from the top (beginning) of the drawPile
            if (tSD.type == "slot")
            {
                firstRowOfCards[slotCards] = cp;
                slotPositions[slotCards]   = cp.transform;
                cp.faceUp = false;
                slotCards++;
            }
            cp.faceUp           = tSD.faceUp;   //set its faceUp to the value in slotDef
            cp.transform.parent = layoutAnchor; //make its parent layoutAnchor
            //this replaces the previous parent: deck.deckAnchor, which appears as _Deck in the Hierarchy when the scene is playing.
            cp.transform.localPosition = new Vector3(layout.multiplier.x * tSD.x, layout.multiplier.y * tSD.y, -tSD.layerID);
            //^Set the localPosition of the card based on slotDef
            cp.layoutID = tSD.id;
            cp.slotDef  = tSD;
            cp.state    = CardState.tableau;
            //CardSolitaires in the tableau have the state CardState.tableau

            cp.SetSortingLayerName(tSD.layerName); //set the sorting layers

            tableau.Add(cp);                       //add this CardSolitaire to the List<> tableau
        }


        /*
         * //Set which cards are hiding others
         * foreach (CardSolitaire tCP in tableau) {
         *      foreach(int hid in tCP.slotDef.hiddenBy){
         *              cp=FindCardByLayoutID(hid);
         *              tCP.hiddenBy.Add(cp);
         *      }
         * }
         */

        //add other cards to stack
        for (int i = 0; i < 3 * firstRowOfCards.Length + 4; i++)
        {
            //get bottom of current card
            CardSolitaire bottomCard = firstRowOfCards[i % firstRowOfCards.Length].BottomOfStack();
            //flip this card over
            bottomCard.faceUp = false;
            //add this card to that stack
            CardSolitaire tempCard = Draw();
            //tempCard.transform.Find("back").GetComponent<SpriteRenderer>().sortingLayerName = bottomCard.GetSortingOrderLayerName();
            tempCard.SetSortingLayerName(bottomCard.GetSortingOrderLayerName());
            //set its row
            tempCard.Join(bottomCard);
        }


        //set up the Draw pile
        UpdateDrawPile();
    }