Skip to content

Instantly share code, notes, and snippets.

@ttreitlinger
Created March 8, 2011 17:17
Show Gist options
  • Save ttreitlinger/860579 to your computer and use it in GitHub Desktop.
Save ttreitlinger/860579 to your computer and use it in GitHub Desktop.
require 'player.rb'
require 'poker.rb'
class Casino
def initialize
@total_1 = {'John' => 0, 'Mary' => 0, 'Luke' => 0, 'Eimear' => 0}
@total_2 = {'John' => 0, 'Mary' => 0, 'Luke' => 0, 'Eimear' => 0}
@analyser_1 = Proc.new do |this_game|
results = this_game.results
# find out who won
winner_name = this_game.winner.name.to_s
@total_1[winner_name] = @total_1 [winner_name] + 1
end
@analyser_2 = Proc.new do |this_game|
results = this_game.results
# find out who won
winner_name = this_game.winner.name.to_s
@total_2[winner_name] = @total_2[winner_name] + 1
end
end
def watch_games
players = [Player.new("John"), Player.new("Mary"), Player.new("Luke"), Player.new("Eimear")]
poker_game = Poker.new 100, players
poker_game.add_observer @analyser_1
poker_game.add_observer @analyser_2
poker_game.play
# poker_game.print_results
puts " total_1: #{@total_1.to_s}"
puts " total_2: #{@total_2.to_s}"
end
end
casino = Casino.new
casino.watch_games
require 'player.rb'
require 'hand.rb'
require 'deck.rb'
require 'pile.rb'
require 'subject.rb'
# Class that represents a simple 1-card poker game.
class Poker
include Subject
attr_reader :results, :winner
# Create poker game of given number of rounds using players array.
def initialize no_of_rounds, players
super()
@players = players
@no_of_rounds = no_of_rounds
@results = Hash.new
@players.each do |player|
@results[player.name] = []
end
end
# Player the game of Poker.
def play
@pile = Pile.new
@no_of_rounds.times do
play_round
@pile.empty!
end
end
# Play an individual round.
def play_round
@deck = Deck.new
# deal each player a hand
@players.each do |player|
player.set_hand(@deck.deal_hand(1))
end
# Each player plays a card
@players.each do |player|
@pile.add(player.play)
end
winning_card = @pile.calculate_winner
@winner = nil
# find out who played the winning card
@players.each_with_index do |player, i|
if winning_card == player.last_card_played
@winner = player
end
end
@results[@winner.name] << winning_card.to_string
# notify that a round has ended
notify_observers
end
# Print the overall results of the series of rounds
def print_results
@results.each do |name, results|
puts "#{name} won #{@results[name].length} times with #{results}"
end
end
end
players = [Player.new("John"), Player.new("Mary"), Player.new("Luke"), Player.new("Eimear")]
poker_game = Poker.new 100, players
poker_game.play
poker_game.print_results
module Subject
def initialize
@observers = []
end
def add_observer observer
@observers << observer
end
def delete_observer observer
@observers.delete observer
end
# use PUSH model for notification
# Procs will require one argument (a reference to the subject)
def notify_observers
@observers.each do |observer|
observer.call(self)
end
end
end
@Mhyrnessa
Copy link

Oh, let me tell you about my new favorite online casino called Ducky Luck Casino! It's just such a fun and exciting experience every time I play there. First off, the website itself is super user-friendly and visually appealing with its bright colors and cute duck mascot. The game selection is incredible - they offer a wide variety of slots, table games, and even live dealer options for that extra thrill. What really sets Ducky Luck https://ducky-luck.casinologin.mobi/ apart from other online casinos is their generous bonuses and promotions. They have a fantastic welcome package for new players and ongoing special offers for loyal ones. Plus, their customer support team is top-notch - always responsive and helpful whenever I have any questions or concerns. And let's not forget about the fast and secure payment options they provide. Overall, if you're looking for a casual but enjoyable online gambling experience with exciting games, great bonuses, and excellent customer service, Ducky Luck Casino is definitely worth checking out!

@jasicarose75
Copy link

It is interesting

@W1zarDddD
Copy link

W1zarDddD commented Feb 13, 2024

In a casino, everyone can show their luck. It is important to remember that gambling can be dangerous if the hobby turns into a harmful addiction. I’m now reading about deposit hungary, I found information about no deposit casino bonus hungary for myself. The main rule is to spend a lot of time studying. This is what I'm doing now.

@Cloudsicker
Copy link

I recently went out to dinner with friends and we started talking about different hobbies. It turns out that many of us like to bet, but few of us know the good places. I shared with them a site where you can make different spins and bets - you can try here, and we even tried to play together. The site has many games, as well as a huge number of promotions and bonuses, from free spins to deposit bonuses. My friends liked it, and I was once again convinced that it is a great place to spend time together.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment