Esempio n. 1
0
 public EffectHolder(CardGameState GS, bool Shared, int OwnerIndex)
 {
     TheCardGameState = GS;
     this.Shared      = Shared;
     this.OwnerIndex  = OwnerIndex;
     mCardZoneType    = new CardZoneType(Shared ? ZoneType.SharedEffect : ZoneType.Effect, Range.NA, OwnerIndex);
 }
Esempio n. 2
0
        private List <Actions.ActionOrder> GetAvailableActions(TurnInfo turnInfo, CardGameState gameState)
        {
            List <Actions.ActionOrder> availableActions = new List <Actions.ActionOrder>();

            foreach (Entity E in mHand.Cards)
            {
                availableActions.AddRange(E.GetAIActions(gameState, turnInfo));
            }
            foreach (Effects.EffectNode EN in mEffects.Nodes)
            {
                availableActions.AddRange(EN.GetEntity().GetAIActions(gameState, turnInfo));
            }
            foreach (Effects.EffectNode EN in gameState.SharedEffects.Nodes)
            {
                availableActions.AddRange(EN.GetEntity().GetAIActions(gameState, turnInfo));
            }
            foreach (CardZone CZ in mBoard.RangeZones)
            {
                foreach (Entity E in CZ.List.Cards)
                {
                    availableActions.AddRange(E.GetAIActions(gameState, turnInfo));
                }
            }
            return(availableActions);
        }
 public ChangeAttackDefenseEffectProcess(CardBase monsterCard, CardGameState cardGameState, Player ownerPlayer) : base(ownerPlayer, "转换攻防")
 {
     effectProcessType  = EffectProcessType.RemoveAfterFinish;
     this.monsterCard   = monsterCard;
     launchEffectCard   = monsterCard;
     this.cardGameState = cardGameState;
 }
Esempio n. 4
0
        public static void CreateActionsAndGameStateSet(
            CardGameState stateToCopy, List <ActionOrder> actionsToCopy,
            out ActionsAndGameStateSet setToReturn)
        {
            MemoryStream    stream    = new MemoryStream();
            BinaryFormatter formatter = new BinaryFormatter();

            // Use a set with only one card game state so that everything gets serialised together.
            ActionsAndGameStateSet set = new ActionsAndGameStateSet();

            set.mAvailableActions = new List <ActionOrder>(actionsToCopy);
            set.mCardGameStates   = new List <CardGameState>();
            set.mCardGameStates.Add(stateToCopy);

            formatter.Serialize(stream, set);

            ActionsAndGameStateSet returnSet = new ActionsAndGameStateSet();

            returnSet.mAvailableActions = new List <ActionOrder>();
            returnSet.mCardGameStates   = new List <CardGameState>();

            for (int i = 0; i < actionsToCopy.Count; i++)
            {
                stream.Seek(0, SeekOrigin.Begin);
                ActionsAndGameStateSet setCopy = (ActionsAndGameStateSet)formatter.Deserialize(stream);
                returnSet.mAvailableActions.Add(setCopy.mAvailableActions[i]);
                returnSet.mCardGameStates.Add(setCopy.mCardGameStates[0]);
            }
            setToReturn = returnSet;
        }
Esempio n. 5
0
        private static float EvaluateGameState(int playerIndex, CardGameState gameState, bool passing = false)
        {
            // TODO Make this in any way good

            // TODO Make this handle more cases of players being passed.
            // ie a player cant do anything when passed so it should be possible
            // to more properly calculate if they are worth beating.

            Player player   = gameState.Players[playerIndex];
            Player opponent = gameState.Players[(playerIndex + 1) % 2];

            if (passing && opponent.GetVP() > player.GetVP())
            {
                // We know for sure* we are losing this round.
                // *Unless they manage to cause themselves to lose VP :P
                return(0.0f);
            }

            float playerScoreTotal   = ScorePlayer(player);
            float opponentScoreTotal = ScorePlayer(opponent);

            float scoreDifference  = opponentScoreTotal - playerScoreTotal;
            float probabiltyFactor = GetProbFromScoreDifference(scoreDifference);

            if (scoreDifference > 0)
            {
                return(probabiltyFactor);
            }
            else
            {
                return(1 - probabiltyFactor);
            }
        }
Esempio n. 6
0
 /// <summary>
 /// 判断当前是否在场上
 /// </summary>
 /// <returns></returns>
 public static bool IsInArea(CardGameState cardGameState)
 {
     return(cardGameState == CardGameState.FrontAttack ||
            cardGameState == CardGameState.FrontDefense ||
            cardGameState == CardGameState.Front ||
            cardGameState == CardGameState.Back);
 }
