🐐
This commit is contained in:
@@ -132,8 +132,6 @@ class NeuralNet:
|
||||
return net
|
||||
|
||||
|
||||
# ==================== Feature extraction ====================
|
||||
|
||||
def extract_plan_features(plans: list, player, opponent) -> np.ndarray:
|
||||
"""
|
||||
Returns (n_plans, N_FEATURES) float32 array.
|
||||
@@ -143,7 +141,7 @@ def extract_plan_features(plans: list, player, opponent) -> np.ndarray:
|
||||
|
||||
n = len(plans)
|
||||
|
||||
# ---- state (same for every plan) ----
|
||||
# state (same for every plan)
|
||||
state = np.array([
|
||||
player.life / STARTING_LIFE,
|
||||
opponent.life / STARTING_LIFE,
|
||||
@@ -155,7 +153,7 @@ def extract_plan_features(plans: list, player, opponent) -> np.ndarray:
|
||||
len(opponent.deck) / _MAX_DECK,
|
||||
], dtype=np.float32)
|
||||
|
||||
# ---- current boards (same for every plan) ----
|
||||
# current boards (same for every plan)
|
||||
my_board = np.zeros(BOARD_SIZE * 3, dtype=np.float32)
|
||||
opp_board = np.zeros(BOARD_SIZE * 3, dtype=np.float32)
|
||||
for slot in range(BOARD_SIZE):
|
||||
@@ -170,7 +168,7 @@ def extract_plan_features(plans: list, player, opponent) -> np.ndarray:
|
||||
opp_board[slot * 3 + 1] = c.defense / _MAX_DEF
|
||||
opp_board[slot * 3 + 2] = 1.0
|
||||
|
||||
# ---- per-plan features ----
|
||||
# per-plan features
|
||||
plan_part = np.zeros((n, 3 + BOARD_SIZE * 3), dtype=np.float32)
|
||||
for idx, plan in enumerate(plans):
|
||||
# simulate board result
|
||||
@@ -192,7 +190,7 @@ def extract_plan_features(plans: list, player, opponent) -> np.ndarray:
|
||||
plan_part[idx, 3 + slot * 3 + 1] = c.defense / _MAX_DEF
|
||||
plan_part[idx, 3 + slot * 3 + 2] = 1.0
|
||||
|
||||
# ---- opponent deck type one-hot (same for every plan) ----
|
||||
# opponent deck type one-hot (same for every plan)
|
||||
opp_deck_oh = np.zeros(len(_DECK_TYPES), dtype=np.float32)
|
||||
opp_deck_oh[_DECK_TYPE_IDX.get(opponent.deck_type, 0)] = 1.0
|
||||
|
||||
@@ -204,8 +202,6 @@ def extract_plan_features(plans: list, player, opponent) -> np.ndarray:
|
||||
return np.concatenate([state_t, my_board_t, opp_board_t, plan_part, opp_deck_t], axis=1)
|
||||
|
||||
|
||||
# ==================== Neural player ====================
|
||||
|
||||
class NeuralPlayer:
|
||||
"""
|
||||
Wraps a NeuralNet for use in game simulation.
|
||||
|
||||
Reference in New Issue
Block a user