示例#1
0
        public bool commit()
        {
            bool ret = false;

            if (!isDirty)
            {
                return(ret);
            }
            string colNames = ""; foreach (DbField f in bscTbl.Fields.from(2))

            {
                colNames += ", " + f.sql(db);
            }
            colNames = colNames.Substring(2);

            if (isInDb)
            {
                db.exec(bscTbl.sR(db.cd(bscTbl.Fields[1].sql(db)).EQ((long)(this[1]))).sC(colNames).UPD(values.from(2).array()));
            }
            else
            {
                db.push(bscTbl.INS(bscTbl.sC("Max(id) + 1, " + Db.ds(values.from(2).array())).SLD));
                db.push(bscTbl.sR(db.cd("id").EQ(bscTbl.sC("Max(id)").SLD0)).SLD0);
                Recs.Push(clone(db.exec()[1].Rows[1]));
                ret = true;
            }
            ori     = val.Clone();
            isDirty = false;
            return(ret);
        }
示例#2
0
        public void Find()
        {
            // Check for swaps.
            int maxExtraSuits = ExtraSuits(FindTableau.NumberOfSpaces);

            for (int from = 0; from < NumberOfPiles; from++)
            {
                Pile         fromPile     = FindTableau[from];
                int          splitRow     = fromPile.Count - RunFinder.GetRunUpAnySuit(from);
                int          extraSuits   = 0;
                HoldingStack holdingStack = HoldingStacks[from];
                for (int fromRow = fromPile.Count - 1; fromRow >= splitRow; fromRow--)
                {
                    if (fromRow < fromPile.Count - 1)
                    {
                        if (fromPile[fromRow].Suit != fromPile[fromRow + 1].Suit)
                        {
                            // This is a cross-suit run.
                            extraSuits++;
                            if (extraSuits > maxExtraSuits + holdingStack.Suits)
                            {
                                break;
                            }
                        }
                    }

                    Check(from, fromRow, extraSuits, maxExtraSuits);
                }
            }
        }
示例#3
0
 public Money(string owner, Change[] blueprints)
 {
     this.blueprints = blueprints;
     if (owner == "Player")
     {
         changes[0] = new Pile(blueprints[0], 80);
         changes[1] = new Pile(blueprints[1], 40);
         changes[2] = new Pile(blueprints[2], 20);
         changes[3] = new Pile(blueprints[3], 10);
         changes[4] = new Pile(blueprints[4], 5);
     }
     else if (owner == "Empty")
     {
         for (int i = 0; i < 5; i++)
         {
             changes[i] = new Pile(blueprints[i], 0);
         }
     }
     else
     {
         string[] values = owner.Split(' ');
         for (int i = 0; i < 5; i++)
         {
             changes[i] = new Pile(blueprints[i], Int32.Parse(values[i]));
         }
     }
 }
示例#4
0
        public void MoveCard(string gamePin, MoveCardModel moveCardModel)
        {
            Status status = GameManager.MoveCard(gamePin, moveCardModel);

            if (status == Status.Success)
            {
                Clients.Group(gamePin).MoveCard(moveCardModel);

                //Delete source pile if it is empty and a run pile
                Pile oldPile = GameManager.GetGameState(gamePin).Single((pile) => pile.PileNo == moveCardModel.SourcePileNo);
                if (oldPile.GetCards().Count() == 0 && oldPile.PileType == PileType.Run)
                {
                    DeleteEmptyRunPile(gamePin, oldPile);
                }
            }
            else
            {
                //TODO: Pile version issues...
                IEnumerable <Pile> piles = GameManager.GetGameState(gamePin);

                Clients.Caller.StartGame(piles);
                //MoveRejected(moveCardModel.TargetPileVersionNo, moveCardModel.TargetPileNo, moveCardModel.TargetIndex,
                //    moveCardModel.SourcePileVersionNo, moveCardModel.SourcePileNo, moveCardModel.SourceIndex);
            }
        }
示例#5
0
        public void CheckCardCountIntegrity()
        {
            Card     card     = new Card("", "", 0, "", "");
            Pile     property = new Pile("delsuckah", "Property");
            Pile     discard  = new Pile("game", "Discard");
            CardDeck deck     = new CardDeck();
            Pile     myHand   = new Pile("delsuckahh", "Hand");
            Player   player1  = new Player("delsuckahh");

            deck.ShuffleDeck();
            while (card.Type != "Property")
            {
                card = deck.DealCard();
                if (card.Type == "Property")
                {
                    break;
                }
                else
                {
                    discard.AddCard(card);
                }
            }
            property.AddCard(card);
            player1.DrawCards(2, myHand, deck);

            Assert.AreEqual(106, deck.numCards + discard.GetSize() + property.GetSize() + myHand.GetSize());
        }
示例#6
0
 private bool                   checkDirty()
 {
     if (!isDirty)
     {
         return(false);
     }
     for (int inx = 1; inx <= val.Len; inx++)
     {
         bool isDifferent = false;
         Type t           = val[inx].GetType();
         if (t == typeof(Reach))
         {
             isDifferent = !((Reach)(ori[inx])).equals((Reach)(val[inx]));
         }
         if (t == typeof(string))
         {
             isDifferent = !((string)(ori[inx])).Equals((string)(val[inx]));
         }
         if (t == typeof(double))
         {
             isDifferent = ((double)(ori[inx])) != ((double)(val[inx]));
         }
         if (t == typeof(long))
         {
             isDifferent = ((long)(ori[inx])) != ((long)(val[inx]));
         }
         if (isDifferent)
         {
             return(true);
         }
     }
     ori = new Pile <object>();
     return(false);
 }
