-
Notifications
You must be signed in to change notification settings - Fork 0
FEATURE: basic notation standard #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Segelzwerg
wants to merge
72
commits into
main
Choose a base branch
from
feature/notation_definition
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
72 commits
Select commit
Hold shift + click to select a range
f390769
ADD: header example
Segelzwerg c43cf88
UPDATE: use list for players
Segelzwerg 595a0db
UPDATE: use standard as filename
Segelzwerg fbf8773
ADD: autosectionlabel extension
Segelzwerg 58956d5
UPDATE: use auto section ref
Segelzwerg 31d0bf2
ENABLE: autosection
Segelzwerg 0e833fa
REMOVE: enumartion
Segelzwerg 53bb906
Merge branch 'setup' into feature/notation_definition
Segelzwerg e0d485b
UPDATE: enable if invalid reference
Segelzwerg 45c7d15
FIX: ref syntax
Segelzwerg ada4d3b
REMOVE: language tag
Segelzwerg 6fa573a
REMOVE: fail on warning
Segelzwerg 1b25e96
REMOVE: language at all
Segelzwerg 1cf7d48
REMOVE: caption
Segelzwerg e687761
FIX: caption header
Segelzwerg c4118a9
REMOVE: fail on warning
Segelzwerg f624c83
REMOVE: caption
Segelzwerg 005eedb
Revert "REMOVE: fail on warning"
Segelzwerg b94bd69
REMOVE: empty line
Segelzwerg becc601
ADD: language toml tag
Segelzwerg fa24eb4
FIX: empyt line before code
Segelzwerg 47532e3
REMOVE: fail on warning
Segelzwerg 7efec69
ADD: time and location details
Segelzwerg 2cad108
FIX: array name
Segelzwerg c11f692
UPDATE: dependencies
Segelzwerg b73f3f3
Merge branch 'main' into feature/notation_definition
Segelzwerg fb13763
ADD: stack notation
Segelzwerg 21e6095
ADD: make strings
Segelzwerg ab0489b
ADD: make strings
Segelzwerg cc80c86
ADD: players hand
Segelzwerg 313267d
Merge branch 'main' into feature/notation_definition
Segelzwerg 8735169
FIX: lock file
Segelzwerg 4f221fe
ADD: card model
Segelzwerg 8dd38bf
UPDATE: documentation
Segelzwerg 54e99ce
FIX: spacing
Segelzwerg 58cb60c
Create test_card.py
Segelzwerg ba5fc0e
ADD: general validation
Segelzwerg 998b893
FORMAT
Segelzwerg e1ac6ab
REFACTOR: rename test
Segelzwerg f62036f
REMOVE: init
Segelzwerg a6be886
ADD: more tests
Segelzwerg daa08f3
FIX: tests
Segelzwerg afdd286
FIX: test name
Segelzwerg 97be351
WIP: stack
Segelzwerg 7f20625
Merge branch 'main' into feature/notation_definition
Segelzwerg 310aabb
ADD: stack implementation
Segelzwerg b9ee2c8
ADD: tomlkit
Segelzwerg 42e3aff
ADD: card properties
Segelzwerg fefe97b
FIX: array of tables
Segelzwerg d10aa96
REMOVE: tomli_w
Segelzwerg 6caa052
UPDATE: documentation
Segelzwerg 6b65dd2
ADD: team flake config
Segelzwerg 342cc33
REFACTOR: constants
Segelzwerg e785d7e
UPDATE: use seat instead of names
Segelzwerg 1bbc37e
ADD: builder player
Segelzwerg 037aa1c
ADD: player class
Segelzwerg 6f4e141
ADD: header
Segelzwerg a92d4a5
UPDATE: check for pausible team setups
Segelzwerg e0b314d
FIX: player names
Segelzwerg 2d2c82b
UPDATE: test edge cases
Segelzwerg 2154797
ADD: player dict
Segelzwerg cadbc24
ADD: card dict
Segelzwerg f5b48a7
ADD: location support
Segelzwerg 82398a0
UPDATE: documentation
Segelzwerg 92177ed
Update notation/header.py
Segelzwerg 8f6c775
Update docs/source/standard.rst
Segelzwerg 6ea1087
Update docs/source/standard.rst
Segelzwerg 5e71ae3
REMOVE: unused row
Segelzwerg 07471a5
UPDATE: move seat to attribute
Segelzwerg 9db26c6
UPDATE: tests
Segelzwerg 4af5909
FIX: f string notation
Segelzwerg 66f81bf
REMOVE: double wrap
Segelzwerg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| [flake8] | ||
| exclude = | ||
| .git | ||
| .github | ||
| .venv | ||
| __pycache__ | ||
| .eggs | ||
| *.egg | ||
| *.egg-info | ||
| build | ||
| dist | ||
| venv | ||
| ignore = D200, D204, D205, D400, D401 | ||
| max-line-length = 100 | ||
| max-complexity = 10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ build: | |
|
|
||
| sphinx: | ||
| configuration: docs/source/conf.py | ||
|
|
||
| formats: | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| Card Game Notation Standard | ||
| =========================== | ||
| This standard uses TOML_ as notation language. | ||
|
|
||
| Header | ||
| ------- | ||
| All meta data is defined in the Header. | ||
| This contains information about teams and players. | ||
| Furthermore, the location and datetime is stated. | ||
|
|
||
| .. code-block:: toml | ||
|
|
||
| [header] | ||
| # Timestamp of the starting time in RFC 3339 | ||
| timestamp = 2022-08-06T11:22:00 | ||
| # Location of the game or the server url | ||
| location = "Hamburg" | ||
| # Unsigned Integer | ||
| number_of_teams = 2 | ||
| [[players]] | ||
| # Unsigned Integer: ID of team starting with 0 | ||
| team = 0 | ||
| name = "John" | ||
| [[players]] | ||
| team = 1 | ||
| Name = "Lucy" | ||
|
|
||
| Stack | ||
| ----- | ||
| The data contains one mandatory field ``stack`` that is a list of strings representing a card. | ||
| Furthermore it has an optional field ``hands`` that is a table of the players' cards in hand. | ||
| One card can be represented with | ||
|
|
||
| .. code-block:: toml | ||
|
|
||
| suit = "[♦♣♥♠]" | ||
| rank = "[2-10JQKA]" | ||
|
iTitus marked this conversation as resolved.
|
||
|
|
||
| .. code-block:: toml | ||
|
|
||
|
|
||
| [[stack]] | ||
| suit="heart" | ||
| rank="A" | ||
| [[stack]] | ||
| suit="heart" | ||
| rank="K" | ||
|
|
||
| [[hands.player_1]] | ||
| [[hands.player_1.card]] | ||
|
iTitus marked this conversation as resolved.
|
||
| suit="heart" | ||
| rank="2" | ||
|
|
||
|
|
||
| .. _TOML: https://toml.io/en/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| """Python implementation of a general card and specific versions.""" | ||
| import tomlkit | ||
|
|
||
| FRENCH_SUITS = ('♦', '♣', '♥', '♠') | ||
|
|
||
| FRENCH_RANKS = ('A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K') | ||
|
|
||
|
|
||
| class Card: | ||
| """General representation of a card.""" | ||
|
|
||
| def __init__(self, suit: str, rank: str) -> None: | ||
| """ | ||
| Construct a card. | ||
|
|
||
| :param suit: The suit of the card. | ||
| :param rank: The rank of the card. | ||
| """ | ||
| self._suit: str = self._valid_suit(suit) | ||
| self._rank: str = self._valid_rank(rank) | ||
|
|
||
| @staticmethod | ||
| def _valid_suit(suit: str) -> str: | ||
| if not isinstance(suit, str): | ||
| raise ValueError('Suit must be string.') | ||
| if not suit: | ||
| raise ValueError('Suit cannot be empty.') | ||
| return suit | ||
|
|
||
| @staticmethod | ||
| def _valid_rank(rank: str) -> str: | ||
| if not isinstance(rank, str): | ||
| raise ValueError('Rank must be string.') | ||
| if not rank: | ||
| raise ValueError('Rank must not be empty.') | ||
| return rank | ||
|
|
||
| @property | ||
| def suit(self) -> str: | ||
| """Returns the suit of a card as string.""" | ||
| return self._suit | ||
|
|
||
| @property | ||
| def rank(self) -> str: | ||
| """Returns the rank of a card as string.""" | ||
| return self._rank | ||
|
|
||
| def dumps(self) -> str: | ||
| """Return the card as TOML string.""" | ||
| return tomlkit.dumps(self.dict()) | ||
|
|
||
| def dict(self): | ||
| """Return the card as dictionary.""" | ||
| return {'suit': self._suit, 'rank': self._rank} | ||
|
|
||
|
|
||
| class FrenchCard(Card): | ||
| """Represents a French card.""" | ||
|
|
||
| @staticmethod | ||
| def _valid_suit(suit: str) -> str: | ||
| if suit not in FRENCH_SUITS: | ||
| raise ValueError('Not a correct french suit.') | ||
| return suit | ||
|
|
||
| @staticmethod | ||
| def _valid_rank(rank: str) -> str: | ||
| if rank not in FRENCH_RANKS: | ||
| raise ValueError('Not a correct french rank.') | ||
| return rank |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| """Header containing the meta data of a game.""" | ||
| from datetime import datetime | ||
| from typing import Optional | ||
|
|
||
| import tomlkit | ||
|
|
||
| from notation.player import Player | ||
|
|
||
|
|
||
| # pylint: disable=too-few-public-methods | ||
| class Header: | ||
| """Class implementation of a meta data wrapper.""" | ||
|
|
||
| def __init__(self, start_time: datetime, players: list[Player], | ||
| number_teams: int, location: Optional[str] = None, ): | ||
| """Constructor. | ||
| :param start_time: The start time of the game as datetime object | ||
| :param players: The list of players. | ||
| :param number_teams: The number of teams. | ||
| :param location: Optional. Where the game to place. | ||
| """ | ||
| self._start_time: datetime = start_time | ||
| self._location = location | ||
| if players is None or len(players) == 0: | ||
| raise ValueError('Player list cannot be empty') | ||
| if number_teams > len(players): | ||
| raise ValueError('Number teams cannot be greater than amount of players') | ||
| self._players = players | ||
| self._number_teams = number_teams | ||
|
|
||
| def dumps(self) -> str: | ||
| """Return a TOML string representation of the header.""" | ||
| players = [tomlkit.dumps({'players': [player.dict()]}) for player in self._players] | ||
| header_dump = {'header': {'timestamp': self._start_time.isoformat(), | ||
| 'number_of_teams': self._number_teams}} | ||
| if self._location: | ||
| header_dump['header']['location'] = self._location | ||
| player_string = '\n'.join(players) | ||
| return f'{tomlkit.dumps(header_dump)}\n{player_string}' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| """Wrapper for player data.""" | ||
|
|
||
|
|
||
| # pylint: disable=too-few-public-methods | ||
| class Player: | ||
| """Class containing player data.""" | ||
|
|
||
| def __init__(self, name: str, team: int, seat: int): | ||
| """Constructs | ||
| :param name: name of player | ||
| :param team: integer of the team ID | ||
| :param seat: The unique identifier of place at table for that player. | ||
| """ | ||
| self._name = name | ||
| self._team = team | ||
| self._seat = seat | ||
|
|
||
| def dict(self) -> dict[str, str]: | ||
| """Return player data as dictionary.""" | ||
| return {'name': self._name, 'team': self._team, 'seat': self._seat} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| """Implementation of a stack of cards.""" | ||
| from typing import List | ||
|
|
||
| import tomlkit | ||
|
|
||
| from notation.card import Card | ||
|
|
||
|
|
||
| # pylint: disable=too-few-public-methods | ||
| class Stack: | ||
| """A list of cards.""" | ||
|
|
||
| def __init__(self, cards: List[Card]): | ||
| """ | ||
| Construct a stack of cards. | ||
|
|
||
| :param cards: A list of cards. | ||
| """ | ||
| self._card_list: List[Card] = cards | ||
|
|
||
| def dumps(self) -> str: | ||
| """Return the stack as TOML string.""" | ||
| card_dump = [card.dict() for card in self._card_list] | ||
| return tomlkit.dumps({'stack': card_dump}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.