35 lines
842 B
Crystal
35 lines
842 B
Crystal
require "./ai"
|
|
require "./rules_set"
|
|
require "./game_history"
|
|
require "./round"
|
|
|
|
module GameOfGame
|
|
|
|
class Game
|
|
@players : Array(Ai)
|
|
@rules : RulesSet
|
|
getter rounds : GameHistory
|
|
@verbose : Bool = false
|
|
|
|
def initialize(@players, @rules, @verbose = false)
|
|
@rounds = GameHistory.new(rules: @rules)
|
|
end
|
|
|
|
def play
|
|
round = Round.new(previous: @rounds.last_round)
|
|
@players.each do |player|
|
|
player_bet = player.bet(@rounds)
|
|
puts "#{player.name} bets #{player_bet}" if @verbose
|
|
round.bet(player, player_bet)
|
|
end
|
|
@players.each do |player|
|
|
player_score = @rules.examine(round, player)
|
|
puts "#{player.name} scores #{player_score}" if @verbose
|
|
round.score(player, player_score)
|
|
end
|
|
@rounds << round
|
|
end
|
|
end
|
|
|
|
end
|