示例#7
0
    private void MoveCardPile(Card card, Pile pile)
    {
        CardObject singleCard = CardManager.GetCards(card)[0];

        singleCard.transform.parent = pile.transform;
        pile.RearrangeCards();
    }
示例#8
0
文件: Pile.cs 项目: MichalMajka/Poker
    public static Pile operator -(Pile firstAdditive, Pile secondAdditive)
    {
        Pile ret = new Pile(firstAdditive.storedChange, 0);

        ret.quantity = firstAdditive.quantity - secondAdditive.quantity;
        return(ret);
    }
示例#9
0
    //This is an approximation.
    //Its fairly accurate only when range area << deposit area
    public Pile GetSupplyWithinRange(Vector3 position, float range, Resource resource = null)
    {
        float distance = position.YChangedTo(0).Distance(transform.position.YChangedTo(0));

        if (distance > Extent)
        {
            return(new Pile());
        }

        Pile supply_within_range = new Pile().PutIn(Composition);

        float gaussian_weight = Mathf.Exp(-0.5f * Mathf.Pow(distance / Extent * 3, 2)) / Mathf.Sqrt(2 * Mathf.PI);
        float relative_area   = Mathf.Min(1, (range * range) / (Extent * Extent));
        float volume          = Volume;

        if (resource != null)
        {
            volume = Supply.GetVolumeOf(resource);
            supply_within_range = new Pile().PutIn(resource, 1);
        }

        float volume_within_range = relative_area * volume;

        switch (Distribution)
        {
        case DistributionType.Gaussian:
            volume_within_range *= gaussian_weight / unit_gaussian_area;
            break;
        }

        return(supply_within_range.Normalized() * Mathf.Min(volume, volume_within_range));
    }
示例#10
0
        static void Main(string[] args)
        {
            TcpChannel chnl = new TcpChannel();

            ChannelServices.RegisterChannel(chnl, false);


            //Pile pile = (Pile)Activator.GetObject(typeof(Pile), "tcp://localhost:1111/Pile");

            UsinePile usinePile = (UsinePile)Activator.GetObject(typeof(UsinePile), "tcp://localhost:1111/UsinePile");

            Console.WriteLine("Client 1");
            Console.WriteLine("donnez la taille de la pile a creer : ");
            Pile pile = usinePile.creationPile(int.Parse(Console.ReadLine()));


            for (int i = 0; i < 3; i++)
            {
                Console.WriteLine("Etudiant" + i + 1);
                String nom    = Console.ReadLine();
                String prenom = Console.ReadLine();
                int    id     = int.Parse(Console.ReadLine());
                pile.empiler(new Etudiant(id, nom, prenom));
            }

            //pile.empiler(new Etudiant(11,"houssein","hhoo"));

            Console.WriteLine("taille courante : " + pile.lire_taille_courante());

            Console.WriteLine("taille max : " + pile.lire_taille_max());
        }
示例#11
0
    /// <summary>
    /// Redistributes the Ballots in the given Pile to the Piles of the active
    /// candidates. </summary>
    /// <param name="pile"> The Pile whose Ballots are to be redistributed. </param>
    private void redistributeBallots(Pile pile)
    {
        int           candidate;
        Pile          votePile;
        List <Ballot> ballotsToRemove = new List <Ballot>();

        // For each Ballot in the Pile
        foreach (Ballot ballot in pile.Ballots)
        {
            // Get the candidate for which the Ballot is voting
            candidate = ballot.getCandidateForBallot(activeCandidates);
            // If this Ballot is casting a vote
            if (candidate > 0)
            {
                // Get the corresponding Pile for this candidate
                votePile = piles[candidate];
                // Add this Ballot to the Pile
                votePile.AddBallot(ballot);
                ballotsToRemove.Add(ballot);
            }
        }

        foreach (Ballot ballot in ballotsToRemove)
        {
            pile.Ballots.Remove(ballot);
        }
    }
        public ShitheadPileLogicTests()
        {
            _game = new Game(ShitheadConstants.GAME_TYPE, string.Empty)
            {
                Id = Guid.Parse("D0199003-D79D-493A-8118-50F9EE2A7755")
            };

            _discardPile = new Pile(_game, PileType.Discard, ShitheadConstants.PileIdentifiers.DISCARD);
            _game.Piles.Add(_discardPile);

            var burnPile = new Pile(_game, PileType.Discard, ShitheadConstants.PileIdentifiers.BURN);

            _game.Piles.Add(burnPile);

            _deckPile = new Pile(_game, PileType.Deck, ShitheadConstants.PileIdentifiers.DECK);
            _game.Piles.Add(_deckPile);

            _player1    = AddPlayer(Guid.Parse("E4F475AA-0FAB-4FAA-883E-C7ED1D26F5C0"));
            _game.State = _player1.Id.ToString();

            _shitheadMoveValidator = Substitute.For <IShitheadMoveValidator>();
            var shitheadPlayerLogic = Substitute.For <IShitheadPlayerLogic>();

            _shitheadPileLogic = new ShitheadPileLogic(_shitheadMoveValidator, shitheadPlayerLogic);
        }
示例#13
0
 public void AddPile(Pile pile)
 {
     foreach (Card card in pile)
     {
         _histogram[card.Value]++;
     }
 }
