/* * Itterative are deals been played until one of the players reach sixty six */ public static Player PlaySixtySix(Player player1, Player player2) { var deck = CardsDeckUtil.InitializeDeck(); player1.HasWonLastDeal = true; CardsDeckUtil.ShuffleDeck(deck); //we first shuffle the deck do { player1.ResetPlayerAfterDeal(); player2.ResetPlayerAfterDeal(); if (player1.HasWonLastDeal) { var splitIndex = MovementUtil.GetDeckSplittingIndex(player2); CardsDeckUtil.SplitDeck(deck, splitIndex); //one of the players should split the deck player1.HasWonLastHand = true; player2.HasWonLastHand = false; PlayOneDeal(deck, player1, player2); } else if (player2.HasWonLastDeal) { var splitIndex = MovementUtil.GetDeckSplittingIndex(player1); CardsDeckUtil.SplitDeck(deck, splitIndex); //one of the players should split the deck player2.HasWonLastHand = true; player1.HasWonLastHand = false; PlayOneDeal(deck, player2, player1); } else { //Should not enter here PlayOneDeal(deck, player1, player2); } }while (player1.WinsCount < Constants.TOTAL_PLAYS_FOR_WIN && player2.WinsCount < Constants.TOTAL_PLAYS_FOR_WIN); if (player1.WinsCount >= Constants.TOTAL_PLAYS_FOR_WIN) { if (!player1.IsSilent) { Console.WriteLine("You has won!!! Result is: {0} to {1}.", player1.WinsCount, player2.WinsCount); } return(player1); } else { if (!player2.IsSilent) { Console.WriteLine("AI player has won!!! Result is: {0} to {1}.", player2.WinsCount, player1.WinsCount); } return(player2); } }
private bool HandleEndOfDeal(PlayerViewModel player, PlayerViewModel opponent, Deck deck) { if (player.HasWonLastHand && player.Score >= Constants.TOTAL_SCORE) { deck.IsEndOfGame = true; var enginePlayer = player.ToPlayer(); var engineOpponent = opponent.ToPlayer(); CardsDeckUtil.CollectCardsInDeck(deck, enginePlayer, engineOpponent); player.Cards = new ObservableCollection <CardViewModel>(); player.WinsCount += SixtySixUtil.GetNumberOfWins(opponent.ToPlayer()); player.Score = 0; opponent.Score = 0; this.TrumpCard = null; player.SelectedCard = null; opponent.SelectedCard = null; player.HasWonLastDeal = true; opponent.HasWonLastDeal = false; player.ThrownCards = new ObservableCollection <CardViewModel>(); opponent.Cards = new ObservableCollection <CardViewModel>(); opponent.ThrownCards = new ObservableCollection <CardViewModel>(); if (enginePlayer.HasWonLastDeal) { var splitIndex = AIMovementUtil.GetDeckSplittingIndex(); CardsDeckUtil.SplitDeck(deck, splitIndex); //one of the players should split the deck SixtySixUtil.DealCards(deck, engineOpponent, enginePlayer); } else if (engineOpponent.HasWonLastDeal) { //TODO Get User Input var splitIndex = 10; //MovementUtil.GetDeckSplittingIndex(engineOpпonent); CardsDeckUtil.SplitDeck(deck, splitIndex); //one of the players should split the deck SixtySixUtil.DealCards(deck, enginePlayer, engineOpponent); } player = PlayerViewModel.ConvertToPlayerViewModel(enginePlayer); opponent = PlayerViewModel.ConvertToPlayerViewModel(engineOpponent); player.Messages = "WIN"; opponent.Messages = "LOSE"; return(true); } return(false); }