-
Notifications
You must be signed in to change notification settings - Fork 0
/
match.rb
53 lines (46 loc) · 1005 Bytes
/
match.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require_relative "match_state"
class Match
attr_reader :max_game_count
%i[
current_game_nr
game_finished?
game_winner_side
games
inspect
match_finished?
p1_game_score
p2_game_score
side_having_service
waiting_for_final_game_switching_of_sides?
winner
winner_side
].each do |method|
define_method method do
@match_state.public_send(method)
end
end
def initialize(side_having_first_service:, max_game_count: 3)
@side_having_first_service = side_having_first_service
@max_game_count = max_game_count
@history = []
set_game_state
end
def handle_input(c)
@history.push(c)
set_game_state
end
def undo
@history.pop
set_game_state
end
def set_game_state
@match_state = MatchState.new(
@history,
side_having_first_service: @side_having_first_service,
max_game_count: max_game_count
)
end
def score_for_side(side)
@match_state.score_for_side(side)
end
end