示例#14
0
        public string sql(Db db)
        {
            string ret = "UPDATE " + db.dbTable(Update) + " SET ";

            for (int i = 1; i <= Fields.Len; i++)
            {
                if ((Values[i]).GetType() == typeof(DbSlc))
                {
                    ret += Fields[i].sql(db) + " = ( " + ((DbSlc)Values[i]).sql(db) + "), ";
                }
                else
                {
                    ret += Fields[i].sql(db) + " = " + Values[i] + ", ";
                }
            }
            ret          = ret.Substring(0, ret.Length - 2);
            string where = "\r\n WHERE "; if (this.where.Len > 0)
            {
                where += "( "; foreach (DbCnd j in this.where)
                {
                    where += "(" + j.sql(db) + ") AND ";
                }
                where = where.Substring(0, where.Length - 4) + " ) ";
            }
            if (this.where.Len > 0)
            {
                ret += where;
            }
            return(ret);
        }
示例#15
0
文件: IParse.cs 项目: QsCompany/Qs
        public bool Contain(IList <char> list, Tree parent)
        {
            Pile.Save();
            var T = new Tree(Pile, parent, (Kind)Kind.Operator);

            return(Pile.Open && list.Contains(Pile.Current) ? Pile.Next() | T.Set() : Pile.Leave(false));
        }
示例#16
0
 public void SendMain()
 {
     while (Pile.Count > 0)
     {
         md.TurnDeck(Pile.Pop());
     }
 }
示例#17
0
        public Game()
        {
            Seed = -1;
            TraceStartFinish = false;
            TraceDeals = false;
            TraceMoves = false;
            ComplexMoves = false;
            Diagnostics = false;
            Instance = -1;

            Shuffled = new Pile();
            Tableau = new Tableau();

            Candidates = new MoveList();
            SupplementaryList = new MoveList();
            RunFinder = new RunFinder();
            FaceLists = new PileList[(int)Face.King + 2];
            for (int i = 0; i < FaceLists.Length; i++)
            {
                FaceLists[i] = new PileList();
            }
            Coefficients = null;

            TableauInputOutput = new TableauInputOutput(Tableau);
            MoveProcessor = new MoveProcessor(this);

            Variation = Variation.Spider4;
            AlgorithmType = AlgorithmType.Study;
        }
示例#18
0
        private int MoveOffUsingSpaces(int from, int fromRow, int to, int remainingSuits, int n)
        {
            int suits = Math.Min(remainingSuits, n);

            if (Diagnostics)
            {
                Utils.WriteLine("MOUS: {0} -> {1}: {2}", from, to, suits);
            }
            for (int i = n - suits; i < n; i++)
            {
                // Move as much as possible but not too much.
                Pile fromPile       = Tableau[from];
                int  currentFromRow = fromPile.Count - Tableau.GetRunUp(from, fromPile.Count);
                if (currentFromRow < fromRow)
                {
                    currentFromRow = fromRow;
                }
                int runLength = fromPile.Count - currentFromRow;
                MakeSimpleMove(from, -runLength, Spaces[i]);
                MoveStack.Push(new Move(Spaces[i], -runLength, to));
            }
            for (int i = n - 2; i >= n - suits; i--)
            {
                int runLength = Tableau[Spaces[i]].Count;
                MakeSimpleMove(Spaces[i], -runLength, Spaces[n - 1]);
                MoveStack.Push(new Move(Spaces[n - 1], -runLength, Spaces[i]));
            }
            return(suits);
        }
示例#19
0
 public PlayCard(int id = -1, int idx = 0)
 {
     this.libId = id;
     this.globalIdx = idx;
     this.pos = 0;
     this.pile = Pile.none;
 }
示例#20
0
        public static void Main()
        {
            int[] options = ReadInts(Console.ReadLine(), 2);
            int[] sizes   = ReadInts(Console.ReadLine(), options[0]);// iterates over all 1 000 000 sizes one more time than needed

            int freed = 0;

            if (sizes.Length > 1)
            {
                Pile p    = new Pile(options[1]);
                int  last = sizes[0];
                p.Add(last);
                bool increasing = sizes[0] < sizes[1];
                for (int i = 1; i < sizes.Length; ++i)
                {
                    bool inc = last < sizes[i];
                    if (sizes[i] != last && (increasing || !inc) && p.Add(sizes[i]))
                    {
                        ++freed;
                    }
                    else
                    {
                        p.Clear();
                        p.Add(sizes[i]);
                    }
                    increasing = inc;
                    last       = sizes[i];
                }
            }
            Console.WriteLine(freed);
        }
示例#21
0
 public PlayCard(int id = -1, int idx = 0)
 {
     this.libId     = id;
     this.globalIdx = idx;
     this.pos       = 0;
     this.pile      = Pile.none;
 }
示例#22
0
        public bool Parse(Tree parent, int i)
        {
            BasicParse.Pile.Save(Kind.Expression);
            var T = new Tree(BasicParse.Pile, parent, GetKind(i))
            {
                GeneratedBy = this
            };
            bool vB;
            var  vB1 = i < 4 ? Parse(T, ++i) : this[EPNames.ComplexHeritachy].Parse(T);

            if (vB1)
            {
                do
                {
                    vB = BasicParse.GetOperator(T, Descripter.Operators[i - 1]);
                    if (vB)
                    {
                        vB = Parse(T, i);
                    }
                } while (vB);
            }
            T             = Reform(T);
            T.GeneratedBy = this;
            if (vB1)
            {
                if (T.Children.Count == 1)
                {
                    T = T.Children[0];
                    parent.Add(T);
                    return(Pile.Leave(vB1));
                }
            }
            return(T.Set(vB1));
        }
