SimplePlayerB¶
Role: Deterministic Player B policy that uses Player A’s communication bits when addressed by the gun index, otherwise falls back to stochastic shooting.
Location: Q_Sea_Battle.simple_player_b.SimplePlayerB
Constructor¶
Parameter | Type | Description
| --- | --- | --- |
| game_layout | GameLayout, constraints: not specified, shape: not applicable | Game configuration for this player.
Preconditions
game_layoutis aGameLayoutinstance (not otherwise validated here).
Postconditions
- The instance is initialized via
PlayerB.__init__(game_layout). self.game_layoutis available as provided by the base class (exact storage details not specified in this module).
Errors
- Not specified.
Example
from Q_Sea_Battle.simple_player_b import SimplePlayerB
from Q_Sea_Battle.game_layout import GameLayout
layout = GameLayout(...) # Not specified in this module
player_b = SimplePlayerB(game_layout=layout)
Public Methods¶
decide¶
decide(self, gun: np.ndarray, comm: np.ndarray, supp: Optional[Any] = None) -> int
Decide whether to shoot based on the gun and Player A’s message.
Parameter | Type | Description
| --- | --- | --- |
| gun | np.ndarray, dtype: any (cast to int via np.asarray(..., dtype=int)), constraints: expected one-hot (not enforced), shape: any (flattened to 1D via ravel()), resulting shape (n2,) | One-hot gun vector over enemy field cells; the selected index is argmax(flat_gun). |
| comm | np.ndarray, dtype: any (cast to int via np.asarray(..., dtype=int)), constraints: expected length m where m = self.game_layout.comms_size (not enforced before indexing), shape: any (flattened to 1D via ravel()), resulting shape (m,) | Communication vector from Player A; used as addressed bits when gun_index < m. |
| supp | Optional[Any], constraints: unused, shape: not applicable | Optional supporting information (unused). |
Returns
int, constraints: in{0,1}, shape: scalar; action where1means shoot and0means do not shoot.
Preconditions
self.game_layout.comms_sizeis available and is compatible with indexing intocommwhengun_index < m(exact type constraints not specified in this module).self.game_layout.enemy_probabilityis available and is used as a probability thresholdp(not validated to be within \([0, 1]\) in this module).
Postconditions
- If
gun_index < m, returnsint(comm[gun_index]). - Otherwise, returns
int(np.random.rand() < p).
Errors
- May raise
IndexErrorifgun_index < mbutcommis shorter thanm(or shorter thangun_index + 1). - Other exceptions may be raised by NumPy conversions or attribute access if inputs or
game_layoutare incompatible (not exhaustively specified).
Example
import numpy as np
from Q_Sea_Battle.simple_player_b import SimplePlayerB
from Q_Sea_Battle.game_layout import GameLayout
layout = GameLayout(...) # Not specified in this module
player_b = SimplePlayerB(layout)
gun = np.array([0, 1, 0, 0]) # argmax -> 1
comm = np.array([1, 0, 1]) # m should be 3 to match comm length here
action = player_b.decide(gun=gun, comm=comm)
Data & State¶
- Inherits from
PlayerB; base-class state is not specified in this module. - Uses
self.game_layout.comms_size(definesm, the number of communication bits) andself.game_layout.enemy_probability(definesp, the stochastic shoot probability outside the addressing range).
Planned (design-spec)¶
- Not specified.
Deviations¶
- No design notes provided; no deviations identified.
Notes for Contributors¶
- The method assumes
gunrepresents a valid one-hot selection, but it does not validate one-hotness; it usesargmaxon the flattened array, so ties or non-binary inputs will select the first maximum index. - The method casts
gunandcommto integer arrays; negative or non-binary values incommwill be returned as-is (afterint(...)) when addressed. - If strict validation is required (e.g., enforcing
commlength equalsmand ensuring \(p \in [0,1]\)), it must be added explicitly; this module currently does not enforce these constraints.
Related¶
Q_Sea_Battle.players_base.PlayerBQ_Sea_Battle.game_layout.GameLayout
Changelog¶
- Not specified.