public with_a_deal_in_cards_action() { double_down_spec = MockRepository.GenerateStub <ICanDoubleDown>(); split_spec = MockRepository.GenerateStub <ICanSplit>(); insurance_spec = MockRepository.GenerateStub <ICanTakeInsurance>(); card_shoe = MockRepository.GenerateStub <ICardShoe>(); positions = MockRepository.GenerateStub <IPlayingPositions>(); player = MockRepository.GenerateStub <IPlayer>(); players_hand = MockRepository.GenerateStub <IPlayersHand>(); positions.Stub(x => x.players_active_hand).Return(players_hand); dealers_hand = MockRepository.GenerateStub <IDealersHand>(); positions.Stub(x => x.dealers_hand).Return(dealers_hand); hand = MockRepository.GenerateStub <IHand>(); hands = new List <IHand>() { hand }; positions.Stub(x => x.all_hands).Return(hands); hand_status_factory = MockRepository.GenerateStub <IHandStatusFactory>(); annouce_winner_action = MockRepository.GenerateStub <IAnnouceWinnerAction>(); SUT = new Domain.GamePlay.Model.Dealer.Actions.DealCardsIn(hand_status_factory, annouce_winner_action, double_down_spec, split_spec, insurance_spec); }
public void raise_illegal_move_if_action_cannot_be_made_on(IPlayingPositions playing_positions) { if (playing_positions.have_cards_been_dealt()) { throw new IllegalMoveException("Cannot stick hand as your turn has ended."); } }
protected void update_the_status_of_each_hand_in(IPlayingPositions playing_positions) { foreach (var hand in playing_positions.all_hands) { _hand_status_factory.set_status_for(hand); } }
private void check_if_player_can_take_insurance(IPlayingPositions playing_positions) { if (_insurance_spec.is_satisfied_by(playing_positions.dealers_hand)) { playing_positions.players_active_hand.mark_as_able_to_take_insurance(); } }
public void raise_illegal_move_if_action_cannot_be_made_on(IPlayingPositions playing_positions, IPlayer player) { if (!player.can_afford_to_bet(playing_positions.players_active_hand.wager)) { throw new IllegalMoveException(string.Format("Please cash in to take insurance. You need at least {0} dollars.", playing_positions.players_active_hand.wager.ToString())); } }
public with_a_deal_in_cards_action() { double_down_spec = MockRepository.GenerateStub<ICanDoubleDown>(); split_spec = MockRepository.GenerateStub<ICanSplit>(); insurance_spec = MockRepository.GenerateStub<ICanTakeInsurance>(); card_shoe = MockRepository.GenerateStub<ICardShoe>(); positions = MockRepository.GenerateStub<IPlayingPositions>(); player = MockRepository.GenerateStub<IPlayer>(); players_hand = MockRepository.GenerateStub<IPlayersHand>(); positions.Stub(x => x.players_active_hand).Return(players_hand); dealers_hand = MockRepository.GenerateStub<IDealersHand>(); positions.Stub(x => x.dealers_hand).Return(dealers_hand); hand = MockRepository.GenerateStub<IHand>(); hands = new List<IHand>() { hand }; positions.Stub(x => x.all_hands).Return(hands); hand_status_factory = MockRepository.GenerateStub<IHandStatusFactory>(); annouce_winner_action = MockRepository.GenerateStub<IAnnouceWinnerAction>(); SUT = new Domain.GamePlay.Model.Dealer.Actions.DealCardsIn(hand_status_factory, annouce_winner_action, double_down_spec, split_spec, insurance_spec); }
private void check_if_player_can_double_down(IPlayingPositions playing_positions) { if (_double_down_spec.is_satisfied_by(playing_positions.players_active_hand)) { playing_positions.players_active_hand.mark_as_able_to_double_down(); } }
public void raise_illegal_move_if_action_cannot_be_made_on(IPlayingPositions playing_positions, IPlayer player) { if (playing_positions.players_active_hand.turn_ended()) { throw new IllegalMoveException("Cannot stick hand as your turn has ended."); } }
public override void action_to_perform(IPlayingPositions playing_positions, ICardShoe card_shoe, IPlayer player) { raise_illegal_move_if_action_cannot_be_made_on(playing_positions, player); player.decrease_pot_by(playing_positions.players_active_hand.wager); playing_positions.players_active_hand.double_stake(); playing_positions.players_active_hand.add(card_shoe.take_card()); playing_positions.players_active_hand.change_state_to(HandStatus.stick); }
public on_a_blackjacktable() { card_shoe = MockRepository.GenerateStub<ICardShoe>(); playing_positions = MockRepository.GenerateStub<IPlayingPositions>(); table_status = MockRepository.GenerateStub<ITableStatus>(); player = MockRepository.GenerateStub<IPlayer>(); SUT = new BlackJackTable(player, card_shoe, playing_positions, table_status); }
public BlackJackTable(IPlayer player, ICardShoe card_shoe, IPlayingPositions playing_positions, ITableStatus table_status) { id = Guid.NewGuid(); this.player = player; _card_shoe = card_shoe; _playing_positions = playing_positions; change_status_to(table_status); _playing_positions.create_dealers_hand_for(this); }
public on_a_blackjacktable() { card_shoe = MockRepository.GenerateStub <ICardShoe>(); playing_positions = MockRepository.GenerateStub <IPlayingPositions>(); table_status = MockRepository.GenerateStub <ITableStatus>(); player = MockRepository.GenerateStub <IPlayer>(); SUT = new BlackJackTable(player, card_shoe, playing_positions, table_status); }
public void draw_cards_for_dealer_in(IPlayingPositions hands, ICardShoe card_shoe) { var dealers_hand = hands.dealers_hand; while (_can_hit_dealer.is_satisfied_by(dealers_hand)) { dealers_hand.add(card_shoe.take_card()); _hand_status_factory.set_status_for(dealers_hand); } }
public void perform_on(IPlayingPositions playing_positions, ICardShoe card_shoe, IPlayer player) { raise_illegal_move_if_action_cannot_be_made_on(playing_positions, player); player.decrease_pot_by(playing_positions.players_active_hand.wager.halved()); playing_positions.players_active_hand.mark_as_taken_insurance(); playing_positions.players_active_hand.remove_offer_to_take_insurance(); }
private void deal_two_cards_to_each_hand_in(IPlayingPositions hands, ICardShoe card_shoe) { int no_of_cards_to_deal = 2; while (no_of_cards_to_deal > 0) { hands.players_active_hand.add(card_shoe.take_card()); hands.dealers_hand.add(card_shoe.take_card()); no_of_cards_to_deal--; }; }
public override void action_to_perform(IPlayingPositions playing_positions, ICardShoe card_shoe, IPlayer player) { raise_illegal_move_if_action_cannot_be_made_on(playing_positions, player); player.decrease_pot_by(playing_positions.players_active_hand.wager); playing_positions.split_players_hand(); foreach (var hand in playing_positions.players_hands()) { hand.add(card_shoe.take_card()); } }
private void deal_two_cards_to_each_hand_in(IPlayingPositions hands, ICardShoe card_shoe) { int no_of_cards_to_deal = 2; while (no_of_cards_to_deal > 0) { hands.players_active_hand.add(card_shoe.take_card()); hands.dealers_hand.add(card_shoe.take_card()); no_of_cards_to_deal--; } ; }
public void perform_on(IPlayingPositions playing_positions, ICardShoe card_shoe, IPlayer player) { action_to_perform(playing_positions, card_shoe, player); update_hand_status(playing_positions); if (should_play_dealers_hand(playing_positions)) play_dealers_hand(playing_positions, card_shoe, player); playing_positions.clear_all_first_hand_decision_offers(); playing_positions.update_active_hand(); }
public void perform_on(IPlayingPositions playing_positions, ICardShoe card_shoe, IPlayer player) { action_to_perform(playing_positions, card_shoe, player); update_hand_status(playing_positions); if (should_play_dealers_hand(playing_positions)) { play_dealers_hand(playing_positions, card_shoe, player); } playing_positions.clear_all_first_hand_decision_offers(); playing_positions.update_active_hand(); }
public void perform_on(IPlayingPositions playing_positions, ICardShoe card_shoe, IPlayer player) { raise_illegal_move_if_action_cannot_be_made_on(playing_positions); deal_two_cards_to_each_hand_in(playing_positions, card_shoe); update_the_status_of_each_hand_in(playing_positions); if (playing_positions.player_has_blackjack()) _annouce_winner_action.determine_winner_from(playing_positions, player); check_if_player_can_double_down(playing_positions); check_if_player_can_split(playing_positions); check_if_player_can_take_insurance(playing_positions); playing_positions.mark_cards_as_dealt(); playing_positions.update_active_hand(); }
public void perform_on(IPlayingPositions playing_positions, ICardShoe card_shoe, IPlayer player) { raise_illegal_move_if_action_cannot_be_made_on(playing_positions); deal_two_cards_to_each_hand_in(playing_positions, card_shoe); update_the_status_of_each_hand_in(playing_positions); if (playing_positions.player_has_blackjack()) { _annouce_winner_action.determine_winner_from(playing_positions, player); } check_if_player_can_double_down(playing_positions); check_if_player_can_split(playing_positions); check_if_player_can_take_insurance(playing_positions); playing_positions.mark_cards_as_dealt(); playing_positions.update_active_hand(); }
public abstract void action_to_perform(IPlayingPositions playing_positions, ICardShoe card_shoe, IPlayer player);
private void check_if_player_can_double_down(IPlayingPositions playing_positions) { if (_double_down_spec.is_satisfied_by(playing_positions.players_active_hand)) playing_positions.players_active_hand.mark_as_able_to_double_down(); }
public override void action_to_perform(IPlayingPositions playing_positions, ICardShoe card_shoe, IPlayer player) { raise_illegal_move_if_action_cannot_be_made_on(playing_positions, player); playing_positions.players_active_hand.change_state_to(HandStatus.stick); }
public void raise_illegal_move_if_action_cannot_be_made_on(IPlayingPositions playing_positions, IPlayer player) { if (playing_positions.players_active_hand.turn_ended()) throw new IllegalMoveException("Cannot stick hand as your turn has ended."); }
public void raise_illegal_move_if_action_cannot_be_made_on(IPlayingPositions playing_positions, IPlayer player) { if (!player.can_afford_to_bet(playing_positions.players_active_hand.wager)) throw new IllegalMoveException(string.Format("Please cash in to Double Down. You need at least {0} dollars.", playing_positions.players_active_hand.wager.ToString())); }
public void determine_winner_from(IPlayingPositions playing_positions, IPlayer player) { var dealers_hand = playing_positions.dealers_hand; dealers_hand.show_card_in_hole(); foreach (var players_hand in playing_positions.players_hands()) { if (players_hand.has_status_of(HandStatus.blackjack) && dealers_hand.has_status_of(HandStatus.blackjack)) { players_hand.change_state_to(HandStatus.push); } else if (players_hand.has_status_of(HandStatus.blackjack)) { players_hand.change_state_to(HandStatus.won); } else if (dealers_hand.has_status_of(HandStatus.blackjack)) { players_hand.change_state_to(HandStatus.lost); } else if (players_hand.has_status_of(HandStatus.soft_blackjack) && dealers_hand.has_status_of(HandStatus.soft_blackjack)) { players_hand.change_state_to(HandStatus.push); } else if (players_hand.has_status_of(HandStatus.soft_blackjack)) { players_hand.change_state_to(HandStatus.won); } else if (dealers_hand.has_status_of(HandStatus.soft_blackjack)) { players_hand.change_state_to(HandStatus.lost); } else if (players_hand.has_status_of(HandStatus.bust) && dealers_hand.has_status_of(HandStatus.bust)) { players_hand.change_state_to(HandStatus.push); } else if (players_hand.has_status_of(HandStatus.bust)) { players_hand.change_state_to(HandStatus.lost); } else if (dealers_hand.has_status_of(HandStatus.bust)) { players_hand.change_state_to(HandStatus.won); } else if (players_hand.has_status_of(HandStatus.stick)) { var player_score = _hand_scorer.calculate_score_for(players_hand); var dealers_score = _hand_scorer.calculate_score_for(dealers_hand); if (player_score > dealers_score) { players_hand.change_state_to(HandStatus.won); } else if (player_score < dealers_score) { players_hand.change_state_to(HandStatus.lost); } else if (player_score == dealers_score) { players_hand.change_state_to(HandStatus.push); } } var chips_to_give_to_player = new Chips(0m); // Check if dealer has blackjack and that player took insurnace if (players_hand.has_taken_insurance() && dealers_hand.has_status_of(HandStatus.blackjack)) { var original_insurance_amount = players_hand.wager.halved(); var winnings = original_insurance_amount.mulitple_by_odds_of(2, 1); chips_to_give_to_player = chips_to_give_to_player.add(original_insurance_amount.add(winnings)); } if (players_hand.has_status_of(HandStatus.won)) { chips_to_give_to_player = chips_to_give_to_player.add(players_hand.wager.mulitple_by_odds_of(3, 2).add(players_hand.wager)); DomainEvents.raise(new HandResultEvent(string.Format("Hand {0} Won - you win {1}", players_hand.get_hand_letter(), chips_to_give_to_player.ToString()))); player.increase_pot_by(chips_to_give_to_player); } if (players_hand.has_status_of(HandStatus.push)) { chips_to_give_to_player = chips_to_give_to_player.add(players_hand.wager); player.increase_pot_by(chips_to_give_to_player); DomainEvents.raise(new HandResultEvent(string.Format("Hand {0} tied with the dealer, you get {1}", players_hand.get_hand_letter(), chips_to_give_to_player.ToString()))); } if (players_hand.has_status_of(HandStatus.lost)) { if (chips_to_give_to_player.contains_chips()) { player.increase_pot_by(chips_to_give_to_player); DomainEvents.raise(new HandResultEvent(string.Format("Hand {0} lost, but you won insurance bet of {1}", players_hand.get_hand_letter(), chips_to_give_to_player.ToString()))); } else { DomainEvents.raise(new HandResultEvent(string.Format("Hand {0} lost", players_hand.get_hand_letter()))); } } } }
public void update_hand_status(IPlayingPositions hands) { var players_active_hand = hands.players_active_hand; _hand_status_factory.set_status_for(players_active_hand); }
private void check_if_player_can_take_insurance(IPlayingPositions playing_positions) { if (_insurance_spec.is_satisfied_by(playing_positions.dealers_hand)) playing_positions.players_active_hand.mark_as_able_to_take_insurance(); }
public void raise_illegal_move_if_action_cannot_be_made_on(IPlayingPositions playing_positions) { if (playing_positions.have_cards_been_dealt()) throw new IllegalMoveException("Cannot stick hand as your turn has ended."); }
public void play_dealers_hand(IPlayingPositions hands, ICardShoe card_shoe, IPlayer player) { _play_dealers_hand.draw_cards_for_dealer_in(hands, card_shoe); _annouce_winner_action.determine_winner_from(hands, player); }
public bool can_perform_on(IPlayingPositions playing_positions) { return playing_positions.have_cards_been_dealt() == false; }
public override void action_to_perform(IPlayingPositions playing_positions, ICardShoe card_shoe, IPlayer player) { raise_illegal_move_if_action_cannot_be_made_on(playing_positions, player); playing_positions.players_active_hand.add(card_shoe.take_card()); }
private bool should_play_dealers_hand(IPlayingPositions hands) { return(hands.player_has_finished()); }
private bool should_play_dealers_hand(IPlayingPositions hands) { return hands.player_has_finished(); }
public bool can_perform_on(IPlayingPositions playing_positions) { return(playing_positions.have_cards_been_dealt() == false); }
protected void update_the_status_of_each_hand_in(IPlayingPositions playing_positions) { foreach (var hand in playing_positions.all_hands) _hand_status_factory.set_status_for(hand); }