示例#23
0
        internal DbIns(string into, Pile <DbField> fields, object[] values)
        {
            init();
            //this.fieldNames.Add(fieldNames); //fields = fields.Trim(); while (fields.Length > 0) { this.fields.Add(utl.cutl(ref fields, ",").Trim()); fields = fields.Trim(); }
            //this.fieldTypes.Add(fieldTypes); //fields = fields.Trim(); while (fields.Length > 0) { this.fields.Add(utl.cutl(ref fields, ",").Trim()); fields = fields.Trim(); }
            this.fields = fields.Clone();
            foreach (object o in values)
            {
                if (o.GetType() == typeof(string))
                {
                    this.values.Add((string)o);
                }
                else if (o.GetType() == typeof(double))
                {
                    this.values.Add(("" + o).Replace(",", "."));
                }
                else
                {
                    this.values.Add("" + o);
                }
            }
            this.into = into.Trim();
            string tShort = utl.cutl(ref into, ",").Trim().ToLower();
            string tName  = utl.cutl(ref tShort, " ").Trim();

            tShort = tShort.Trim(); if (tShort.Length == 0)
            {
                tShort = tName;
            }
            into = tName.Trim() + " " + tShort.Trim();
        }
示例#24
0
        private Player AddPlayer(Guid id)
        {
            if (_game.Players.Any(p => p.Id == id))
            {
                throw new Exception($"Cannot add duplicate player id {id}");
            }

            var player = new Player(_game)
            {
                Id = id,
            };

            _game.Players.Add(player);

            var handPile = new Pile(_game, PileType.PlayerHand, Game.GetPlayerIdentifier(player, PlayerHandType.Hand.ToString()));

            _game.Piles.Add(handPile);

            var faceUpPile = new Pile(_game, PileType.PlayerHand, Game.GetPlayerIdentifier(player, PlayerHandType.FaceUp.ToString()));

            _game.Piles.Add(faceUpPile);

            var faceDownPile = new Pile(_game, PileType.PlayerHand, Game.GetPlayerIdentifier(player, PlayerHandType.FaceDown.ToString()));

            _game.Piles.Add(faceDownPile);

            return(player);
        }
示例#25
0
 public GameState()
 {
     cardFactory = new CardFactory();
     hero = new Player(this, LocationPlayer.HERO);
     villain = new Player(this, LocationPlayer.VILLAIN);
     stack = new Pile(new Location(LocationPile.STACK, LocationPlayer.NOONE));
 }
示例#26
0
        public void AddDeckCardsToPile(ShitheadGameConfig config, Pile pile, CreateDeckOptions options)
        {
            var cards = new List <Card>();

            for (var i = 1; i <= 13; i++)
            {
                cards.Add(new Card(pile, CardSuit.Clubs, i));
                cards.Add(new Card(pile, CardSuit.Diamonds, i));
                cards.Add(new Card(pile, CardSuit.Hearts, i));
                cards.Add(new Card(pile, CardSuit.Spades, i));
            }

            if (options.IncludeJokers)
            {
                for (var i = 0; i < 2; i++)
                {
                    cards.Add(new Card(pile, CardSuit.Joker, config.Joker));
                }
            }

            if (options.Shuffled)
            {
                _shuffler.Shuffle(cards);
            }

            foreach (var card in cards)
            {
                pile.Cards.Add(card);
            }
        }
        public void CanPlayCardsOnPile_Invalid_when_card_is_lower_than_pile()
        {
            // Arrange
            var config = new ShitheadGameConfig {
                Joker = 15, Reset = 2, Invisible = 3, Reverse = 7, Burn = 10, Skip = 15
            };
            var  shitheadMoveValidator = new ShitheadMoveValidator();
            Pile pile = new Pile(null, PileType.Deck, "")
            {
                Cards = new List <Card>
                {
                    new Card(null, CardSuit.Clubs, 14),
                },
            };
            var cardsToPlay = new List <Card>
            {
                new Card(null, CardSuit.Clubs, 5)
            };

            // Act
            var result = shitheadMoveValidator.CanPlayCardsOnPile(config, pile, cardsToPlay);

            // Assert
            var expectedValidationResult = string.Format(Resources.Card__0__is_not_higher_or_equal_to_card__1_, cardsToPlay.First(), pile.Cards.First());

            Assert.Equal(expectedValidationResult, result);
        }
