protected override void AfterShuffle() { //this is what runs after the cards shuffle. DeckRegularDict <BlackjackCardInfo> newCol; if (_model == null) { throw new BasicBlankException("Model must be populated when running aftershuffle function"); } int x; int y; bool choicess = false; _oneNeeded = 0; _model.NeedsAceChoice = false; // defaults to false. must be proven true. _model.CanHitOrStay = false; // has to start that it can't hit or stay. //_model.DeckPile!.Visible = true; for (x = 1; x <= 2; x++) { newCol = new DeckRegularDict <BlackjackCardInfo>(); for (y = 1; y <= 2; y++) { newCol.Add(_model.DeckPile.DrawCard()); } if (x == 2) { _model.ComputerStack !.ClearBoard(newCol, ref _computerStartChoice); } else { _model.HumanStack !.ClearBoard(newCol, ref choicess); } } if (choicess == true) { _oneNeeded = 2; _model.NeedsAceChoice = true; } else { _model.HumanPoints = _model.HumanStack !.CalculateScore(_model); } }
public int Find15Combos(IDeckDict <CribbageCard> thisCol) { DeckRegularDict <CribbageCard> newCol = new DeckRegularDict <CribbageCard>(); newCol.AddRange(thisCol); newCol.Add(StartCard()); int firstNumber; int secondNumber; int output = 0; CribbageCard secondCard; int x = 0; newCol.ForEach(firstCard => { if (firstCard.Value >= EnumCardValueList.Ten) { firstNumber = 10; } else { firstNumber = (int)firstCard.Value; } var loopTo = newCol.Count - 1; // because 0 based for (int y = x + 1; y <= loopTo; y++) { secondCard = newCol[y]; if (secondCard.Value >= EnumCardValueList.Ten) { secondNumber = 10; } else { secondNumber = (int)secondCard.Value; } if (firstNumber + secondNumber == 15) { output++; } } x += 1; }); return(output); }
public void ClearBoard() { DeckRegularDict <T> tempList = new DeckRegularDict <T>(); int x = 0; foreach (var thisCard in CardList) { T tempCard = new T(); x++; tempCard.Populate(x); tempCard.Deck += 1000; //try this way. hopefully won't cause any other issues. tempCard.IsUnknown = true; tempCard.Visible = true; tempList.Add(tempCard); } OrderList.Clear(); CardList.ReplaceRange(tempList); // hopefully its that simple. Visible = true; // now it is visible. }
public DeckRegularDict <SolitaireCard> ListGivenCards(int pile) { var thisPile = PileList[pile]; DeckRegularDict <SolitaireCard> output = new DeckRegularDict <SolitaireCard>(); var thisTemp = thisPile.CardList.ToRegularDeckDict(); thisTemp.Reverse(); foreach (var thisCard in thisTemp) { if (thisCard.IsUnknown == false) { output.Add(thisCard); } else { break; } } output.Reverse(); //i think this is needed too. return(output); }
public int Move() { DeckRegularDict <SimpleDominoInfo> newList = new DeckRegularDict <SimpleDominoInfo>(); var possibleList = _gameBoard.GetVisibleList(); if (possibleList.Count == 0) { throw new BasicBlankException("There cannot be 0 visible items or the game would have been over."); } foreach (var thisDomino in possibleList) { if (_gameBoard.IsValidMove(thisDomino.Deck) == true) { newList.Add(thisDomino); } } if (newList.Count == 0) { return(0); } return(newList.GetRandomItem().Deck); }
public async Task RemoveEntireSetAsync(int index) { TileSet thisSet = _model !.MainSets1 !.GetIndividualSet(index); //looks like 0 based bug again try a different method that is not 0 based. var tempList = new DeckRegularDict <TileInfo>(); thisSet.HandList.ForEach(thisTile => { thisTile.WhatDraw = EnumDrawType.FromSet; SaveRoot !.TilesFromField.Add(thisTile.Deck); if (thisTile.IsJoker) { thisTile.Number = 20; } tempList.Add(thisTile); }); _model.MainSets1.RemoveSet(index - 1); //i think 0 based bug again. SingleInfo !.MainHandList.AddRange(tempList); if (SingleInfo.PlayerCategory == EnumPlayerCategory.Self) { SingleInfo.MainHandList.Sort(); } await ContinueTurnAsync(); }
private DeckRegularDict <MahjongSolitaireTileInfo> GetPreviousTiles() { BoardInfo firstBoard; BoardInfo secondBoard; DeckRegularDict <MahjongSolitaireTileInfo> output = new DeckRegularDict <MahjongSolitaireTileInfo>(); for (int x = 0; x < _saveRoot.PreviousList.Count; x++) { firstBoard = _saveRoot.PreviousList[x]; secondBoard = _saveRoot.BoardList[x]; if (firstBoard.TileList.Count != secondBoard.TileList.Count) { firstBoard.TileList.ForEach(tile => { if (secondBoard.TileList.ObjectExist(tile.Deck) == false) { tile.IsSelected = false; output.Add(tile); } }); } } return(output); }
protected override void AfterShuffleCards() { var firstKing = CardList.First(items => items.Value == EnumCardValueList.King); var thisList = new DeckRegularDict <SolitaireCard> { firstKing }; CardList !.RemoveSpecificItem(firstKing); var nextKing = CardList.First(items => items.Value == EnumCardValueList.King && items.Color == firstKing.Color); CardList.RemoveSpecificItem(nextKing); thisList.Add(nextKing); var nextList = CardList.Where(items => items.Value == EnumCardValueList.LowAce && items.Color != firstKing.Color).ToRegularDeckDict(); CardList.RemoveGivenList(nextList); thisList.AddRange(nextList); if (thisList.Count != 4) { throw new BasicBlankException("Must have 4 cards for foundation"); } AfterShuffle(thisList); CardList.Clear(); }
private void GenerateList() { _list.Clear(); int x, y, z, q = 0; for (x = 1; x <= ThisInfo !.HowManyDecks; x++) { for (y = 0; y < ThisInfo.SuitList.Count; y++) { for (z = ThisInfo.LowestNumber; z <= ThisInfo.HighestNumber; z++) { if (CanUse(ThisInfo.SuitList[y], z)) { q++; RegularSimpleCard card = new RegularSimpleCard(); card.Deck = q; card.Suit = ThisInfo.SuitList[y]; if (z == 1 || z == 14) { PopulateAceValue(); } else { Value = (EnumCardValueList)z; } card.Value = Value; card.Section = x; card.CardType = EnumCardTypeList.Regular; if (card.Suit == EnumSuitList.Clubs || card.Suit == EnumSuitList.Spades) { card.Color = EnumColorList.Black; } else { card.Color = EnumColorList.Red; } _list.Add(card); } } } } if (ThisInfo.UseJokers == true) { for (int r = 1; r <= ThisInfo.HowManyDecks; r++) { for (int p = 1; p <= 2; p++) { q++; RegularSimpleCard card = new RegularSimpleCard(); card.Value = EnumCardValueList.Joker; card.Deck = q; card.CardType = EnumCardTypeList.Joker; if (p == 1) { card.Color = EnumColorList.Black; } else { card.Color = EnumColorList.Red; } card.Section = r; _list.Add(card); } } EnumColorList last = EnumColorList.Red; int s = ThisInfo.HowManyDecks; for (int i = 0; i < ThisInfo.GetExtraJokers; i++) { q++; if (last == EnumColorList.Red) { last = EnumColorList.Black; } else { last = EnumColorList.Red; } s++; if (s > ThisInfo.HowManyDecks) { s = 1; } RegularSimpleCard card = new RegularSimpleCard(); card.Value = EnumCardValueList.Joker; card.Deck = q; card.CardType = EnumCardTypeList.Joker; card.Section = s; card.Color = last; _list.Add(card); } } }
public DeckRegularDict <MexicanDomino> GetTrainList(DeckObservableDict <MexicanDomino> piecesCollection, int givenNumber) { DeckRegularDict <MexicanDomino> output; Dictionary <int, MexicanDomino> matchingPieces = new Dictionary <int, MexicanDomino>(); List <int> Positions = new List <int>(); DeckObservableDict <MexicanDomino> TempList = new DeckObservableDict <MexicanDomino>(); foreach (var currentPiece in piecesCollection) { TempList.Add(currentPiece); } bool anyPieceMatch = false; int count = 1; DateTime newTime; newTime = DateTime.Now.AddSeconds(5); foreach (var currentPiece in piecesCollection) { if ((currentPiece.CurrentFirst == givenNumber) | (currentPiece.CurrentSecond == givenNumber)) { MexicanDomino newPiece = new MexicanDomino(); newPiece.CurrentFirst = currentPiece.CurrentFirst; newPiece.CurrentSecond = currentPiece.CurrentSecond; newPiece.Deck = currentPiece.Deck; newPiece.CurrentFirst = currentPiece.CurrentFirst; newPiece.Keeps = currentPiece.Keeps; newPiece.CurrentSecond = currentPiece.CurrentSecond; newPiece.Status = currentPiece.Status; newPiece.Train = currentPiece.Train; Positions.Add(count); matchingPieces.Add(count, newPiece); anyPieceMatch = true; } count += 1; } if (anyPieceMatch == false) { return(new DeckRegularDict <MexicanDomino>()); } CustomBasicList <CustomBasicList <MexicanDomino> > allTrains = new CustomBasicList <CustomBasicList <MexicanDomino> >(); count = 1; // Searching for Trains foreach (var currentPiece in matchingPieces.Values) { // Searching for Train CustomBasicList <MexicanDomino> train = new CustomBasicList <MexicanDomino>(); if (currentPiece.CurrentFirst != givenNumber) { ReplacePieceFirstSecond(currentPiece); } train.Add(currentPiece); // All Pieces Clone with Removing the first matched var allPieces = CloneList(TempList); allPieces.RemoveAt(Positions[count - 1] - 1); // 0 based int i = 1; MexicanDomino trainEnd = currentPiece; CustomBasicList <CustomBasicList <MexicanDomino> > trainPieceList = new CustomBasicList <CustomBasicList <MexicanDomino> >(); CustomBasicList <CustomBasicList <MexicanDomino> > trainSecondList = new CustomBasicList <CustomBasicList <MexicanDomino> >(); CustomBasicList <MexicanDomino> trainDominoList = new CustomBasicList <MexicanDomino>(); CustomBasicList <int> trainIndexList = new CustomBasicList <int>(); while (i <= allPieces.Count) { MexicanDomino piece; piece = allPieces[i - 1]; // because 0 based if (piece.CurrentFirst == trainEnd.CurrentSecond) { trainPieceList.Add(CloneList(allPieces)); trainSecondList.Add(CloneList(train)); trainDominoList.Add(CloneDominoPiece(trainEnd)); train.Add(piece); allPieces.RemoveAt(i - 1); // 0 based trainEnd = piece; i = 1; } else if (piece.CurrentSecond == trainEnd.CurrentSecond) { trainPieceList.Add(CloneList(allPieces)); trainSecondList.Add(CloneList(train)); trainDominoList.Add(CloneDominoPiece(trainEnd)); trainIndexList.Add(i + 1); ReplacePieceFirstSecond(piece); train.Add(piece); allPieces.RemoveAt(i - 1); // 0 based trainEnd = piece; i = 1; } else { if (i < allPieces.Count) { i += 1; } else if ((trainPieceList.Count > 0) & (i >= allPieces.Count) & trainIndexList.Count > 0) { allTrains.Add(CloneList(train)); if (allPieces.Count == 0) { throw new BasicBlankException("allpieces has nothing left"); } allPieces = trainPieceList.First(); trainPieceList.RemoveAt(0); if (trainSecondList.Count == 0) { throw new BasicBlankException("trainsecondlist has nothing left"); } train = trainSecondList.First(); trainSecondList.RemoveAt(0); if (trainDominoList.Count == 0) { throw new BasicBlankException("traindominolist has nothing left"); } trainEnd = trainDominoList.First(); trainDominoList.RemoveAt(0); if (trainIndexList.Count == 0) { i++; } else { i = trainIndexList.First(); trainIndexList.RemoveAt(0); } } else { // Saves the current list allTrains.Add(CloneList(train)); // No more List possible break; } if (DateTime.Now > newTime) { // MsgBox("taking too long") break; } } } if (train.Count > 0) { allTrains.Add(CloneList(train)); } if (DateTime.Now > newTime) { break; } count += 1; } int j = 1; int piecesCount = 0; bool multiplePiecesCount = false; CustomBasicList <int> piecesPositions = new CustomBasicList <int>(); while (j <= allTrains.Count) { CustomBasicList <MexicanDomino> currentTrain; currentTrain = allTrains[j - 1]; // 0 based if (currentTrain.Count > piecesCount) { piecesCount = currentTrain.Count; multiplePiecesCount = false; piecesPositions.Clear(); piecesPositions.Add(j); } else if (currentTrain.Count == piecesCount) { multiplePiecesCount = true; piecesPositions.Add(j); } j += 1; } CustomBasicList <MexicanDomino> tempCol; if (!multiplePiecesCount) { tempCol = allTrains[piecesPositions[0] - 1]; // try 0 based here output = new DeckRegularDict <MexicanDomino>(); MexicanDomino newDomino; foreach (var thisDomino in tempCol) { newDomino = piecesCollection.GetSpecificItem(thisDomino.Deck); newDomino.CurrentFirst = thisDomino.CurrentFirst; newDomino.CurrentSecond = thisDomino.CurrentSecond; piecesCollection.RemoveObjectByDeck(newDomino.Deck); // try this way output.Add(newDomino); } return(output); } else { int points; int bestPoints = 0; int bestPosition = 0; var loopTo = piecesPositions.Count - 1; for (points = 0; points <= loopTo; points++) { int totalPoints = 0; CustomBasicList <MexicanDomino> currentTrain = allTrains[piecesPositions[points] - 1]; // 0 based foreach (var piece in currentTrain) { totalPoints += piece.Points; } if (totalPoints > bestPoints) { bestPosition = points; } } tempCol = allTrains[piecesPositions[bestPosition] - 1]; // 0 based output = new DeckRegularDict <MexicanDomino>(); MexicanDomino NewDomino; foreach (var ThisDomino in tempCol) { NewDomino = piecesCollection.GetSpecificItem(ThisDomino.Deck); NewDomino.CurrentFirst = ThisDomino.CurrentFirst; NewDomino.CurrentSecond = ThisDomino.CurrentSecond; piecesCollection.RemoveSpecificItem(NewDomino); // try this way output.Add(NewDomino); } return(output); } }
public void GetUnknownList() //run only once. { _listUnknownCards.Clear(); PileList.ForEach(thisPile => { thisPile.CardList.ForConditionalItems(items => items.IsUnknown == true, thisCard => _listUnknownCards.Add(thisCard)); }); }
private int WhoWonTrick(DeckObservableDict <HorseshoeCardGameCardInformation> thisCol) { if (thisCol.Count != 4) { throw new BasicBlankException("Must have 4 cards for the trick list to see who won"); } var thisCard = thisCol.First(); int begins = thisCard.Player; EnumCardValueList nums = thisCard.Value; if (thisCol.All(Items => Items.Value == nums)) { return(begins); } DeckRegularDict <HorseshoeCardGameCardInformation> playerStarted = new DeckRegularDict <HorseshoeCardGameCardInformation>(); DeckRegularDict <HorseshoeCardGameCardInformation> otherPlayer = new DeckRegularDict <HorseshoeCardGameCardInformation>(); playerStarted.Add(thisCol.First()); playerStarted.Add(thisCol.Last()); otherPlayer.Add(thisCol[1]); otherPlayer.Add(thisCol[2]); HorseshoeCardGameCardInformation firstCard = playerStarted.First(); HorseshoeCardGameCardInformation secondCard = playerStarted.Last(); EnumSuitList whichSuit = firstCard.Suit; EnumCardValueList pairAmount; EnumCardValueList highestSuitNumber = EnumCardValueList.None; int possibleWinPlayer = 0; if (firstCard.Value == secondCard.Value) { pairAmount = firstCard.Value; } else { pairAmount = EnumCardValueList.None; var card = thisCol.Where(x => x.Suit == whichSuit).OrderByDescending(x => x.Value).Take(1).Single(); highestSuitNumber = card.Value; possibleWinPlayer = card.Player; //if (secondCard.Value > firstCard.Value && secondCard.Suit == firstCard.Suit) // highestSuitNumber = secondCard.Value; //else if (secondCard.Suit == firstCard.Suit) // highestSuitNumber = firstCard.Value; } firstCard = otherPlayer.First(); secondCard = otherPlayer.Last(); if (firstCard.Value != secondCard.Value && pairAmount > 0) { return(begins); } if (firstCard.Value == secondCard.Value) { if (firstCard.Value > pairAmount) { if (begins == 1) { return(2); } return(1); } } if (pairAmount > 0) { return(begins); } if (possibleWinPlayer == 0) { throw new BasicBlankException("Sombody had to win it"); } return(possibleWinPlayer); //if (firstCard.Suit == whichSuit) //{ // if (firstCard.Value > highestSuitNumber) // { // if (begins == 1) // return 2; // return 1; // } //} //if (secondCard.Suit == whichSuit) //{ // if (secondCard.Value > highestSuitNumber) // { // if (begins == 1) // return 2; // return 1; // } //} //return begins; }