Exemplo n.º 1
0
        public override void OnCardPlaced(TriadGameData gameData, int boardPos)
        {
            TriadCardInstance checkCard = gameData.board[boardPos];

            if (checkCard.card.Type != ETriadCardType.None)
            {
                int scoreMod = gameData.typeMods[(int)checkCard.card.Type];
                if (scoreMod != 0)
                {
                    checkCard.scoreModifier = scoreMod;

                    if (gameData.bDebugRules)
                    {
                        Logger.WriteLine(">> " + RuleName + "! [" + boardPos + "] " + checkCard.card.Name + " is: " + ((scoreMod > 0) ? "+" : "") + scoreMod);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public override void OnCheckCaptureNeis(TriadGameData gameData, int boardPos, int[] neiPos, List <int> captureList)
        {
            TriadCardInstance checkCard = gameData.board[boardPos];
            int numSame = 0;

            for (int sideIdx = 0; sideIdx < 4; sideIdx++)
            {
                int testNeiPos = neiPos[sideIdx];
                if (testNeiPos >= 0 && gameData.board[testNeiPos] != null)
                {
                    TriadCardInstance neiCard = gameData.board[testNeiPos];

                    int numPos   = checkCard.GetNumber((ETriadGameSide)sideIdx);
                    int numOther = neiCard.GetOppositeNumber((ETriadGameSide)sideIdx);
                    if (numPos == numOther)
                    {
                        numSame++;
                    }
                }
            }

            if (numSame >= 2)
            {
                for (int sideIdx = 0; sideIdx < 4; sideIdx++)
                {
                    int testNeiPos = neiPos[sideIdx];
                    if (testNeiPos >= 0 && gameData.board[testNeiPos] != null)
                    {
                        TriadCardInstance neiCard = gameData.board[testNeiPos];
                        if (neiCard.owner != checkCard.owner)
                        {
                            neiCard.owner = checkCard.owner;
                            captureList.Add(testNeiPos);

                            if (gameData.bDebugRules)
                            {
                                Logger.WriteLine(">> " + RuleName + "! [" + testNeiPos + "] " + neiCard.card.Name + " => " + neiCard.owner);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        public override void OnPostCaptures(TriadGameData gameData, int boardPos)
        {
            TriadCardInstance checkCard = gameData.board[boardPos];

            if (checkCard.card.Type != ETriadCardType.None)
            {
                int scoreMod = checkCard.scoreModifier - 1;
                gameData.typeMods[(int)checkCard.card.Type] = scoreMod;

                for (int Idx = 0; Idx < gameData.board.Length; Idx++)
                {
                    TriadCardInstance otherCard = gameData.board[Idx];
                    if ((otherCard != null) && (checkCard.card.Type == otherCard.card.Type))
                    {
                        otherCard.scoreModifier = scoreMod;
                        if (gameData.bDebugRules)
                        {
                            Logger.WriteLine(">> " + RuleName + "! [" + Idx + "] " + otherCard.card.Name + " is: " + ((scoreMod > 0) ? "+" : "") + scoreMod);
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        private void UpdateAvailableRedCards(TriadDeckInstanceScreen redDeck,
                                             TriadCard[] screenCardsRed, TriadCard[] screenCardsBlue, TriadCard[] screenBoard,
                                             TriadCard[] prevCardsBlue, TriadCardInstance[] prevBoard, bool bContinuePrevState)
        {
            bool bDebugMode      = false;
            int  hiddenCardId    = TriadCardDB.Get().hiddenCard.Id;
            int  numVisibleCards = deckRed.cards.Length;

            redDeck.numPlaced = 0;
            if (!bContinuePrevState)
            {
                redDeck.numUnknownPlaced = 0;
            }

            int maxUnknownToUse     = redDeck.cards.Length - redDeck.deck.knownCards.Count;
            int firstUnknownPoolIdx = redDeck.cards.Length + redDeck.deck.knownCards.Count;

            if (redDeck.deck.unknownCardPool.Count > 0)
            {
                redDeck.unknownPoolMask = ((1 << redDeck.deck.unknownCardPool.Count) - 1) << firstUnknownPoolIdx;

                for (int Idx = 0; Idx < screenCardsRed.Length; Idx++)
                {
                    if ((screenCardsRed[Idx] != null) && (screenCardsRed[Idx].Id != hiddenCardId) && redDeck.deck.unknownCardPool.Contains(screenCardsRed[Idx]))
                    {
                        redDeck.unknownPoolMask |= (1 << Idx);
                    }
                }
            }

            int allDeckAvailableMask = ((1 << (redDeck.deck.knownCards.Count + redDeck.deck.unknownCardPool.Count)) - 1) << numVisibleCards;

            bool bCanCompareWithPrevData = (screenCardsRed.Length == redDeck.cards.Length) && (screenCardsBlue.Length == prevCardsBlue.Length) && (screenBoard.Length == prevBoard.Length);

            if (bCanCompareWithPrevData && !bContinuePrevState)
            {
                // special case: 1st turn

                int numCardsOnBoard = 0;
                for (int Idx = 0; Idx < screenBoard.Length; Idx++)
                {
                    if (screenBoard[Idx] != null)
                    {
                        numCardsOnBoard++;
                    }
                }

                if (numCardsOnBoard <= 1)
                {
                    bCanCompareWithPrevData = true;
                    prevBoard                 = new TriadCardInstance[screenBoard.Length];
                    prevCardsBlue             = new TriadCard[numVisibleCards];
                    deckRed.cards             = new TriadCard[numVisibleCards];
                    deckRed.availableCardMask = allDeckAvailableMask;
                    deckRed.numPlaced         = 0;
                    deckRed.numUnknownPlaced  = 0;
                }
                else
                {
                    bCanCompareWithPrevData = false;
                }
            }

            if (bDebugMode)
            {
                Logger.WriteLine("Red deck update, diff mode check... " +
                                 "bContinuePrevState:" + bContinuePrevState +
                                 ", cards(screen:" + screenCardsRed.Length + ", prev:" + deckRed.cards.Length + ")=" + ((screenCardsRed.Length == deckRed.cards.Length) ? "ok" : "nope") +
                                 ", other(screen:" + screenCardsBlue.Length + ", prev:" + prevCardsBlue.Length + ")=" + ((screenCardsBlue.Length == prevCardsBlue.Length) ? "ok" : "nope") +
                                 ", board(screen:" + screenBoard.Length + ", prev:" + prevBoard.Length + ")=" + ((screenBoard.Length == prevBoard.Length) ? "ok" : "nope"));
            }

            if (bCanCompareWithPrevData)
            {
                // create diffs, hopefully prev state comes from last turn and is just 2 cards away
                List <int>       usedCardsIndices = new List <int>();
                List <TriadCard> usedCardsOther   = new List <TriadCard>();

                int numKnownOnHand   = 0;
                int numUnknownOnHand = 0;
                int numHidden        = 0;
                int numOnHand        = 0;
                for (int Idx = 0; Idx < deckRed.cards.Length; Idx++)
                {
                    if (screenCardsRed[Idx] == null)
                    {
                        TriadCard prevCard = deckRed.cards[Idx];
                        if ((prevCard != null) && (prevCard.Id != hiddenCardId))
                        {
                            if (bDebugMode)
                            {
                                Logger.WriteLine("  card[" + Idx + "]:" + prevCard.Name + " => mark as used, disappeared from prev state");
                            }
                            usedCardsIndices.Add(Idx);
                        }

                        deckRed.availableCardMask &= ~(1 << Idx);
                        deckRed.numPlaced++;
                    }
                    else
                    {
                        if (screenCardsRed[Idx].Id != hiddenCardId)
                        {
                            bool bIsUnknown = (deckRed.unknownPoolMask & (1 << Idx)) != 0;
                            numUnknownOnHand += bIsUnknown ? 1 : 0;
                            numKnownOnHand   += bIsUnknown ? 0 : 1;
                            numOnHand++;
                            deckRed.availableCardMask |= (1 << Idx);

                            int knownCardIdx   = deckRed.deck.knownCards.IndexOf(screenCardsRed[Idx]);
                            int unknownCardIdx = deckRed.deck.unknownCardPool.IndexOf(screenCardsRed[Idx]);
                            if (knownCardIdx >= 0)
                            {
                                deckRed.availableCardMask &= ~(1 << (knownCardIdx + deckRed.cards.Length));
                            }
                            else if (unknownCardIdx >= 0)
                            {
                                deckRed.availableCardMask &= ~(1 << (unknownCardIdx + deckRed.cards.Length + deckRed.deck.knownCards.Count));
                            }

                            if (bDebugMode)
                            {
                                TriadCard cardOb = screenCardsRed[Idx];
                                Logger.WriteLine(" card[" + Idx + "]:" + (cardOb != null ? cardOb.Name : "??") +
                                                 " => numUnknown:" + numUnknownOnHand + ", numKnown:" + numKnownOnHand + ", numHidden:" + numHidden);
                            }
                        }
                        else
                        {
                            numHidden++;
                        }
                    }
                }

                for (int Idx = 0; Idx < prevCardsBlue.Length; Idx++)
                {
                    if ((prevCardsBlue[Idx] != null) && (screenCardsBlue[Idx] == null))
                    {
                        usedCardsOther.Add(prevCardsBlue[Idx]);
                        if (bDebugMode)
                        {
                            Logger.WriteLine("  blue[" + Idx + "]:" + prevCardsBlue[Idx].Name + " => mark as used");
                        }
                    }
                }

                for (int Idx = 0; Idx < prevBoard.Length; Idx++)
                {
                    TriadCard testCard = screenBoard[Idx];
                    if ((prevBoard[Idx] == null || prevBoard[Idx].card == null) && (testCard != null))
                    {
                        int testCardIdx = deckRed.GetCardIndex(testCard);
                        if (!usedCardsOther.Contains(testCard) && (testCardIdx >= 0))
                        {
                            usedCardsIndices.Add(testCardIdx);
                            if (bDebugMode)
                            {
                                Logger.WriteLine("  card[" + testCardIdx + "]:" + testCard.Name + " => mark as used, appeared on board[" + Idx + "], not used by blue");
                            }
                        }
                    }
                }

                Array.Copy(screenCardsRed, deckRed.cards, 5);

                for (int Idx = 0; Idx < usedCardsIndices.Count; Idx++)
                {
                    int cardMask = 1 << usedCardsIndices[Idx];
                    deckRed.availableCardMask &= ~cardMask;

                    bool bIsUnknownPool = (deckRed.unknownPoolMask & cardMask) != 0;
                    if (bIsUnknownPool)
                    {
                        deckRed.numUnknownPlaced++;
                    }

                    if (bDebugMode)
                    {
                        TriadCard cardOb = deckRed.GetCard(usedCardsIndices[Idx]);
                        Logger.WriteLine(" card[" + usedCardsIndices[Idx] + "]:" + (cardOb != null ? cardOb.Name : "??") + " => used");
                    }
                }

                if ((numHidden == 0) && ((numOnHand + deckRed.numPlaced) == numVisibleCards))
                {
                    deckRed.availableCardMask &= (1 << numVisibleCards) - 1;
                    if (bDebugMode)
                    {
                        Logger.WriteLine("   all cards are on hand and visible");
                    }
                }
                else if ((deckRed.numUnknownPlaced + numUnknownOnHand) >= maxUnknownToUse ||
                         ((numKnownOnHand >= (numVisibleCards - maxUnknownToUse)) && (numHidden == 0)))
                {
                    deckRed.availableCardMask &= (1 << (numVisibleCards + deckRed.deck.knownCards.Count)) - 1;

                    if (bDebugMode)
                    {
                        Logger.WriteLine("   removing all unknown cards, numUnknownPlaced:" + deckRed.numUnknownPlaced +
                                         ", numUnknownOnHand:" + numUnknownOnHand + ", numKnownOnHand:" + numKnownOnHand +
                                         ", numHidden:" + numHidden + ", maxUnknownToUse:" + maxUnknownToUse);
                    }
                }
            }
            else
            {
                // TriadDeckInstanceScreen is mostly stateless (created from scratch on screen capture)
                // this makes guessing which cards were placed hard, especially when there's no good
                // history data to compare with.
                // Ignore board data here, cards could be placed by blue and are still available for red deck

                deckRed.UpdateAvailableCards(screenCardsRed);
                deckRed.availableCardMask = allDeckAvailableMask;
            }

            if (bDebugMode)
            {
                redDeck.LogAvailableCards("Red deck");
            }
        }
Exemplo n.º 5
0
        private void CheckCaptures(TriadGameData gameData, int boardPos, List <int> comboList, int comboCounter)
        {
            // combo:
            // - modifiers are active only in intial placement
            // - only card captured via modifiers can initiate combo (same, plus)
            // - type modifiers (ascention, descention) values are baked in card and influence combo
            // - can't proc another plus/same as a result of combo

            int[] neis      = cachedNeis[boardPos];
            bool  allowMods = comboCounter == 0;

            if (allowMods && (modFeatures & TriadGameModifier.EFeature.CaptureNei) != 0)
            {
                foreach (TriadGameModifier mod in modifiers)
                {
                    mod.OnCheckCaptureNeis(gameData, boardPos, neis, comboList);
                }
            }

            TriadCardInstance checkCard = gameData.board[boardPos];

            for (int sideIdx = 0; sideIdx < 4; sideIdx++)
            {
                int neiPos = neis[sideIdx];
                if (neiPos >= 0 && gameData.board[neiPos] != null)
                {
                    TriadCardInstance neiCard = gameData.board[neiPos];
                    if (checkCard.owner != neiCard.owner)
                    {
                        int numPos   = checkCard.GetNumber((ETriadGameSide)sideIdx);
                        int numOther = neiCard.GetOppositeNumber((ETriadGameSide)sideIdx);

                        if (allowMods && (modFeatures & TriadGameModifier.EFeature.CaptureWeights) != 0)
                        {
                            foreach (TriadGameModifier mod in modifiers)
                            {
                                mod.OnCheckCaptureCardWeights(gameData, boardPos, neiPos, ref numPos, ref numOther);
                            }
                        }

                        bool bIsCaptured = (numPos > numOther);
                        if (allowMods && (modFeatures & TriadGameModifier.EFeature.CaptureMath) != 0)
                        {
                            foreach (TriadGameModifier mod in modifiers)
                            {
                                mod.OnCheckCaptureCardMath(gameData, boardPos, neiPos, numPos, numOther, ref bIsCaptured);
                            }
                        }

                        if (bIsCaptured)
                        {
                            neiCard.owner = checkCard.owner;
                            if (comboCounter > 0)
                            {
                                comboList.Add(neiPos);
                            }

                            if (gameData.bDebugRules)
                            {
                                Logger.WriteLine(">> " + (comboCounter > 0 ? "combo!" : "") + " [" + neiPos + "] " + neiCard.card.Name.GetCodeName() + " => " + neiCard.owner);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 6
0
        private void CheckCaptures(TriadGameData gameData, int boardPos, List <int> comboList, int comboCounter)
        {
            int[] neis = GetNeighbors(gameData, boardPos);
            bool  bAllowBasicCaptureCombo = (comboCounter > 0);

            if ((comboCounter == 0) && ((modFeatures & TriadGameModifier.EFeature.CaptureNei) != 0))
            {
                foreach (TriadGameModifier mod in modifiers)
                {
                    mod.OnCheckCaptureNeis(gameData, boardPos, neis, comboList);
                }

                bAllowBasicCaptureCombo = bAllowBasicCaptureCombo || (comboList.Count > 0);
            }

            TriadCardInstance checkCard = gameData.board[boardPos];

            for (int sideIdx = 0; sideIdx < 4; sideIdx++)
            {
                int neiPos = neis[sideIdx];
                if (neiPos >= 0 && gameData.board[neiPos] != null)
                {
                    TriadCardInstance neiCard = gameData.board[neiPos];
                    if (checkCard.owner != neiCard.owner)
                    {
                        int numPos   = checkCard.GetNumber((ETriadGameSide)sideIdx);
                        int numOther = neiCard.GetOppositeNumber((ETriadGameSide)sideIdx);
                        if ((modFeatures & TriadGameModifier.EFeature.CaptureWeights) != 0)
                        {
                            foreach (TriadGameModifier mod in modifiers)
                            {
                                mod.OnCheckCaptureCardWeights(gameData, boardPos, neiPos, ref numPos, ref numOther);
                            }
                        }

                        bool bIsCaptured = (numPos > numOther);
                        if ((modFeatures & TriadGameModifier.EFeature.CaptureMath) != 0)
                        {
                            foreach (TriadGameModifier mod in modifiers)
                            {
                                mod.OnCheckCaptureCardMath(gameData, boardPos, neiPos, numPos, numOther, ref bIsCaptured);
                            }
                        }

                        if (bIsCaptured)
                        {
                            neiCard.owner = checkCard.owner;
                            if (bAllowBasicCaptureCombo)
                            {
                                comboList.Add(neiPos);
                            }

                            if (gameData.bDebugRules)
                            {
                                Logger.WriteLine(">> " + (comboCounter > 0 ? "combo!" : "") + " [" + neiPos + "] " + neiCard.card.Name + " => " + neiCard.owner);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 7
0
 public TriadCardInstance(TriadCardInstance copyFrom)
 {
     card          = copyFrom.card;
     owner         = copyFrom.owner;
     scoreModifier = copyFrom.scoreModifier;
 }