Esempio n. 7
0
        public override List <ActionOrder> GetAIActions(CardGameState gameState, TurnInfo TI)
        {
            List <ActionOrder> results = new List <ActionOrder>();

            if (!IsPlaced)
            {
                foreach (CardZone CZ in Owner.mBoard.RangeZones)
                {
                    Actions.Action placeCardAction = new PlaceCard_Action(this, CZ.Type);
                    if (placeCardAction.CheckValidity(null, null, TI))
                    {
                        results.Add(new ActionOrder(placeCardAction, null, null));
                    }
                }
            }
            else
            {
                if (!TI.IsDeployment())
                {
                    foreach (ActionInfo AI in GetActions())
                    {
                        foreach (ActionOrder AO in AI.GetPossibleActionOrders(gameState, this))
                        {
                            if (AO.Action.CheckValidity(AO.Performer, AO.Selection, TI))
                            {
                                results.Add(AO);
                            }
                        }
                    }
                }
            }
            return(results);
        }
Esempio n. 8
0
 public void NewTurn(CardGameState GS)
 {
     if (HasEffect)
     {
         TheEffect.NewTurn(GS);
     }
 }
Esempio n. 9
0
        public List <ActionOrder> GetPossibleActionOrders(CardGameState gameState, Entities.Entity performer)
        {
            List <ActionOrder> possibleActions = new List <ActionOrder>();

            if (Min == 0 || SelectType == PlayerType.NA)
            {
                possibleActions.Add(new ActionOrder(mAction, performer, null));
            }
            if (Max > 0)
            {
                List <List <Entities.Entity> > selections = null;
                if (SelectType == PlayerType.Ally)
                {
                    selections = GetPossibleSelections(performer.Owner.mBoard, performer, (uint)Min, (uint)Max);
                }
                if (SelectType == PlayerType.Enemy)
                {
                    selections = GetPossibleSelections(gameState.Players[(performer.Owner.getIndex() + 1) % 2].mBoard,
                                                       performer, (uint)Min, (uint)Max);
                }
                foreach (List <Entities.Entity> selection in selections)
                {
                    possibleActions.Add(new ActionOrder(mAction, performer, selection));
                }
            }
            return(possibleActions);
        }
Esempio n. 10
0
 public void Update(CardGameState GS)
 {
     if (HasEffect)
     {
         TheEffect.Update(GS);
     }
 }
Esempio n. 11
0
        public override List <Actions.ActionOrder> GetAIActions(CardGameState gameState, TurnInfo TI)
        {
            List <Actions.ActionOrder> results = new List <Actions.ActionOrder>();

            if (!IsPlaced)
            {
                CardZoneType   effectCardZoneType = mIsShared ? gameState.SharedEffects.mCardZoneType : Owner.mEffects.mCardZoneType;
                Actions.Action placeCardAction    = new Actions.PlaceCard_Action(this, effectCardZoneType);
                if (placeCardAction.CheckValidity(null, null, TI))
                {
                    results.Add(new Actions.ActionOrder(placeCardAction, null, null));
                }
            }
            else
            {
                foreach (Actions.ActionInfo AI in GetActions())
                {
                    if (AI.mAction.IsAvailable(this))
                    {
                        foreach (Actions.ActionOrder AO in AI.GetPossibleActionOrders(gameState, this))
                        {
                            if (AO.Action.CheckValidity(AO.Performer, AO.Selection, TI))
                            {
                                results.Add(AO);
                            }
                        }
                    }
                }
            }
            return(results);
        }
Esempio n. 12
0
 void OnStateChangeHandler(CardGameState state, bool isFirstState)
 {
     m_cardsInHandText.text     = "Cards In hand count:" + this.myPlayer.cardsInHand.Count;
     m_cardsInFieldText.text    = "Field Card count:" + state.cardsInField.Count;
     m_cardsInHandMapText.text  = "Cards In hand Map count:" + this.myPlayer.cardsInHandMap.Count;
     m_cardsInFieldMapText.text = "Field Card Map count:" + state.cardsInFieldMap.Count;
 }
        List <CardBase> sacrificeCards = new List <CardBase>(); //祭品列表

        public CallMonsterEffectProcess(CardBase calledMonster, CardGameState cardGameState, Player ownerPlayer) : base(ownerPlayer, "召唤怪兽")
        {
            canBeChained       = true;
            this.calledMonster = calledMonster;
            this.cardGameState = cardGameState;

            finishAction += () => { };
        }
Esempio n. 14
0
 /// <summary>
 /// 召唤怪兽到场上
 /// </summary>
 /// <param name="monsterCard"></param>
 public void CallMonster(CardBase monsterCard, CardGameState cardGameState = CardGameState.Unknown)
 {
     if (IsMyPlayer())
     {
         //检测召唤条件是否满足
         CallMonsterEffectProcess callMonsterEffectProcess = new CallMonsterEffectProcess(monsterCard, cardGameState, this);
         AddEffectProcess(callMonsterEffectProcess);
     }
 }
