-
Notifications
You must be signed in to change notification settings - Fork 3
/
playfield.py
206 lines (171 loc) · 4.85 KB
/
playfield.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import random as rand
import card_util as cu
# Index values for player 1 and 2.
P1 = 0
P2 = 1
class Playfield:
"""Class to hold variables that define a playfield"""
# Check the action stack
# Action stack is stored as
AS = []
# Current stage settings
# Phase count starts at 0
CUR_PHASE = 0
# Global variable to check if the user has already
# summoned in which round.
PREV_NORM_SUMMON = -1
# List of phase names for reference.
# Check the number of rounds played
# Always increases regardless of the player in play
# So always increases round count as a result.
ROUND_CNT = 0
# Life points
LP = [
8000, 8000
]
# Each entry has two for each side of the field.
FIELD = [
[[],[],[],[],[]],
[[],[],[],[],[]]
]
# Trap contains non-pendulum.
SPELL = [
[[] ,[] ,[]],
[[], [], []]
]
PEND = [
[[], []],
[[], []]
]
GRAV = [
[], []
]
BAN = [
[], []
]
DECK = [
[], []
]
WKDECK = [
[], []
]
EXTD = [
[], []
]
WKEXTD = [
[], []
]
EXTM = [
[], []
]
HAND = [
[], []
]
# String to array mapping of field positions
FIELD_POS = {
"hand": HAND,
"field": FIELD,
"pend": PEND,
"grave": GRAV,
"extm": EXTM,
"ban": BAN,
"spell": SPELL
}
# Array of field names for ease of use
FIELD_NAMES = list(FIELD_POS.keys())
# Increment a phase
# starts a new round if finish phases.
def next_phase(pf):
pf.CUR_PHASE += 1
if pf.CUR_PHASE >= 5:
new_round()
# Clear the action stack
AS = []
# Resolve the global stack.
def resolve_stack(pf):
resolve_stack_rec(pf.AS)
# Resolve_stack can be called recursively
# Hence why we need a stack object
# Called by resolve_stack
# No support stacking midway.
def resolve_stack_rec(stack):
while len(stack) != 0:
f = stack.pop()
# Run function
f()
stack = []
# Logic to start the next round.
def new_round(pf):
pf.CUR_PHASE = 0
pf.ROUND_CNT += 1
AS = []
# Types of card positions
# FD is mainly for spells being facedown
CARD_POS = ["FU_ATK", "FU_DEF", "FD_DEF", "FD"]
# All face up is > 0 and all face down is < 0
# Card position definitions
FACE_UP_ATK = 1
FACE_UP_DEF = 2
FACE_DOWN_ATK = -1
FACE_DOWN_DEF = -2
# Same enumeration from before, mainly for syntactic sugar.
FACE_UP_SPELL = 1
FACE_DOWN_SPELL = -1
#
# Playfield print functions
#
# Print all deck info
def startdeckinfo(pf, player):
result = "\nStarting Deck Total(" + str(cu.count_compress_cards(pf.DECK[player])) + "): \n"
result += cu.cards_to_string(pf.DECK[player])
result += "\n"
result += "\nStarting EXT Deck Total(" + str(len(pf.EXTD[player])) + "): \n"
result += cu.cards_to_string(pf.EXTD[player])
result += "\n"
return result
# All cards destroyed
def destroyedinfo(pf, player):
result = "\n"
ult = ""
ult += "\nGraveyard Total(" + str(len(pf.GRAV[player])) + "): \n"
ult += cu.cards_to_string(cu.compress_cards(pf.GRAV[player]))
result += "\n"
result += "\nBan Total(" + str(len(pf.BAN[player])) + "): \n"
result = cu.cards_to_string(cu.compress_cards(pf.BAN[player]))
result += "\n"
return result
def handinfo(pf, player):
result = "\n"
result += "\nHand Total(" + str(len(pf.HAND[player])) + "): \n"
result += cu.cards_to_string(cu.compress_cards(pf.HAND[player]))
result += "\n"
return result
def fieldinfo(pf, player):
other = 1 - player
result = "\nEXT Monster Total(" + str(len(pf.EXTM[player])) + "): \n"
result += "\nPLAYER:"
result += cu.cards_to_string(pf.EXTM[player])
result += "\nOPPONENT:"
result += cu.cards_to_string(pf.EXTM[other], True)
result += "\n"
result += "\nField Total(" + str(cu.multi_array_count(pf.FIELD[player])) + "): \n"
print(pf.FIELD)
result += "\nPLAYER:"
result += cu.multi_cards_to_string(pf.FIELD[player])
result += "\nOPPONENT:"
result += cu.multi_cards_to_string(pf.FIELD[other], True)
result += "\n"
return result
# Returns string with all the info regarding the current player
def cardinfo(pf, player):
result = "\nDeck Total(" + str(len(pf.WKDECK[player])) + "): \n"
result += cu.cards_to_string(cu.compress_cards(pf.WKDECK[player]))
result += "\n"
return result
def allinfo(pf, player):
result = startdeckinfo(pf, player)
result += handinfo(pf, player)
result += cardinfo(pf, player)
result += fieldinfo(pf, player)
result += destroyedinfo(pf, player)
return result