-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalMain.py
93 lines (78 loc) · 3.21 KB
/
CalMain.py
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
import pandas as pd
from sklearn.tree import DecisionTreeClassifier
import openpyxl
import numpy
Player_Value = []
Player_Name = []
class Calculation:
def __init__(self, value_dic):
self.value_dic = value_dic
def main_cal(self):
# for each individual players
for init_value in self.value_dic:
# for each card of individual player
temp_list = self.value_dic[init_value]
# for number of first, second and third card
one_num_card = temp_list["First"][2]
two_num_card = temp_list["Second"][2]
three_num_card = temp_list["Third"][2]
# sorting the number
num = (one_num_card, two_num_card, three_num_card)
num_sorted = sorted(num)
num1 = num_sorted[0]
num2 = num_sorted[1]
num3 = num_sorted[2]
# for shape of first, second and third card
color1 = temp_list["First"][1]
color2 = temp_list["Second"][1]
color3 = temp_list["Third"][1]
if color1 == color2 == color3:
color_value = 1
else:
color_value = 0
# read file
read_file = pd.read_excel(r'NumberRule.xlsx')
# ML to predict
dataset_cond = read_file.drop(columns=['priority'])
output_dataset = read_file['priority']
# using tree
mod_tree = DecisionTreeClassifier()
# form above for prediction using tree for number value
mod_tree.fit(dataset_cond.values, output_dataset)
# prediction with given data
prediction_result = mod_tree.predict([[num1, num2, num3, color_value]])
# prediction based on previous data
Player_Value.append(prediction_result[0])
# getting the key
for key in self.value_dic:
Player_Name.append(key)
# making the dict from two lists
result_dict = dict(zip(Player_Name, Player_Value))
from_winner = self.winner(result_dict)
return from_winner
def winner(self, res_dict):
# sorting the dict according to its value
result = dict(sorted(res_dict.items(), key=lambda item: item[1]))
# for the result
card_value = []
players_card = []
for i, val in enumerate(result):
if 1 <= result[val] <= 13:
players_card.append(self.value_dic[val])
card_value.append('Trail')
elif 14 <= result[val] <= 25:
players_card.append(self.value_dic[val])
card_value.append('Pure Sequence')
elif 26 <= result[val] <= 37:
players_card.append(self.value_dic[val])
card_value.append('Sequence')
elif 38 <= result[val] <= 311:
players_card.append(self.value_dic[val])
card_value.append('Color')
elif 312 <= result[val] <= 467:
players_card.append(self.value_dic[val])
card_value.append('Double')
else:
players_card.append(self.value_dic[val])
card_value.append('Normal Card')
return result, card_value, players_card