Class: C4::Model::Game
- Inherits:
-
Object
- Object
- C4::Model::Game
- Defined in:
- lib/c4/model/game.rb
Constant Summary collapse
- P1 =
'o'
- P2 =
'x'
- ROWS =
6
- COLUMNS =
7
- WINNING_LENGTH =
4
Instance Attribute Summary collapse
-
#board ⇒ Object
readonly
Returns the value of attribute board.
-
#current_player_index ⇒ Object
readonly
Returns the value of attribute current_player_index.
-
#players ⇒ Object
readonly
Returns the value of attribute players.
Instance Method Summary collapse
- #current_player ⇒ Object
- #impasse? ⇒ Boolean
-
#initialize ⇒ Game
constructor
A new instance of Game.
- #play!(column) ⇒ Object
- #winner ⇒ Object
Constructor Details
Instance Attribute Details
#board ⇒ Object (readonly)
Returns the value of attribute board.
12 13 14 |
# File 'lib/c4/model/game.rb', line 12 def board @board end |
#current_player_index ⇒ Object (readonly)
Returns the value of attribute current_player_index.
12 13 14 |
# File 'lib/c4/model/game.rb', line 12 def current_player_index @current_player_index end |
#players ⇒ Object (readonly)
Returns the value of attribute players.
12 13 14 |
# File 'lib/c4/model/game.rb', line 12 def players @players end |
Instance Method Details
#current_player ⇒ Object
31 32 33 |
# File 'lib/c4/model/game.rb', line 31 def current_player players[current_player_index] end |
#impasse? ⇒ Boolean
35 36 37 |
# File 'lib/c4/model/game.rb', line 35 def impasse? board.full? end |
#play!(column) ⇒ Object
26 27 28 29 |
# File 'lib/c4/model/game.rb', line 26 def play!(column) board.put_stone!(column, current_player) toggle_player end |
#winner ⇒ Object
39 40 41 42 43 |
# File 'lib/c4/model/game.rb', line 39 def winner players.find do |player| player if valid_streak_exists?(player) end end |