-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgame.rb
64 lines (56 loc) · 2.3 KB
/
game.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
# Authors: Yuchen Wang, Gautam Agarwal
# Date: 7 February 2023
require './card'
require './deck'
# check if the three cards form a set
def check_set(card1, card2, card3)
color_set = (card1.color == card2.color) && (card2.color == card3.color) ||
(card1.color != card2.color) && (card2.color != card3.color) && (card1.color != card3.color)
shape_set = (card1.shape == card2.shape) && (card2.shape == card3.shape) ||
(card1.shape != card2.shape) && (card2.shape != card3.shape) && (card1.shape != card3.shape)
number_set = (card1.number == card2.number) && (card2.number == card3.number) ||
(card1.number != card2.number) && (card2.number != card3.number) && (card1.number != card3.number)
shading_set = (card1.shading == card2.shading) && (card2.shading == card3.shading) ||
(card1.shading != card2.shading) && (card2.shading != card3.shading) && (card1.shading != card3.shading)
color_set && shape_set && number_set && shading_set
end
# This function will determine if the set is already in set
def set_in_sets?(set, sets)
sets.each do |set_in_sets|
card1 = set[0]
card2 = set[1]
card3 = set[2]
return true if set_in_sets.include?(card1) && set_in_sets.include?(card2) && set_in_sets.include?(card3)
end
false
end
# # This function will determine if 3 cards on table can be made into a set
def table_contains_set?(table)
# TODO
table.each do |first_card|
table.each do |second_card|
table.each do |third_card|
if (first_card != second_card && first_card != third_card && second_card != third_card) && check_set(first_card, second_card, third_card)
return true
end
end
end
end
false
end
# Generates hint
def hint(table)
# Iterate through all possible combinations of 3 cards present in the table.
table.each do |first_card|
table.each do |second_card|
table.each do |third_card|
#check the tree cards make a set and are not same.
if (first_card != second_card && first_card != third_card && second_card != third_card) && check_set(first_card, second_card, third_card)
puts "Hint: #{first_card.output} - #{second_card.output} are the two cards of the set!"
return
end
end
end
end
puts "No more hints available."
end