Exemplo n.º 1
0
 public bool AddCard(CardClass card)
 {
     if (card.player == owner)
     {
         deck.Push(card);
         return true;
     }
     return false;
 }
Exemplo n.º 2
0
 public void AddToHand(CardClass cc)
 {
     hand.AddCard(cc);
 }
Exemplo n.º 3
0
 public void RemoveCardFromHand(CardClass cc)
 {
     hand.RemoveCard(cc);
 }
Exemplo n.º 4
0
        private void SetupCardMovementAnimation(CardClass card, int offsetX, int offsetY, Vector2 cardLoc)
        {
            moveCard = card;
            MoveLocation[,] map = card.GetMove();
            moveStartLoc = ConvertMapCoordToScreen((int)cardLoc.X, (int)cardLoc.Y) + center;
            MoveLocation currentLoc = map[offsetY, offsetX];
            movementSteps.Clear();
            movementSteps.Push(new MoveSteps(offsetX, offsetY));
            while (currentLoc.x >= 0 && currentLoc.y >= 0 && !(currentLoc.x == 2 && currentLoc.y == 2))
            {
                movementSteps.Push(new MoveSteps(currentLoc.y, currentLoc.x));
                currentLoc = map[currentLoc.x, currentLoc.y];
            }

            moveCard.SetMoving(moveStartLoc);
            moving = true;
        }
Exemplo n.º 5
0
        private int NodeEval(CardClass[,] ms, PlayerTurn currTurn, Vector2 cardStart, Vector2 cardEnd, int depth)
        {
            int score = 0;
            Turn activeTurn = map.GetTurn(currTurn);
            Turn otherTurn = map.GetTurn(currTurn == PlayerTurn.Player1 ? PlayerTurn.Player2 : PlayerTurn.Player1);
            CardClass cc = null;
            bool foundActive = false;
            bool foundOther = false;
            int win_value = WinValue - 10 * depth;
            int dis = 0;
            for (int i = 0; i < ms.GetLength(0); i++)
            {
                for (int j = 0; j < ms.GetLength(1); j++)
                {
                    cc = ms[i, j];

                    if (cc != null && cc.GetCardType().player == currTurn)
                    {
                        foundActive = true;
                        score += cc.GetCardType().GetStat() + cc.GetCardType().numberOfMoves + cc.GetCardType().weight;
                        dis = Math.Abs(otherTurn.GateLane() - i) + Math.Abs(3 - j);
                        if (dis == 0)
                            score += win_value;
                        else
                            score += (int)(moveValue * (1.0f /dis));
                    }
                    else if (cc != null)
                    {
                        foundOther = true;
                        score -= cc.GetCardType().GetStat() - cc.GetCardType().numberOfMoves - cc.GetCardType().weight;
                        dis = Math.Abs(activeTurn.GateLane() - i) + Math.Abs(3 - j);
                        if (dis == 0)
                            score -= win_value;
                        else
                            score -= (int)(moveValue * (1.0f / dis));
                    }
                }
            }

            // Add for loop for the hands to sum them.

            foreach (CardClass c in hand.GetCardList())
            {
                score += c.GetCardType().GetStat() + c.GetCardType().numberOfMoves + c.GetCardType().weight;
            }

            foreach (CardClass c in otherTurn.GetHand().GetCardList())
            {
                score -= c.GetCardType().GetStat() - c.GetCardType().numberOfMoves - c.GetCardType().weight;
            }

            if (!foundActive && hand.Count == 0)
                score -= win_value;

            if (!foundOther && otherTurn.HandCount() == 0)
                score -= win_value;

            return score;// *(currTurn == PlayerTurn.Player2 ? 1 : -1);
        }
Exemplo n.º 6
0
 public void Render(SpriteBatch sb, CardClass selectedCard)
 {
     Render(sb, renderLoc, selectedCard);
 }
Exemplo n.º 7
0
 public void MoveCard(CardClass card, int x, int y)
 {
     MoveCard(card, x, y, 0, true);
 }
