Class: Linotype::Simulator

Inherits:
Object
  • Object
show all
Defined in:
lib/linotype/simulator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(strategy_one, strategy_two) ⇒ Simulator

Returns a new instance of Simulator.



6
7
8
9
# File 'lib/linotype/simulator.rb', line 6

def initialize(strategy_one, strategy_two)
  self.player_one = Player.new(strategy: strategy_one)
  self.player_two = Player.new(strategy: strategy_two)
end

Instance Attribute Details

#gameObject

Returns the value of attribute game.



4
5
6
# File 'lib/linotype/simulator.rb', line 4

def game
  @game
end

#player_oneObject

Returns the value of attribute player_one.



4
5
6
# File 'lib/linotype/simulator.rb', line 4

def player_one
  @player_one
end

#player_twoObject

Returns the value of attribute player_two.



4
5
6
# File 'lib/linotype/simulator.rb', line 4

def player_two
  @player_two
end

Instance Method Details

#simulate!Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/linotype/simulator.rb', line 11

def simulate!
  self.game = Game.new(player_one: player_one, player_two: player_two)
  puts "Let's start the simulator"
  while !game.over?
    if best_next_play = game.best_next_play        
      puts "Player #{game.player_number(game.current_player)} will play: #{best_next_play.word}"
      game.play(*best_next_play.to_hash[:coordinates])
    else
      puts "Player #{game.player_number(game.current_player)} will pass."
      game.play
    end
    game.print_board
    game.print_scores
    puts "---------------"
  end
  puts "Game Over!"
end