-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIndependent.py
113 lines (92 loc) · 2.68 KB
/
Independent.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import json
import random
from datetime import datetime
ToTile = dict({
"c": 0,
"d": 1,
"b": 2,
"o": 3, # 中發白、風
"f": 4, # 花
})
def CheckInDependent(info):
turn = info['Actions'][-1]['Turn']
pid = info['Id']
action = info['CurAction']
card = info['Actions'][-1]['Card']
hand = info['Hand']
safe_before = info['SafeBefore']
actions = info['Actions']
deadcards = info['DeadCards']
# convert card(string) to tile
if action == "Throw":
if info['OtherTing'] or turn >= 36 :
if not CheckIsSafe(card, deadcards):
action = "Dangerous"
else:
if card in safe_before:
action = "Follow"
# for i := 1; i < 3; i++ {
# if otherPlayer := room.Players[(currentIdx+4-i)%4]; otherPlayer.CheckEat(card) {
# otherPlayer.Hand.Add(card)
# if otherPlayer.StepsToHu > otherPlayer.Hand.CountStepsToHu() {
# room.BroadcastCoversation(otherPlayer.ID, "WantEat")
# }
# otherPlayer.Hand.Sub(card)
# }
# }
# 別人前兩輪不是丟字牌
elif info['ThrowTimes'] < 1 and ToTile[card[0]] != 3:
action = "ThrowGoodFirst"
pid = (pid + random.randint(0, 3) + 1) % 4
elif action == "Draw":
if ToTile[card[0]] == 4:
# if flowers := room.Players[currentIdx].Flowers.Count(); flowers >= 6:
# if flowers == CountDeadCard(card):
# action = "LotsOfFlowers"
print(4)
elif card in [action['Card'] for action in actions if action['Action'] == "Throw"]:
action = "ThrowBefore"
elif info['OtherTing'] or turn >= 36:
if CheckIsUseless(card, deadcards):
if info['IsTing'] or info['StepsToHu'] <= 2:
action = "Useless"
else:
action = "Safe"
elif action == "Ting" and turn < 20:
action += "Fast"
elif action == "Pon" or action == "Eat" or action == "CantEat":
if CheckLastNeed(card, deadcards, hand):
action += "LastCard"
# if action == "Dangerous" or action == "Follow" or action == "Ting" or action == "TingFast" or action == "Ongon" or action == "KeepWin":
# action = "Other" + action
return pid, action
def CheckIsUseless(card, deadcards):
IsUseless = False
amount = CountCard(card, deadcards)
if amount >= 2:
IsUseless = True
return IsUseless
def CheckLastNeed(card, deadcards, hand):
IsLast = False
amount = CountCard(card, deadcards)
# check pid's hand card
amount += CountCard(card, hand)
if amount == 4:
IsLast = True
return IsLast
def CheckIsSafe(card, deadcards):
amount = CountCard(card, deadcards)
if amount <= 2:
return False
elif amount >= 3:
return True
return True
def CheckKeepWin(keepwin):
if keepwin:
return True
else:
return False
def CountCard(card, cards):
#convert card(string) to tile
amount = cards[ToTile[card[0]]] >> (int(card[1]) * 3) & 7
return amount