Esempio n. 15
0
 public void UpdatePersistance(CardGameState GS)
 {
     if (mPersistanceModules != null)
     {
         foreach (PersistanceModule PM in mPersistanceModules)
         {
             PM.Run(GS);
         }
     }
 }
Esempio n. 16
0
 public virtual bool NewTurn(CardGameState GS)
 {
     NumNewTurns += 1;
     if (NewTurnLength == NumNewTurns)
     {
         End();
         return(false);
     }
     return(true);
 }
Esempio n. 17
0
        public override void Process()
        {
            int           cardID            = int.Parse(GetContent("cardID"));
            CallType      callType          = (CallType)Enum.Parse(typeof(CallType), GetContent("callType"));
            CardGameState fromCardGameState = (CardGameState)Enum.Parse(typeof(CardGameState), GetContent("fromCardGameState"));
            CardGameState toCardGameState   = (CardGameState)Enum.Parse(typeof(CardGameState), GetContent("toCardGameState"));
            int           flag = int.Parse(GetContent("flag"));

            GameManager.GetDuelScene().OpponentCallMonster(cardID, callType, fromCardGameState, toCardGameState, flag);
        }
Esempio n. 18
0
        public override void CallMonsterNotify(int id, CallType callType, CardGameState fromCardGameState, CardGameState toCardGameState, int flag)
        {
            CCallMonster cCallMonster = new CCallMonster();

            cCallMonster.AddContent("cardID", id);
            cCallMonster.AddContent("callType", callType);
            cCallMonster.AddContent("fromCardGameState", fromCardGameState);
            cCallMonster.AddContent("toCardGameState", toCardGameState);
            cCallMonster.AddContent("flag", flag);
            ClientManager.GetSingleInstance().SendProtocol(cCallMonster);
        }
Esempio n. 19
0
 public Player(int index, CardGameState GS)
 {
     mPlayerIndex      = index;
     mCommandPoints    = kMaxCP;
     mBoard            = new PlayerBoard(index);
     mEffects          = new Effects.EffectHolder(GS, false, mPlayerIndex);
     mMaxMulligans     = kMaxMulligans;
     mMulligansUsed    = 0;
     mUnitCardsPlaced  = 0;
     mOtherCardsPlaced = 0;
 }
Esempio n. 20
0
 public override void Placed(CardZoneType CZ, CardList CL, CardGameState GS)
 {
     IsPlaced = true;
     Zone     = CZ;
     CL.AddCard(this);
     AddStatus("Placed this turn");
     if (GS.mTurnInfo.IsFirstDeployment())
     {
         AddStatus("Deployed");
     }
 }
Esempio n. 21
0
        public void AllKnownCasesPassWinCheck(int row1, int row2, int row3, CardGameState expect)
        {
            var expectation = new ConfigExpectation(row1, row2, row3, expect);

            var state = expectation.Config.GetState();

            Assert.True(
                state == expect,
                $"[!] Fail {expectation.Config}. Should be {expect}. Was {state}"
                );
        }
Esempio n. 22
0
 public void Update(CardGameState GS)
 {
     mEffects.UpdatePersistance();
     for (int i = 0; i < mBoard.RangeZones.Length; i++)
     {
         foreach (Entity E in mBoard.RangeZones[i].List.Cards)
         {
             E.Update();
         }
     }
     mEffects.Update();
 }
 protected override void BeforeProcessFunction()
 {
     if (cardGameState == CardGameState.Unknown)
     {
         duelScene.ShowAttackOrDefensePanel(calledMonster, (cardGameState) =>
         {
             this.cardGameState = cardGameState;
             RealFunction();
         });
         return;
     }
     RealFunction();
 }
Esempio n. 24
0
 public void NewTurn(CardGameState GS)
 {
     mEffects.NewTurn();
     mSpentCP          = false;
     mUnitCardsPlaced  = 0;
     mOtherCardsPlaced = 0;
     foreach (CardZone CZ in mBoard.RangeZones)
     {
         foreach (Entity E in CZ.List.Cards)
         {
             E.NewTurn();
         }
     }
 }
