Exemple #1
0
        //***********************************************************************
        //**************************** Basic Methods ****************************
        //***********************************************************************

        //Adds a tile to the collection
        //Note: if the tile is locked with a different access key, will not add
        new public void Add(Tile tile, int accessKey = 0)
        {
            if ((accessKey != _accessKey) && _accessKey != 0)
            {
                return;
            }
            if (Contains(tile, _accessKey))
            {
                return;
            }
            TileID id = tile.Query(_accessKey);

            if (id == TileID.Hidden)
            {
                return;
            }
            //Insert tile into sorted position
            int i = 0;

            while (i < tileIDs.Count && sorting.GreaterThan(id, tileIDs[i]))
            {
                i++;
            }
            tiles.Insert(i, tile);
            tileIDs.Insert(i, id);
        }
Exemple #2
0
        //Updates the meld list for the drawn tile
        private void CheckDraw()
        {
            Tile   draw   = hand.Draw;
            TileID drawID = draw.Query(accessKey);

            //All tiles are loose until proven otherwise, so put it in the loose tile list
            LooseTiles.Add(draw, accessKey);

            /* The following may not be necessary if the incompleted versions of the completed
             * meld stays in the list anyway, as we're just going to  be checking around the
             * first instance of the draw anyway.
             * TODO: if it seems to be working, remove this dead code
             * //First, check all the waiting melds and update any who were waiting on this draw
             * List<PotentialMeld> waitingMelds = GetWaitingMelds(drawID);
             * int i = 0;
             * for (i = 0; i < waitingMelds.Count; i++)
             * {
             *  waitingMelds[i].Add(drawID);
             *  waitingMelds[i].Waits.Clear();
             *  waitingMelds[i].Completed = true;
             *  //If a koutsu was just completed, then let's also register the potential kantsu
             *  if (waitingMelds[i].Type == Meld.MeldType.Koutsu)
             *  {
             *      PotentialMeld meld = new PotentialMeld(waitingMelds[i].IDs);
             *      meld.Waits.Add(new Wait(WaitType.Kantsu, drawID));
             *      AddMeld(meld);
             *  }
             * }
             */
            //Next, check the closed tiles around the first identical tile as the draw
            int index = hand.Tiles.Closed.IndexOf(drawID, accessKey);

            CheckAround(index);
        }
Exemple #3
0
        //***********************************************************************
        //***************************** New Methods *****************************
        //***********************************************************************

        //Inserts the tile at the specified index
        public void Insert(int index, Tile tile, int accessKey = 0)
        {
            if ((accessKey != _accessKey) && _accessKey != 0)
            {
                return;
            }
            if (tiles.Contains(tile))
            {
                return;
            }
            TileID id = tile.Query(_accessKey);

            if (id == TileID.Hidden)
            {
                return;
            }
            if (index >= Count)
            {
                Add(tile, _accessKey);
            }
            else
            {
                if (index <= 0)
                {
                    index = 0;
                }
                tiles.Insert(index, tile);
                tileIDs.Insert(index, id);
            }
        }
        //Offers a discard to be called as naki
        public override void Offer(Tile tile)
        {
            TileID id = tile.Query();
            List <PotentialMeld> melds = handAnalyzer.GetWaitingMelds(id);

            /*
             * string message = "Hand Analyzer " + PlayerNumber + " returned these melds matching the offer of " +
             *  id.ToString() + ":\r\n";
             * for (int i = 0; i < melds.Count; i++)
             *  message += melds[i].ToString() + "\r\n";
             * Debug.Log(message);
             */

            //Formulate a list of potential naki to send to the Naki UI Manager
            List <Naki> naki = new List <Naki>();
            bool        add;

            for (int i = 0; i < melds.Count; i++)
            {
                add = true;
                if (Naki.GetNakiType(melds[i].Waits[0].type) == NakiType.Chii)
                {
                    //If I am not kamicha (player to right), I cannot request chii
                    if ((PlayerNumber - tile.StolenFrom + 4) % 4 != 1)
                    {
                        add = false;
                    }
                }
                if (add)
                {
                    naki.Add(new Naki()
                    {
                        meld      = melds[i],
                        requestor = this,
                        type      = Naki.GetNakiType(melds[i].Waits[0].type)
                    });
                }
            }
            //If I cannot request any naki for this tile, respond that I don't want the discard
            if (naki.Count == 0)
            {
                controller.RespondToOffer(new Naki()
                {
                    type      = NakiType.Nashi,
                    requestor = this,
                    meld      = null
                });
            }
            //Otherwise pass the list of possible naki to the Naki UI Manager for user input
            else
            {
                sendingToUI = naki;
                SetState("Awaiting User Naki Choice");
            }
        }
Exemple #5
0
        //Flips a new dora.
        public TileID NewDora()
        {
            Tile indicator = Tiles[Tiles.Count - numberOfRegularDoras * 2 - 2];

            indicator.ReleaseOwnership(_accessKey);
            indicator.SetVisibility(TileVisibility.FaceUp);
            doras.Add(indicator.Query().GetDoraFromIndicator());
            numberOfRegularDoras++;
            EventManager.FlagEvent("New Dora");
            return(doras[doras.Count - 1]);
        }
Exemple #6
0
        //Updates the meld list after a discard
        private void CheckDiscard()
        {
            Tile   discard   = hand.Discard;
            TileID discardID = discard.Query(accessKey);

            //First, remove it from loose tiles if it's in there
            LooseTiles.Remove(discard, accessKey);
            //Find all the melds that used it and remove them.
            RemoveUsedInMelds(discardID);
            //Find the index among the closed tiles where the first identical tile to the discard would go
            int i = FindWouldBeLocationInClosed(discardID);

            //Check around this spot to add back any potential melds that are still valid
            CheckAround(i);
        }
Exemple #7
0
        //Removes the tile from the collection
        public void Remove(Tile tile, int accessKey = 0)
        {
            if ((accessKey != _accessKey) && _accessKey != 0)
            {
                return;
            }
            if (!(Contains(tile, _accessKey)))
            {
                return;
            }
            TileID id = tile.Query(_accessKey);

            tiles.Remove(tile);
            tileIDs.Remove(id);
        }
Exemple #8
0
        //***********************************************************************
        //**************************** Basic Methods ****************************
        //***********************************************************************

        //Adds the tile to the collection
        //Note: if the tile is locked with a different access key, will not add
        public void Add(Tile tile, int accessKey = 0)
        {
            if ((accessKey != _accessKey) && _accessKey != 0)
            {
                return;
            }

            if (Contains(tile, _accessKey))
            {
                return;
            }
            TileID id = tile.Query(_accessKey);

            if (id == TileID.Hidden)
            {
                return;
            }
            tiles.Add(tile);
            tileIDs.Add(id);
        }
Exemple #9
0
        //Returns true if the tile qualifies as loose. Does not add it to the loose tiles collection.
        private bool IsLoose(Tile tile)
        {
            int index = hand.Tiles.Closed.IndexOf(tile, accessKey);

            if (index == -1)
            {
                return(false);
            }
            if (index > 0 && TileID.InSameSuji(hand.Tiles.Closed[index - 1].Query(accessKey), tile.Query(accessKey)))
            {
                return(false);
            }
            if (index + 1 < hand.Tiles.Closed.Count && TileID.InSameSuji(hand.Tiles.Closed[index + 1].Query(accessKey), tile.Query(accessKey)))
            {
                return(false);
            }
            return(true);
        }