Skip to content

Commit

Permalink
[players] Move init function to states.room
Browse files Browse the repository at this point in the history
  • Loading branch information
Prometheus3375 committed Jul 19, 2024
1 parent 0c69960 commit 8ad4bc7
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 44 deletions.
46 changes: 5 additions & 41 deletions solve/players.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from collections.abc import Mapping, Sequence
from collections.abc import Mapping
from dataclasses import dataclass

from .key_sets import KeySetType
from .shapes import Shape2D
from .states import LEFT, MIDDLE, PositionsType, RIGHT, StateOfAllRooms, init_rooms
from .states import PositionsType

type AliasMappingType = Mapping[PositionsType, str]


@dataclass(frozen=True, kw_only=True, slots=True)
Expand All @@ -13,41 +14,4 @@ class Player:
other_shape: Shape2D


type AliasMappingType = Mapping[PositionsType, str]


def init_rooms_from_players(
players: Sequence[Player],
inner_shapes: Sequence[Shape2D],
key_set: KeySetType,
/,
) -> tuple[StateOfAllRooms, AliasMappingType]:
"""
Takes three players in solo rooms,
2D shapes of statues there in order from left to right,
and the current key set.
Returns initial state of solo rooms a mapping of positions to player aliases.
"""
assert len(players) == len(inner_shapes) == 3, f'number of players and shapes must be 3'
inner2person = {
i: p
for i in inner_shapes
for p in players
if p.their_shape == i
}
aliases = dict(zip((LEFT, MIDDLE, RIGHT), (inner2person[i].alias for i in inner_shapes)))
other = tuple(inner2person[i].other_shape for i in inner_shapes)
state = init_rooms(
left_inner_shape=inner_shapes[0],
left_other_shape=other[0],
middle_inner_shape=inner_shapes[1],
middle_other_shape=other[1],
right_inner_shape=inner_shapes[2],
right_other_shape=other[2],
key_set=key_set,
)

return state, aliases


__all__ = 'Player', 'AliasMappingType', 'init_rooms_from_players'
__all__ = 'Player', 'AliasMappingType'
41 changes: 38 additions & 3 deletions solve/states/rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
from collections.abc import Iterator
from dataclasses import dataclass
from itertools import permutations
from typing import Self
from typing import Self, Sequence

from .base import *
from ..key_sets import KSMixed, KeySetType
from ..multiset import Multiset
from ..shapes import *
from ..players import *
from ..shapes import Shape2D


@dataclass(frozen=True, kw_only=True, slots=True)
Expand Down Expand Up @@ -164,4 +165,38 @@ def init_rooms(
)


__all__ = 'PassMove', 'StateOfAllRooms', 'init_rooms'
def init_rooms_from_players(
players: Sequence[Player],
inner_shapes: Sequence[Shape2D],
key_set: KeySetType,
/,
) -> tuple[StateOfAllRooms, AliasMappingType]:
"""
Takes three players in solo rooms,
2D shapes of statues there in order from left to right,
and the current key set.
Returns initial state of solo rooms a mapping of positions to player aliases.
"""
assert len(players) == len(inner_shapes) == 3, f'number of players and shapes must be 3'
inner2person = {
i: p
for i in inner_shapes
for p in players
if p.their_shape == i
}
aliases = dict(zip((LEFT, MIDDLE, RIGHT), (inner2person[i].alias for i in inner_shapes)))
other = tuple(inner2person[i].other_shape for i in inner_shapes)
state = init_rooms(
left_inner_shape=inner_shapes[0],
left_other_shape=other[0],
middle_inner_shape=inner_shapes[1],
middle_other_shape=other[1],
right_inner_shape=inner_shapes[2],
right_other_shape=other[2],
key_set=key_set,
)

return state, aliases


__all__ = 'PassMove', 'StateOfAllRooms', 'init_rooms', 'init_rooms_from_players'

0 comments on commit 8ad4bc7

Please sign in to comment.