PRAssistedPlayers¶
Role: Factory that owns a hierarchy of PR-assisted resources and hands out paired
PRAssistedPlayerA/PRAssistedPlayerBinstances.
Location: Q_Sea_Battle.pr_assisted_players.PRAssistedPlayers
Derived constraints¶
- Let
field_sizebegame_layout.field_size(int, constraints not specified in this module) andcomms_sizebegame_layout.comms_size(int, constraints not specified in this module). comms_size == 1is required.- Let
n2 = field_size ** 2(int).n2 > 0is required. n2must be a power of two (equivalently:n2 & (n2 - 1) == 0forn2 > 0), and additionally_create_pr_assisted_array()enforces exact power-of-two via2**n == n2where \(n = \lfloor \log_2(n2) \rfloor\).- The internal PR-assisted resource list has length \(n\), and contains resources with lengths \(2^{n-1}, 2^{n-2}, \dots, 2^0\).
Constructor¶
| Parameter | Type | Description |
|---|---|---|
game_layout |
GameLayout, constraints Unknown, shape N/A |
Game configuration used to derive field_size and comms_size. |
p_high |
float, constraints Unknown, shape N/A |
Correlation parameter used for all PR-assisted resources. Coerced via float(p_high). |
Preconditions
game_layout.comms_size == 1.n2 = game_layout.field_size ** 2satisfiesn2 > 0.n2is a power of two.
Postconditions
self.p_highis set tofloat(p_high).self._pr_assisted_arrayis created via_create_pr_assisted_array().self._playerA is Noneandself._playerB is None(players are created lazily byplayers()).
Errors
- Raises
ValueErrorifgame_layout.comms_size != 1. - Raises
ValueErrorifgame_layout.field_size ** 2 <= 0. - Raises
ValueErrorifgame_layout.field_size ** 2is not a power of two.
Example
from Q_Sea_Battle.game_layout import GameLayout
from Q_Sea_Battle.pr_assisted_players import PRAssistedPlayers
layout = GameLayout(field_size=4, comms_size=1) # other args, if any, are not specified here
factory = PRAssistedPlayers(game_layout=layout, p_high=0.9)
player_a, player_b = factory.players()
Public Methods¶
players¶
- Signature:
players(self) -> Tuple[PlayerA, PlayerB] - Returns:
Tuple[PlayerA, PlayerB], constraints Unknown, shape(2,)as a 2-tuple(player_a, player_b). - Behavior: Creates
PRAssistedPlayerAandPRAssistedPlayerBon first call (lazy initialization) and caches them; later calls return the cached instances.
Errors
- Not specified.
Example
player_a, player_b = factory.players()
player_a2, player_b2 = factory.players()
assert player_a is player_a2 and player_b is player_b2
reset¶
- Signature:
reset(self) -> None - Returns:
None, constraints N/A, shape N/A. - Behavior: Recreates
self._pr_assisted_arrayvia_create_pr_assisted_array(); does not modify cached_playerA/_playerBin this module.
Errors
- May raise
ValueErrorpropagated from_create_pr_assisted_array()if the currentgame_layout.field_size ** 2is not an exact power of two.
Example
factory.reset()
pr_assisted¶
- Signature:
pr_assisted(self, index: int) -> PRAssisted - Parameters:
index:int, constraints: must be a valid list index forself._pr_assisted_array, shape N/A.- Returns:
PRAssisted, constraints Unknown, shape N/A. - Behavior: Returns the PR-assisted resource at
self._pr_assisted_array[index].
Errors
- Raises
IndexErrorifindexis out of bounds (propagated from list indexing).
Example
box0 = factory.pr_assisted(0)
shared_randomness¶
- Signature:
shared_randomness(self, index: int) -> PRAssisted - Parameters:
index:int, constraints: must be a valid list index forself._pr_assisted_array, shape N/A.- Returns:
PRAssisted, constraints Unknown, shape N/A. - Behavior: Prints a deprecation warning to stdout and delegates to
pr_assisted(index).
Errors
- Raises
IndexErrorifindexis out of bounds (viapr_assisted).
Example
box0 = factory.shared_randomness(0) # prints a deprecation warning
Data & State¶
game_layout:GameLayout, constraints Unknown, shape N/A; inherited fromPlayers(assignment performed byPlayers.__init__as invoked bysuper().__init__(game_layout)).p_high:float, constraints Unknown, shape N/A; correlation parameter used when constructing eachPRAssisted._pr_assisted_array:list[PRAssisted], constraints: lengthnwhere \(n = \log_2(n2)\) withn2 = field_size ** 2an exact power of two, shape N/A._playerA:PRAssistedPlayerA | None, constraints Unknown, shape N/A; cached instance created byplayers()._playerB:PRAssistedPlayerB | None, constraints Unknown, shape N/A; cached instance created byplayers().
Planned (design-spec)¶
- Not specified.
Deviations¶
- Not specified.
Notes for Contributors¶
_create_pr_assisted_array()usesnp.log2(n2)and casts toint, then verifies exactness via2**n == n2; keep this check if refactoring to avoid float rounding issues.shared_randomness()prints directly; if changing deprecation behavior, ensure compatibility considerations are addressed across the package.
Related¶
Q_Sea_Battle.pr_assisted.PRAssistedQ_Sea_Battle.pr_assisted_player_a.PRAssistedPlayerAQ_Sea_Battle.pr_assisted_player_b.PRAssistedPlayerBQ_Sea_Battle.players_base.PlayersQ_Sea_Battle.game_layout.GameLayout
Changelog¶
- Version 0.1: Introduced
PRAssistedPlayerswithpr_assisted()and deprecated aliasshared_randomness().