示例#28
0
        //private Pile<DbObject> rows = new Pile<DbObject>();

        private DbObj clone(Pile <Reach> row)
        {
            DbObj ret = Clone();

            ret.isInDb       = true;
            ret.initializing = true;
            for (int i = 1; i <= row.Len; i++)
            {
                Type typ = ret[i].GetType();
                if (typ == typeof(Reach))
                {
                    ret[i] = row[i]; continue;
                }
                if (typ == typeof(string))
                {
                    ret[i] = row[i].text; continue;
                }
                if (typ == typeof(long))
                {
                    ret[i] = long.Parse(row[i]); continue;
                }
                if (typ == typeof(double))
                {
                    ret[i] = double.Parse(row[i]); continue;
                }
                throw new Exception("Unknown Data Type in DbObj.clone()");
            }
            ret.initializing = false;
            return(ret);
        }
        public void CanPlayCardsOnPile_Valid_when_card_can_be_played_on_anything(int cardToPlayValue)
        {
            // Arrange
            var config = new ShitheadGameConfig {
                Joker = 15, Reset = 2, Invisible = 3, Reverse = 7, Burn = 10, Skip = 15
            };
            var  shitheadMoveValidator = new ShitheadMoveValidator();
            Pile pile = new Pile(null, PileType.Deck, "")
            {
                Cards = new List <Card>
                {
                    new Card(null, CardSuit.Clubs, 14)
                },
            };
            var cardsToPlay = new List <Card>
            {
                new Card(null, CardSuit.Clubs, cardToPlayValue)
            };

            // Act
            var result = shitheadMoveValidator.CanPlayCardsOnPile(config, pile, cardsToPlay);

            // Assert
            Assert.Null(result);
        }
 private void FindUncoveringMoves(int maxExtraSuits)
 {
     // Find all uncovering moves.
     UncoveringMoves.Clear();
     for (int from = 0; from < NumberOfPiles; from++)
     {
         Pile fromPile = FindTableau[from];
         int  fromRow  = fromPile.Count - RunFinder.GetRunUpAnySuit(from);
         if (fromRow == 0)
         {
             continue;
         }
         int      fromSuits = RunFinder.CountSuits(from, fromRow);
         Card     fromCard  = fromPile[fromRow];
         PileList faceList  = FaceLists[(int)fromCard.Face + 1];
         for (int i = 0; i < faceList.Count; i++)
         {
             HoldingStack.Clear();
             int to = faceList[i];
             if (fromSuits - 1 > maxExtraSuits)
             {
                 int holdingSuits = FindHolding(FindTableau, HoldingStack, false, fromPile, from, fromRow, fromPile.Count, to, maxExtraSuits);
                 if (fromSuits - 1 > maxExtraSuits + holdingSuits)
                 {
                     break;
                 }
             }
             Pile toPile = FindTableau[to];
             Card toCard = toPile[toPile.Count - 1];
             int  order  = GetOrder(toCard, fromCard);
             UncoveringMoves.Add(new Move(from, fromRow, to, order, AddHolding(HoldingStack.Set)));
         }
     }
 }
        private void AddSupplementaryMove(Move move, Pile pile, HoldingSet holdingSet, bool undoHolding)
        {
            // Add moves to the holding piles.
            for (int i = 0; i < holdingSet.Count; i++)
            {
                HoldingInfo holding     = holdingSet[i];
                Move        holdingMove = new Move(MoveType.Basic, MoveFlags.Holding, move.From, -holding.Length, holding.To);
                WorkingTableau.Move(holdingMove);
                SupplementaryMoves.Add(holdingMove);
            }

            // Add the primary move.
            WorkingTableau.UncheckedMove(new Move(move.From, move.FromRow, move.To));
            SupplementaryMoves.Add(move);

            if (undoHolding)
            {
                // Undo moves from the holding piles.
                for (int i = holdingSet.Count - 1; i >= 0; i--)
                {
                    HoldingInfo holding     = holdingSet[i];
                    Move        holdingMove = new Move(MoveType.Basic, MoveFlags.UndoHolding, holding.To, -holding.Length, move.To);
                    if (!WorkingTableau.TryMove(holdingMove))
                    {
                        break;
                    }
                    SupplementaryMoves.Add(holdingMove);
                }
            }
        }
示例#32
0
        public Game()
        {
            Seed             = -1;
            TraceStartFinish = false;
            TraceDeals       = false;
            TraceMoves       = false;
            ComplexMoves     = false;
            Diagnostics      = false;
            Instance         = -1;

            Shuffled = new Pile();
            Tableau  = new Tableau();

            Candidates        = new MoveList();
            SupplementaryList = new MoveList();
            RunFinder         = new RunFinder();
            FaceLists         = new PileList[(int)Face.King + 2];
            for (int i = 0; i < FaceLists.Length; i++)
            {
                FaceLists[i] = new PileList();
            }
            Coefficients = null;

            TableauInputOutput = new TableauInputOutput(Tableau);
            MoveProcessor      = new MoveProcessor(this);

            Variation     = Variation.Spider4;
            AlgorithmType = AlgorithmType.Study;
        }
示例#33
0
        public void PileMethod_GetRandomPiece()
        {
            Pile  myPile = new Pile();
            Piece prueba = myPile.GetRandomPiece();

            Assert.AreNotEqual(null, prueba);
        }
示例#34
0
 public static void PrintPiles(Pile[] piles)
 {
     foreach (Pile pile in piles)
     {
         Card topCard = pile.GetTopCard();
         System.Console.Write((topCard != null ? GetVisibleCardString(topCard) : "X") + "  ");
     }
 }
示例#35
0
 public Play(Pile fromPile, Card fromCard, Pile toPile)
 {
     _fromPile = fromPile;
     _fromPileCardIndex = fromPile.IndexOf(fromCard);
     _fromCard = fromCard;
     _toPile = toPile;
     Logger.Write(GenerateToString());
 }
示例#36
0
        public CardPanel(Func<CardButton> buttonGenerator, LayoutArgs args, Pile p = null)
        {
            BackColor = Color.Pink;
            layoutArgs = args;
            cardButtons = new List<CardButton>();
            this.buttonGenerator = buttonGenerator;

            p?.addObserver(this);
        }
示例#37
0
        public void NewPlayTest()
        {
            Pile reservePile = new Pile(PileType.Reserve);
            reservePile.Add(new Card(1));
            Pile buildPile = new Pile(PileType.Build);

            Play play = new Play(reservePile, buildPile);
            Assert.IsTrue(play.IsValid(), "Play " + play + " should be valid");
        }
