Example #1
0
        private void TestKongs(int playerIndex, Tile[] handTiles, IList <InTurnOperation> operations)
        {
            if (CurrentRoundStatus.KongClaimed == MahjongConstants.MaxKongs)
            {
                return;                 // no more kong can be claimed after 4 kongs claimed
            }
            var alreadyRichied = CurrentRoundStatus.RichiStatus(playerIndex);

            if (alreadyRichied)
            {
                // test kongs in richied player hand
                var richiKongs = MahjongLogic.GetRichiKongs(handTiles, justDraw);
                if (richiKongs.Any())
                {
                    foreach (var kong in richiKongs)
                    {
                        operations.Add(new InTurnOperation
                        {
                            Type = InTurnOperationType.Kong,
                            Meld = kong
                        });
                    }
                }
            }
            else
            {
                // 1. test self kongs, aka four same tiles in hand and lastdraw
                var selfKongs = MahjongLogic.GetSelfKongs(handTiles, justDraw);
                if (selfKongs.Any())
                {
                    foreach (var kong in selfKongs)
                    {
                        operations.Add(new InTurnOperation
                        {
                            Type = InTurnOperationType.Kong,
                            Meld = kong
                        });
                    }
                }

                // 2. test add kongs, aka whether a single tile in hand and lastdraw is identical to a pong in open melds
                var addKongs = MahjongLogic.GetAddKongs(
                    CurrentRoundStatus.HandTiles(playerIndex), CurrentRoundStatus.OpenMelds(playerIndex), justDraw);
                if (addKongs.Any())
                {
                    foreach (var kong in addKongs)
                    {
                        operations.Add(new InTurnOperation
                        {
                            Type = InTurnOperationType.Kong,
                            Meld = kong
                        });
                    }
                }
            }
        }