-
Notifications
You must be signed in to change notification settings - Fork 1
/
review.rb
76 lines (62 loc) · 2.72 KB
/
review.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
進捗
①テストコードをパスした
変更箇所
①カードのsuitを定数で扱う
②card_score_judgeの箇所の条件分岐をメソッド内部で行う
7/25 質問箇所
ver 1
上手くいった
def result_judge_by_score
player_cards_score = player_hand.cards_orderd_by_score.map{|card| card.score}.to_enum
cpu_cards_score = cpu_hand.cards_orderd_by_score.map{|card| card.score}.to_enum
player_hand.cards.length.times do
a = player_cards_score.next
b = cpu_cards_score.next
return result_in_player_win if a > b
return result_in_player_lose if a < b
end
return result_in_draw
end
ver2
Failure/Error: expect(judge.player_winning[:result]).to eq GameResult::Draw
NoMethodError:
undefined method [] for nil:NilClass
def result_judge_by_score
player_cards_score = player_hand.cards_orderd_by_score.map{|card| card.score}.to_enum
cpu_cards_score = cpu_hand.cards_orderd_by_score.map{|card| card.score}.to_enum
player_hand.cards.length.times do
begin
a = player_cards_score.next
b = cpu_cards_score.next
return result_in_player_win if a > b
return result_in_player_lose if a < b
rescue StopIteration
return result_in_draw
end
end
end
ver3
望んだ結果にならない
1) ThreeCardPorkerJudge 引き分けの場合、手札の強さで勝敗を判定 スリーカード、ハイカード、フラッシュの場合の判定 Cpuの1番強いカードとプレイヤーの1番強いカードが同じ場合 プレイヤーの2番目に強いカードがCpuよりも強い場合 プレイヤーの勝利になる
Failure/Error: expect(judge.player_winning[:result]).to eq GameResult::Win
expected: 1
got: 0
(compared using ==)
# ./spec/three_card_ver/three_card_porker_judge_spec.rb:170:in `block (6 levels) in <top (required)>'
2) ThreeCardPorkerJudge 引き分けの場合、手札の強さで勝敗を判定 スリーカード、ハイカード、フラッシュの場合の判定 Cpuの1番強いカードとプレイヤーの1番強いカードが同じ場合 プレイヤーの2番目に強いカードがCpuよりも強い場合 Cpuの負けになる
Failure/Error: expect(judge.cpu_winning[:result]).to eq GameResult::Lose
expected: -1
got: 0
def result_judge_by_score
player_cards_score = player_hand.cards_orderd_by_score.map{|card| card.score}.to_enum
cpu_cards_score = cpu_hand.cards_orderd_by_score.map{|card| card.score}.to_enum
begin
loop do
return result_in_player_win if player_cards_score.next > cpu_cards_score.next
return result_in_player_lose if player_cards_score.next < cpu_cards_score.next
end
rescue StopIteration
return result_in_draw
end
end
end