示例#38
0
 public void FromJSON(JSONObject jsCard)
 {
     libId = (int)jsCard["id"];
     globalIdx = (int)jsCard["globalIdx"];
     health = (int)jsCard["health"];
     attack = (int)jsCard["attack"];
     actions = (int)jsCard["actions"];
     saced = (bool)jsCard["saced"];
     pos = (int)jsCard["position"];
     tap = (int)jsCard["tapped"];
     owner = (int)jsCard["owner"];
     pile = (Pile)(int)jsCard["pile"];
 }
示例#39
0
        public DraftPanel()
        {
            BackColor = Color.DodgerBlue;

            cards = new Pile(new Card[0]);
            choices = new CardPanel(() => new CardButton(new FML(clicked
                )), new LayoutArgs(false, false), cards);
            Controls.Add(choices);

            dealEm = new Button();
            dealEm.Click += (_, __) => dealm();
            Controls.Add(dealEm);
        }
示例#40
0
 public CardPanelControl(Pile p, Action<CardButton> f)
 {
     panel = new CardPanel(() =>
     {
         var b = new CardButton(new FML(clickedCallback, f));
         b.setHeight(150);
         return b;
     }, new LayoutArgs(false, false));
     panel.Size = new Size(300, 150);
     panel.BackColor = Color.Navy;
     p.addObserver(panel);
     window = GUI.showWindow(panel);
 }
        public IPile FindDestinationPile()
        {
            if (_pile == null)
            {
                throw new InvalidOperationException("You must first set the pile source via SetPileAsSource");
            }

            if (_dest == null)
            {
                var newPile = new Pile(_pile.IsWatchingFiles);

                foreach (var pile in _pile.FindAllPiles())
                {
                    // Get Urls (just copy over)
                    foreach (var uri in _pile.FindUrls(pile))
                    {
                        newPile.AddUrl(pile, uri.ToString());
                    }

                    // Get New Files
                    if (_combine)
                    {
                        // Only add the pile global file if the file actually has anything
                        if (_pile.FindFiles(pile).Any())
                        {
                            var filePath = Path.Combine(_compilationDirectory.FullName, pile + _compileExtension);
                            newPile.AddFile(pile, filePath);
                        }
                    }
                    else
                    {
                        // We have to add the count in this version to avoid clashes with names...
                        int count = 0;
                        foreach (var file in _pile.FindFiles(pile))
                        {
                            var dirPath = Path.Combine(_compilationDirectory.FullName, pile);
                            var filePath = Path.Combine(dirPath, Path.GetFileNameWithoutExtension(file.Name) + count + _compileExtension);

                            newPile.AddFile(pile, filePath);
                            count++;
                        }
                    }
                }

                _dest = newPile;
            }

            return _dest;
        }
 /// <summary>
 /// It adds a card to the discard pile or to the draw pile.
 /// </summary>
 /// <param name="pile"></param>
 /// <param name="card"></param>
 public static void AddCardToPile(Pile pile, Card card)
 {
     if (pile == Pile.Discard)
     {
         discardPile.AddCard(card);
         if (card.GetFaceValue() != FaceValue.Eight)
         {
             current = card;
         }
     }
     else
     {
         drawPile.AddCard(card);
     }
 }
示例#43
0
        public void PlayToIllegalPileTest()
        {
            Pile pile = new Pile(PileType.Reserve);
            int playedValue;
            Assert.IsFalse(pile.IsLegalPlay(new Card(1), pile, out playedValue));

            pile = new Pile(PileType.Draw);
            Assert.IsFalse(pile.IsLegalPlay(new Card(1), pile, out playedValue));

            pile = new Pile(PileType.Hand);
            Assert.IsFalse(pile.IsLegalPlay(new Card(1), pile, out playedValue));

            pile = new Pile(PileType.Reserve);
            Assert.IsFalse(pile.IsLegalPlay(new Card(1), pile, out playedValue));
        }
示例#44
0
        public void InvalidFromPileIndexTest()
        {
            Pile discardPile = new Pile(PileType.Discard);
            Pile hand = new Pile(PileType.Hand);
            Pile reservePile = new Pile(PileType.Reserve);
            Pile drawPile = new Pile(PileType.Draw);
            Pile buildPile = new Pile(PileType.Build);

            Card card = new Card(1);
            Play play = new Play(hand, card, buildPile);
            Assert.IsFalse(play.IsValid());

            hand.Add(card);
            play = new Play(hand, card, reservePile);
            Assert.IsFalse(play.IsValid());
        }