Esempio n. 25
0
        // This assumes the action is valid, it will not check!
        private static float EvaluateAction(int playerIndex, Actions.ActionOrder action, CardGameState gameState, int roundVictoryLimit)
        {
            Actions.ActionOrder actionCopy = action;
            CardGameState       stateCopy  = gameState;

            // We assume this is a valid action otherwise this action should never have been made available.
            actionCopy.Action.Execute(actionCopy.Performer, actionCopy.Selection, stateCopy);

            Player thisPlayerCopy = stateCopy.Players[playerIndex];
            // Check whether this action (or preceding actions this turn) allows us not to pass this turn.
            bool stillPassing = !(thisPlayerCopy.HasSpentCP() || thisPlayerCopy.WasCardPlaced());

            return(EvaluateMatchWinChance(playerIndex, stateCopy, roundVictoryLimit, stillPassing));
        }
 public override void Update(CardGameState GS)
 {
     foreach (CardZone rangeZone in  GS.Players[Node.OwnerIndex].mBoard.RangeZones)
     {
         foreach (Entities.Entity E in rangeZone.List.Cards)
         {
             Entities.Unit U = ((Entities.Unit)E);
             if (U.IsClass(AffectedClass))
             {
                 U.AttackCostModifier += Amount;
             }
         }
     }
 }
Esempio n. 27
0
        // Remember that actions that were not made from a certain game state cannot be used in any way with it.
        public override void TakeTurn(TurnInfo turnInfo, CardGameState gameState, CardGameManager manager)
        {
            if (turnInfo.IsMulligan)
            {
                // Pass in the mulligan for now
                manager.Continue();
            }
            else
            {
                bool shouldContinue = false;
                bool hasTakenAction = false;
                List <Actions.ActionOrder> availableActions = GetAvailableActions(turnInfo, gameState);

                while (!shouldContinue && availableActions.Count > 0)
                {
                    ActionsAndGameStateSet actionSet;
                    Utility.Serialiser.CreateActionsAndGameStateSet(gameState, availableActions, out actionSet);
                    float continueScore   = EvaluateMatchWinChance(getIndex(), gameState, manager.GetRoundVictoryLimit(), !hasTakenAction);
                    float maxScore        = 0;
                    int   bestActionIndex = -1;
                    for (int actionIndex = 0; actionIndex < actionSet.mAvailableActions.Count; actionIndex++)
                    {
                        float actionScore = EvaluateAction(getIndex(), actionSet.mAvailableActions[actionIndex],
                                                           actionSet.mCardGameStates[actionIndex], manager.GetRoundVictoryLimit());

                        if (actionScore > maxScore)
                        {
                            maxScore        = actionScore;
                            bestActionIndex = actionIndex;
                        }
                    }
                    if (maxScore > continueScore)
                    {
                        UnityEngine.Debug.Assert(bestActionIndex > -1);
                        // Update real game state with action.
                        manager.PassAction(availableActions[bestActionIndex]);
                        availableActions = GetAvailableActions(turnInfo, gameState);
                        hasTakenAction   = HasSpentCP() || WasCardPlaced();
                    }
                    else
                    {
                        shouldContinue = true;
                    }
                }

                // Continue at the end of the turn
                manager.Continue();
            }
        }
Esempio n. 28
0
        public override void Run(CardGameState GS)
        {
            bool hasRequiredUnit = false;

            foreach (CardZone CZ in mParentEffectEntity.Owner.mBoard.RangeZones)
            {
                foreach (Entities.Unit U in CZ.List.Cards)
                {
                    if (U.Name == mRequiredUnitName)
                    {
                        hasRequiredUnit = true;
                    }
                }
            }
            if (!hasRequiredUnit)
            {
                mParentEffectEntity.GetEffect().End();
            }
        }
Esempio n. 29
0
        private static float EvaluateFutureRounds(int playerIndex, CardGameState gameState, int roundsToWin, int opposingRoundsToWin)
        {
            if (roundsToWin == 0)
            {
                return(1.0f);
            }
            else if (opposingRoundsToWin == 0)
            {
                return(0.0f);
            }

            int opposingPlayerIndex = (playerIndex + 1) % 2;

            CardList playerHand         = gameState.Players[playerIndex].mHand;
            CardList opposingPlayerHand = gameState.Players[opposingPlayerIndex].mHand;

            return(TraverseRoundWinTree(playerIndex, playerHand.Cards.Count, ScoreHand(playerHand) / playerHand.Cards.Count, roundsToWin,
                                        opposingPlayerIndex, opposingPlayerHand.Cards.Count, ScoreHand(opposingPlayerHand) / opposingPlayerHand.Cards.Count, opposingRoundsToWin));
        }
Esempio n. 30
0
 public override void Update(CardGameState GS)
 {
     if (Selection != null)
     {
         if (!Done)
         {
             if (Selection.Count == 1)
             {
                 ((Unit)Selection[0]).Heal(OneHeal);
             }
             else
             {
                 ((Unit)Selection[0]).Heal(TwoHeal);
                 ((Unit)Selection[1]).Heal(TwoHeal);
             }
             Done = true;
         }
     }
 }