Exemplo n.º 8
0
        public override void Update(GameTime gt)
        {
            activeTurn.Update(gt);
            if (movementSteps.Count > 0 && moveCard != null)
            {
                MoveSteps ml = movementSteps.Peek();
                Vector2 currentLoc = moveCard.GetMovingLoc();
                Vector2 v = ConvertMapCoordToScreen(ml.x - 2, ml.y - 2) + moveStartLoc;
                Vector2 dir = v - currentLoc;
                dir.Normalize();

                dir = dir * (float)(20/gt.ElapsedGameTime.TotalMilliseconds);

                if (Vector2.Distance(v, currentLoc) < 1.0f)
                {
                    movementSteps.Pop();
                }

                currentLoc = dir + currentLoc;
                moveCard.SetMoving(currentLoc);
            }
            else if (moveCard != null)
            {
                moveCard.EndMoving();
                moveCard = null;
                moving = false;
            }
        }
Exemplo n.º 9
0
        protected bool MoveCard(CardClass card, int x, int y, int depthOffset, bool aiTest)
        {
            Vector2 mapLoc = new Vector2(x, y);
            // Can't move to the sides.
            if (mapLoc.X == 0 || mapLoc.X == map.GetLength(0) - 1)
                return false;

            if (card == null)
                return false;

            Vector2 cardLoc = ConvertScreenCoordToMap(card.GetLoc());

            bool good = false;

            // Handle first card placement.
            if (cardLoc.X == -1 && cardLoc.Y == -1)
            {
                // placing a new card.
                if (activeTurn.InDeploymentZone(mapLoc) && map[(int)mapLoc.Y, (int)mapLoc.X] == null && PlaceCard(card, (int)mapLoc.X, (int)mapLoc.Y, moveID))
                {
                    moveID++;
                    good = true;
                    if (aiTest)
                    {
                        SwitchTurns();
                    }
                }
                else
                    ResetSelectedCard();
            }
            // Handle card movement.
            else if ((deploy - depthOffset) <= 0 && mapLoc.X >= 0 && mapLoc.Y >= 0 && mapLoc.X < map.GetLength(0) && mapLoc.Y < map.GetLength(1) && (card.player == activeTurn.GetPlayerTurn() || !aiTest))
            {
                MoveLocation[,] moveOption = card.GetMove();
                int transX = (int)(mapLoc.X - cardLoc.X) + 2;
                int transY = (int)(mapLoc.Y - cardLoc.Y) + 2;

                if (transX == 2 && transY == 2) // center of the move map IE Early out
                    return false;

                // Check for the actual move.
                if (transX >= 0 && transY >= 0 && transX < moveOption.GetLength(0) && transY < moveOption.GetLength(1) && moveOption[transY, transX] != null)
                {
                    good = RecursiveCardMovement(card, cardLoc, moveOption[transY, transX], moveOption, transX, transY, moveID);
                    if (good)
                    {
                        moveID++;
                        if (aiTest)
                        {
                            SetupCardMovementAnimation(card, transX, transY, cardLoc);
                            SwitchTurns();
                        }
                    }
                }
                else
                {
                    ResetSelectedCard();
                }
            }
            else
            {
                ResetSelectedCard();
            }

            return good;
        }
Exemplo n.º 10
0
 public bool TestRecursiveCardMovement(CardClass card, Vector2 cardLoc, MoveLocation currentLoc, MoveLocation[,] map, int transX, int transY)
 {
     return RecursiveCardMovement(card, cardLoc, currentLoc, map, transX, transY, 0, false);
 }
Exemplo n.º 11
0
        public void UndoMove(CardClass cc)
        {
            if (moveStack.Count > 0)
            {

                uint ID = moveStack.Peek().moveID;

                while (moveStack.Peek().moveID == ID)
                {
                    MoveList ml = moveStack.Pop();
                    if (ml.movedCard != cc)
                    {
                        int kk = 0;
                        kk++;
                    }

                    Vector2 cardPrevLoc = ConvertScreenCoordToMap(ml.cardPrevLoc);
                    Vector2 startLoc = ConvertScreenCoordToMap(ml.startLoc);
                    Vector2 toLoc = ConvertScreenCoordToMap(ml.toLoc);

                    CardClass movedCard = map[(int)toLoc.Y, (int)toLoc.X];
                    movedCard.SetLocation(ml.cardPrevLoc, false);
                    movedCard.SetLocation(ml.startLoc, true);
                    if (startLoc.X > 0 & startLoc.Y > 0)
                        map[(int)startLoc.Y, (int)startLoc.X] = movedCard;
                    else
                    {
                        Turn activeTurn = GetTurn(movedCard.GetCardType().player);
                        activeTurn.AddToHand(movedCard);
                    }

                    map[(int)toLoc.Y, (int)toLoc.X] = ml.replacedCard;
                }
            }
        }