示例#45
0
        public void PlayValidityTest()
        {
            Pile discardPile = new Pile(PileType.Discard);
            Pile hand = new Pile(PileType.Hand);
            Pile reservePile = new Pile(PileType.Reserve);
            Pile drawPile = new Pile(PileType.Draw);
            Pile buildPile = new Pile(PileType.Build);

            Play play;

            Assert.IsTrue(Board.NumDiscardPiles == Board.NumDiscardPiles);
            for (int i = 0; i < Board.NumDiscardPiles; i++)
            {
                Card card = new Card(1);
                discardPile.Add(card);
                play = new Play(discardPile, buildPile);
                Assert.AreSame(card, play.PlayedCard, "Not expected PlayedCard");
                Assert.IsTrue(play.IsValid(), play.ToString());
            }

            Card handCard = new Card(1);
            hand.Add(handCard);
            play = new Play(hand, discardPile);
            Assert.IsTrue(play.ToString().Contains("->"));
            Assert.AreSame(handCard, play.PlayedCard, "Didn't play expected top hand card");
            Assert.IsTrue(play.IsValid(), play.ToString());

            Card reserveCard = new Card(1);
            reservePile.Add(reserveCard);
            play = new Play(reservePile, discardPile);
            Assert.AreSame(reserveCard, play.PlayedCard, "Didn't play expected top reserve card");
            Assert.IsFalse(play.IsValid(), play.ToString());

            Card buildCard = new Card(1);
            buildPile.Add(buildCard);
            play = new Play(buildPile, buildCard, discardPile);
            Assert.AreSame(buildCard, play.PlayedCard, "Didn't play expected top build card");
            Assert.IsFalse(play.IsValid(), play.ToString());

            Card drawCard = new Card(1);
            drawPile.Add(drawCard);
            play = new Play(drawPile, drawCard, hand);
            Assert.AreSame(drawCard, play.PlayedCard, "Didn't play expected draw card");
            Assert.IsTrue(play.IsValid(), string.Format("Draw->Hand should be valid: {0}", play));
        }
示例#46
0
        public IPile FindDestinationPile()
        {
            if (_pile == null)
            {
                throw new InvalidOperationException("You must first set the pile source via SetPileAsSource");
            }

            if (_dest == null)
            {
                var newPile = new Pile(_pile.IsWatchingFiles);

                foreach (var pile in _pile.FindAllPiles())
                {
                    // Get Urls (just copy over)
                    foreach (var uri in _pile.FindUrls(pile))
                    {
                        newPile.AddUrl(pile, uri.ToString());
                    }

                    // Get New Files
                    if (_combine)
                    {
                        var filePath = Path.Combine(_compilationDirectory.FullName, pile + _compileExtension);
                        newPile.AddFile(pile, filePath);
                    }
                    else
                    {
                        foreach (var file in _pile.FindFiles(pile))
                        {
                            var dirPath = Path.Combine(_compilationDirectory.FullName, pile);
                            var filePath = Path.Combine(dirPath, Path.GetFileNameWithoutExtension(file.Name) + _compileExtension);

                            newPile.AddFile(pile, filePath);
                        }
                    }
                }

                _dest = newPile;
            }

            return _dest;
        }
示例#47
0
    public void HMove(bool direction, Pile x)
    {
        if (!direction && (( x.Count() + x.offset) >= 4 || x.offset >= 1))
        {
            x.offset--;
            for(int i=0; i<x.Count(); i++)
            {
                cards[x.Get(i)].picture.transform.position = cards[x.Get(i)].picture.transform.position + new Vector3(-screenWidthUnit / 4.0f,0,0);
            }
        }

        if (direction && x.offset <= 0)
        {
            x.offset++;
            for(int i=0; i<x.Count(); i++)
            {
                cards[x.Get(i)].picture.transform.position = cards[x.Get(i)].picture.transform.position + new Vector3(screenWidthUnit / 4.0f,0,0);
            }
        }
    }
示例#48
0
        public static string ToAsciiString(Tableau tableau)
        {
            Pile discardRow = new Pile();
            for (int i = 0; i < tableau.DiscardPiles.Count; i++)
            {
                Pile discardPile = tableau.DiscardPiles[i];
                discardRow.Add(discardPile[discardPile.Count - 1]);
            }

            string s = "";

            s += Fence;
            s += tableau.Variation.ToAsciiString() + PrimarySeparator;
            s += ToAsciiString(discardRow) + PrimarySeparator;
            s += ToAsciiString(tableau.DownPiles) + PrimarySeparator;
            s += ToAsciiString(tableau.UpPiles) + PrimarySeparator;
            s += ToAsciiString(tableau.StockPile);
            s += Fence;

            return WrapString(s, 60);
        }
示例#49
0
        public static string ToPrettyString(Tableau tableau)
        {
            string s = Environment.NewLine;
            s += "   Spider";
            s += Environment.NewLine;
            s += "--------------------------------";
            s += Environment.NewLine;
            Pile discardRow = new Pile();
            for (int i = 0; i < tableau.DiscardPiles.Count; i++)
            {
                Pile discardPile = tableau.DiscardPiles[i];
                discardRow.Add(discardPile[discardPile.Count - 1]);
            }
            s += ToPrettyString(-1, discardRow);
            s += Environment.NewLine;
            s += ToPrettyString(tableau.DownPiles);
            s += Environment.NewLine;
            s += "    " + ColumnHeadings(tableau.NumberOfPiles);
            s += Environment.NewLine;
            s += ToPrettyString(tableau.UpPiles);
            s += Environment.NewLine;
            int rowIndex = 0;
            Pile row = new Pile();
            for (int index = tableau.StockPile.Count - 1; index >= 0; index--)
            {
                row.Add(tableau.StockPile[index]);
                if (row.Count == tableau.NumberOfPiles)
                {
                    s += ToPrettyString(rowIndex++, row);
                    row.Clear();
                }
            }
            if (row.Count != 0)
            {
                s += ToPrettyString(rowIndex, row);
            }

            return s;
        }
