-
Notifications
You must be signed in to change notification settings - Fork 0
/
about_extra_credit.rb
130 lines (115 loc) · 2.39 KB
/
about_extra_credit.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# EXTRA CREDIT:
#
# Create a program that will play the Greed Game.
# Rules for the game are in GREED_RULES.TXT.
#
# You already have a DiceSet class and score function you can use.
# Write a player class and a Game class to complete the project. This
# is a free form assignment, so approach it however you desire.
class DiceSet
attr :values
def initialize
@values = []
number = 5
while number > 0 do
number -= 1
@values.push(1 + rand(6))
end
end
end
class Score
def calc(dice)
#asegurando que tirada tenga algun valor
if dice.length == 0
return 0
end
one = 0
two = 0
three = 0
four = 0
five = 0
six = 0
result = 0
#mirando las tiradas
dice.each do |value|
if value == 1
one += 1
end
if value == 2
two += 1
end
if value == 3
three += 1
end
if value == 4
four += 1
end
if value == 5
five += 1
end
if value == 6
six += 1
end
end
#generando resultado
if one == 1
result += 100
end
if one == 2
result += 200
end
if one == 3
result += 1000
end
if one == 4
result += 1100
end
if one == 5
result += 1200
end
if two == 3
result += 200
end
if three == 3
result += 300
end
if four == 3
result += 400
end
if five == 1
result += 50
end
if five == 2
result += 100
end
if five == 3
result += 500
end
if five == 4
result += 550
end
if five == 5
result += 600
end
if six == 3
result += 600
end
# respuesta
result
end
end
player1 = DiceSet.new
tirada1 = Score.new
player2 = DiceSet.new
tirada2 = Score.new
player3 = DiceSet.new
tirada3 = Score.new
player4 = DiceSet.new
tirada4 = Score.new
player5 = DiceSet.new
tirada5 = Score.new
p "Jugador 1 - Tiradas : #{player1.values.map { |i| "'" + i.to_s + "'" }.join(",")}, puntuacion #{tirada1.calc(player1.values)}"
p "Jugador 2 - Tiradas : #{player2.values.map { |i| "'" + i.to_s + "'" }.join(",")}, puntuacion #{tirada1.calc(player2.values)}"
p "Jugador 3 - Tiradas : #{player3.values.map { |i| "'" + i.to_s + "'" }.join(",")}, puntuacion #{tirada1.calc(player3.values)}"
p "Jugador 4 - Tiradas : #{player4.values.map { |i| "'" + i.to_s + "'" }.join(",")}, puntuacion #{tirada1.calc(player4.values)}"
p "Jugador 5 - Tiradas : #{player5.values.map { |i| "'" + i.to_s + "'" }.join(",")}, puntuacion #{tirada1.calc(player5.values)}"