Exemplo n.º 12
0
 public bool RecursiveCardMovement(CardClass card, Vector2 cardLoc, MoveLocation currentLoc, MoveLocation[,] map, int transX, int transY, uint ID)
 {
     return RecursiveCardMovement(card, cardLoc, currentLoc, map, transX, transY, ID, true);
 }
Exemplo n.º 13
0
 public bool PlaceCard(CardClass card, int x, int y, uint ID)
 {
     return PlaceCard(card, x, y, 0, 0, ID, true);
 }
Exemplo n.º 14
0
 public bool MoveCardAI(CardClass card, int x, int y, int depth)
 {
     return MoveCard(card, x, y, depth, false);
 }
Exemplo n.º 15
0
 public bool AddCard(CardClass card)
 {
     if (card != null && card.player == owner)
     {
         Vector2 offset = new Vector2(CardClass.cardWidth, 0);
         if (owner == PlayerTurn.Player1)
             card.SetLocation(renderLoc + offset*hand.Count, false);
         else
             card.SetLocation(renderLoc - offset * hand.Count, false);
         hand.Add(card);
         return true;
     }
     return false;
 }
Exemplo n.º 16
0
        private bool PlaceCard(CardClass card, int x, int y, int transX, int transY, uint ID, bool place)
        {
            if ( x >= 0 && y >= 0 && x < map.GetLength(1) && y < map.GetLength(0))
            {
                CardClass replacedCard = map[y, x];
                CardClass winner = card;
                int modifier = 0;
                bool forwardMove = false;
                if (!(transX == 0 && transY == 0))
                {
                    modifier = card.GetMove()[transY, transX].modifier;
                    forwardMove = card.GetMove()[transY, transX].y == transX;
                }

                if (replacedCard != null && replacedCard.player != card.player)
                    // Check to see which one wins in this battle.
                    winner = replacedCard.GetCardType().GetStat() <= card.GetCardType().GetStat() + modifier ? card : replacedCard;
                else if (replacedCard != null)
                {
                    string type = card.GetCardType().typeName.Substring(0, card.GetCardType().typeName.Length - 1);
                    string replaceType = replacedCard.GetCardType().typeName.Substring(0, replacedCard.GetCardType().typeName.Length - 1);
                    string lastLetter = card.GetCardType().typeName.Substring(card.GetCardType().typeName.Length - 1);
                    if (type.Equals("Soldier") && replaceType.Equals("Soldier") && place)
                    {
                        foreach (CardType ct in cardTypes)
                        {
                            if (ct.typeName.ToLower().ToString().Equals("stack" + lastLetter.ToLower()))
                            {
                                winner = new CardClass(ct, card.player);
                                winner.SetLocation(replacedCard.GetLoc(), true);
                                break;
                            }
                        }

                        if (winner == null)
                            return false;
                    }
                    else
                        // tried to move onto own card.
                        return false;
                }

                if (y == activeTurn.GateLane())
                    return false;

                // Check for movement into the gates
                Turn other = turns.Find(delegate(Turn t) { return t != activeTurn; });
                if (other != null && y == other.GateLane())
                {
                    if (!forwardMove || x != 3)
                    {
                        return false;
                    }
                }

                Vector2 oldLoc = ConvertScreenCoordToMap(card.GetPrevLocation());
                // Cards can't move into their old position.
                if ((int)oldLoc.X == x && (int)oldLoc.Y == y)
                    return false;

                if (place)
                {
                    MoveList ml = new MoveList();
                    ml.moveID = ID;
                    ml.movedCard = card;
                    ml.replacedCard = (winner == replacedCard ? card : replacedCard);
                    ml.cardPrevLoc = winner.GetPrevLocation();
                    Vector2 newLoc = center + new Vector2(x * (CardClass.cardWidth + spacing), y * (CardClass.cardHeight + spacing));
                    ml.toLoc = newLoc;
                    ml.startLoc = winner.GetLoc();

                    moveStack.Push(ml);
                    map[y, x] = winner;
                    Vector2 clear = ConvertScreenCoordToMap(card.GetLoc());
                    if (clear.Y >= 0 && clear.X >= 0)
                        map[(int)clear.Y, (int)clear.X] = null;
                    winner.SetLocation(newLoc, true);

                    if (card.player == PlayerTurn.Player1)
                        turns[0].RemoveCardFromHand(card);
                    else if (card.player == PlayerTurn.Player2)
                        turns[1].RemoveCardFromHand(card);
                }

                return (place ? true : winner == card);
            }

            return false;
        }