示例#50
0
        public Player(GameState g, LocationPlayer l)
        {
            gameState = g;
            side = l;

            hand = new Pile(new Location(LocationPile.HAND, l));
            graveyard = new Pile(new Location(LocationPile.GRAVEYARD, l));
            exile = new Pile(new Location(LocationPile.EXILE, l));
            field = new Pile(new Location(LocationPile.FIELD, l));
            deck = new Pile(new Location(LocationPile.DECK, l));

            piles = new Pile[5];
            piles[(int)LocationPile.DECK] = deck;
            piles[(int)LocationPile.EXILE] = exile;
            piles[(int)LocationPile.FIELD] = field;
            piles[(int)LocationPile.GRAVEYARD] = graveyard;
            piles[(int)LocationPile.HAND] = hand;

            curMana = new int[5];
            maxMana = new int[5];
            bonusMana = new int[5];

            health = 20;
        }
示例#51
0
 private static Pile GetPileFromAsciiString(string s)
 {
     int n = s.Length / 2;
     Pile pile = new Pile();
     for (int i = 0; i < n; i++)
     {
         pile.Add(Card.Parse(s.Substring(2 * i, 2)));
     }
     return pile;
 }
示例#52
0
 private static Pile[] GetPilesFromAsciiString(string s)
 {
     string[] rows = s.Split(SecondarySeparator);
     int n = rows.Length;
     Pile[] piles = new Pile[n];
     for (int i = 0; i < n; i++)
     {
         piles[i] = GetPileFromAsciiString(rows[i]);
     }
     return piles;
 }
示例#53
0
 private static string ToPrettyString(int row, Pile pile)
 {
     string s = "";
     if (row == -1)
     {
         s += "   ";
     }
     else
     {
         s += string.Format("{0,2} ", row);
     }
     for (int i = 0; i < pile.Count; i++)
     {
         if (i > 0)
         {
             s += " ";
         }
         s += (pile[i].IsEmpty) ? "  " : pile[i].ToString();
     }
     return s + Environment.NewLine;
 }
示例#54
0
 public void setObservers(Player h, Player v, Pile s)
 {
     gamePanel.setObservers(h, v, s);
 }
示例#55
0
 public CardPanelControl showCards(params Card[] cs)
 {
     Pile pl = new Pile(cs);
     CardPanelControl c = new CardPanelControl(pl, (s) => setFocusCard(s.Card));
     return c;
 }
示例#56
0
 public void PileTypeTest()
 {
     Pile pile = new Pile(PileType.Build);
     Assert.AreEqual(PileType.Build, pile.PileType);
 }
示例#57
0
 private static string ToPrettyString(IList<Pile> piles)
 {
     string s = "";
     int max = 0;
     for (int i = 0; i < piles.Count; i++)
     {
         max = Math.Max(max, piles[i].Count);
     }
     for (int j = 0; j < max; j++)
     {
         Pile row = new Pile();
         for (int i = 0; i < piles.Count; i++)
         {
             if (j < piles[i].Count)
             {
                 row.Add(piles[i][j]);
             }
             else
             {
                 row.Add(Card.Empty);
             }
         }
         s += ToPrettyString(j, row);
     }
     return s;
 }
示例#58
0
        public void PopEmptyPileTest()
        {
            Pile target = new Pile(PileType.Draw);

            target.Pop();
        }
示例#59
0
        public void FromAsciiString(string s)
        {
            // Parse string.
            StringBuilder b = new StringBuilder();
            int i;
            for (i = 0; i < s.Length && s[i] != Fence; i++)
            {
            }
            if (i == s.Length)
            {
                throw new Exception("missing opening fence");
            }
            for (i++; i < s.Length && s[i] != Fence; i++)
            {
                char c = s[i];
                if (!char.IsWhiteSpace(c))
                {
                    b.Append(s[i]);
                }
            }
            if (i == s.Length)
            {
                throw new Exception("missing closing fence");
            }
            s = b.ToString();
            string[] sections = s.Split(PrimarySeparator);
            if (sections.Length != 5)
            {
                throw new Exception("wrong number of sections");
            }

            // Parse sections.
            Variation variation = Variation.FromAsciiString(sections[0]);
            Pile discardCards = GetPileFromAsciiString(sections[1]);
            Pile[] downPiles = GetPilesFromAsciiString(sections[2]);
            Pile[] upPiles = GetPilesFromAsciiString(sections[3]);
            Pile stockPile = GetPileFromAsciiString(sections[4]);
            if (discardCards.Count > variation.NumberOfFoundations)
            {
                throw new Exception("too many discard piles");
            }
            if (downPiles.Length > variation.NumberOfPiles)
            {
                throw new Exception("wrong number of down piles");
            }
            if (upPiles.Length > variation.NumberOfPiles)
            {
                throw new Exception("wrong number of up piles");
            }
            if (stockPile.Count > variation.NumberOfStockCards)
            {
                throw new Exception("too many stock pile cards");
            }

            // Prepare game.
            Tableau.Variation = variation;
            Tableau.Clear();
            foreach (Card discardCard in discardCards)
            {
                Pile discardPile = new Pile();
                for (Face face = Face.King; face >= Face.Ace; face--)
                {
                    discardPile.Add(new Card(face, discardCard.Suit));
                }
                Tableau.DiscardPiles.Add(discardPile);
            }
            for (int column = 0; column < downPiles.Length; column++)
            {
                Tableau.DownPiles[column].Copy(downPiles[column]);
            }
            for (int column = 0; column < upPiles.Length; column++)
            {
                Tableau.UpPiles[column].Copy(upPiles[column]);
            }
            Tableau.StockPile.Copy(stockPile);
            Tableau.Refresh();
        }
示例#60
0
 private static string ToAsciiString(Pile row)
 {
     string s = "";
     for (int i = 0; i < row.Count; i++)
     {
         s += row[i].ToAsciiString();
     }
     return s;
 }