-
Notifications
You must be signed in to change notification settings - Fork 0
/
gilbert.rb
64 lines (50 loc) · 1.65 KB
/
gilbert.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
54
55
56
57
58
59
60
61
62
63
64
require './lib/match'
require './lib/tennis_set'
require './lib/tennis_game'
require './lib/tennis_point'
require './lib/score_board'
require './lib/file_writer'
require 'rubygems'
require 'active_support/all'
require 'ruby-debug'
require 'yaml'
config = YAML.load_file("config/config.yml")
score_board = ScoreBoard.new
match = Match.new
match_score = {player_score: 0, opponent_score: 0, note: "0-0"}
set_number = 1
server = :player
while match_score[:note] != :player_won && match_score[:note] != :opponent_won do
set = TennisSet.new
set_score = {player_score: 0, opponent_score: 0, note: "0-0"}
set.set_number = set_number
game_number = 1
while set_score[:note] != :player_won && set_score[:note] != :opponent_won do
game = TennisGame.new
game_score = "0-0"
game.game_number = game_number
point_number = 1
while game_score != :server_won && game_score != :returner_won do
point = TennisPoint.new(config)
point.generate
point.player_serving = 1
point.current_score = game_score
point.point_number = point_number
point.player_serving = server == :player ? 1 : 2
game.tennis_points_attributes.push(point)
game_score = score_board.next_score(game_score, point.won_by)
point_number += 1
end
set.tennis_games_attributes.push(game)
set_score = game.next_score(set_score, game_score)
game_number += 1
server = server == :player ? :opponent : :player
end
set.team_1_set_score = set_score[:server_score]
set.team_2_set_score = set_score[:returner_score]
match.tennis_sets_attributes.push(set)
match_score = set.next_score(match_score, set_score)
set_number += 1
end
match.number_of_sets = set_number
FileWriter.create(match)