Exemplo n.º 17
0
 public bool RemoveCard(CardClass card)
 {
     bool found = false;
     Vector2 offset = new Vector2(CardClass.cardWidth, 0);
     int count = 0;
     foreach (CardClass cc in hand)
     {
         if (cc == card && !found)
         {
             found = true;
             count--;
         }
         else if (found)
         {
             if (owner == PlayerTurn.Player1)
                 cc.SetLocation(renderLoc + offset * count, false);
             else
                 cc.SetLocation(renderLoc - offset * count, false);
         }
         count++;
     }
     return hand.Remove(card);
 }
Exemplo n.º 18
0
        private bool RecursiveCardMovement(CardClass card, Vector2 cardLoc, MoveLocation currentLoc, MoveLocation[,] map, int transX, int transY, uint ID, bool place)
        {
            if (transX == 2 && transY == 2)
            {
                return true;
            }

            bool placed = false;

            Stack<MoveLocation> order = new Stack<MoveLocation>(2);
            while (currentLoc.x >= 0 && currentLoc.y >= 0 && !(currentLoc.x == 2 && currentLoc.y == 2))
            {
                order.Push(currentLoc);
                currentLoc = map[currentLoc.x, currentLoc.y];
            }
            order.Push(currentLoc);

            MoveLocation next;
            while (order.Count > 1)
            {
                currentLoc = order.Pop();
                next = order.Peek();
                if (place)
                {
                    placed = PlaceCard(card, (int)cardLoc.X + next.y - 2, (int)cardLoc.Y + next.x - 2, next.y, next.x, ID, place) || placed;
                }
                else
                {
                    placed = PlaceCard(card, (int)cardLoc.X + next.y - 2, (int)cardLoc.Y + next.x - 2, next.y, next.x, ID, place);
                }
                if (!placed)
                    return placed;
            }

            //if (currentLoc.x >= 0 && currentLoc.y >= 0 && !(currentLoc.x == 2 && currentLoc.y == 2))
            //{
            //    if (!RecursiveCardMovement(card, cardLoc, map[currentLoc.x, currentLoc.y], map, currentLoc.y, currentLoc.x))
            //        return recurse;
            //}
            ////PlaceCard(selectedCard, (int)mapLoc.X, (int)mapLoc.Y, moveOption[transY, transX].modifier)

            if (place)
            {
                placed = PlaceCard(card, (int)cardLoc.X + transX - 2, (int)cardLoc.Y + transY - 2, transX, transY, ID, place) || placed;
            }
            else
            {
                placed = PlaceCard(card, (int)cardLoc.X + transX - 2, (int)cardLoc.Y + transY - 2, transX, transY, ID, place);
            }

            return placed;
        }
Exemplo n.º 19
0
 public void Render(SpriteBatch sb, Vector2 origin, CardClass selectedCard)
 {
     CardClass card;
     for (int i = 0; i < hand.Count; i++ )
     {
         card = hand[i];
         card.Render(sb);
     }
 }
Exemplo n.º 20
0
 public void MoveCard(CardClass card, Vector2 pos)
 {
     Vector2 mapLoc = ConvertScreenCoordToMap(pos);
     MoveCard(card, (int)mapLoc.X, (int)mapLoc.Y);
 }