Skip to content

Commit

Permalink
Merge pull request #27 from SHADE-AI/feature/add_level_0
Browse files Browse the repository at this point in the history
Feature/add level 0
  • Loading branch information
mjspeck authored Oct 5, 2022
2 parents c291764 + 7890885 commit 5873016
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 37 deletions.
3 changes: 2 additions & 1 deletion src/daidepp/daide_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ def visit_qry_wht_prp_ins(self, node, visited_children):

def visit_idk(self, node, visited_children):
_, _, message, _ = visited_children
return ("IDK", message)

return ("IDK", message[0]) if isinstance(message, list) else ("IDK", message)

def visit_sry(self, node, visited_children):
_, _, exp, _ = visited_children
Expand Down
76 changes: 40 additions & 36 deletions src/daidepp/grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,42 @@ def from_level(level: DAIDE_LEVEL, allow_just_arrangment: bool = False):
return create_daide_grammar(level, allow_just_arrangment)


DAIDE_LEVEL = Literal[10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130]
DAIDE_LEVEL = Literal[0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130]

TRAIL_TOKEN = "---" # any value starting with '---' is meant to be a continuation of that key, not a replacement

LEVEL_0: GRAMMAR_DICT = {
"power": '"AUS" / "ENG" / "FRA" / "GER" / "ITA" / "RUS" / "TUR"',
"order": "hld / mto / sup / cvy / move_by_cvy / retreat / build",
"hld": 'lpar unit rpar "HLD"',
"mto": 'lpar unit rpar "MTO" ws province',
"sup": 'lpar unit rpar "SUP" lpar unit rpar ("MTO" ws prov_no_coast)?',
"cvy": 'lpar unit rpar "CVY" lpar unit rpar "CTO" ws province',
"move_by_cvy": 'lpar unit rpar "CTO" ws province ws "VIA" lpar prov_sea (ws prov_sea)* rpar',
"retreat": "rto / dsb",
"rto": 'lpar unit rpar "RTO" ws province',
"dsb": 'lpar unit rpar "DSB"',
"build": "bld / rem / wve",
"bld": 'lpar unit rpar "BLD"',
"rem": 'lpar unit rpar "REM"',
"wve": 'power ws "WVE"',
"unit_type": '"AMY" / "FLT"',
"unit": "power ws unit_type ws province",
"prov_no_coast": "prov_land_sea / prov_landlock / prov_sea",
"prov_coast": '(lpar "STP" ws "SCS" rpar) / (lpar "STP" ws "SCS" rpar) / (lpar "SPA" ws "NCS" rpar) / (lpar "SPA" ws "SCS" rpar) / (lpar "BUL" ws "ECS" rpar) / (lpar "BUL" ws "SCS" rpar)',
"province": "prov_land_sea / prov_landlock / prov_sea / prov_coast",
"coast": '"NCS" / "ECS" / "SCS" / "WCS"',
"prov_land_sea": '"ALB" / "ANK" / "APU" / "ARM" / "BEL" / "BER" / "BRE" / "BUL" / "CLY" / "CON" / "DEN" / "EDI" / "FIN" / "GAS" / "GRE" / "HOL" / "KIE" / "LON" / "LVN" / "LVP" / "MAR" / "NAF" / "NAP" / "NWY" / "PIC" / "PIE" / "POR" / "PRU" / "ROM" / "RUM" / "SEV" / "SMY" / "SPA" / "STP" / "SWE" / "SYR" / "TRI" / "TUN" / "TUS" / "VEN" / "YOR" / "WAL"',
"prov_landlock": '"BOH" / "BUD" / "BUR" / "MOS" / "MUN" / "GAL" / "PAR" / "RUH" / "SER" / "SIL" / "TYR" / "UKR" / "VIE" / "WAR" ',
"prov_sea": '"ADR" / "AEG" / "BAL" / "BAR" / "BLA" / "BOT" / "EAS" / "ENG" / "HEL" / "ION" / "IRI" / "LYO" / "MAO" / "NAO" / "NTH" / "NWG" / "SKA" / "TYS" / "WES"',
"supply_center": '"ANK" / "BEL" / "BER" / "BRE" / "BUD" / "BUL" / "CON" / "DEN" / "EDI" / "GRE" / "HOL" / "KIE" / "LON" / "LVP" / "MAR" / "MOS" / "MUN" / "NAP" / "NWY" / "PAR" / "POR" / "ROM" / "RUM" / "SER" / "SEV" / "SMY" / "SPA" / "STP" / "SWE" / "TRI" / "TUN" / "VEN" / "VIE" / "WAR"',
"turn": 'season ws ~"\d{4}"',
"season": '"SPR" / "SUM" / "FAL" / "AUT" / "WIN"',
"lpar": '~"\s*\(\s*"',
"rpar": '~"\s*\)\s*"',
"ws": '~"\s+"',
}

# Peace and Alliances
LEVEL_10: GRAMMAR_DICT = {
"pce": '"PCE" lpar power (ws power)* rpar',
Expand All @@ -47,15 +79,11 @@ def from_level(level: DAIDE_LEVEL, allow_just_arrangment: bool = False):
"bwx": '"BWX" lpar press_message rpar',
"fct": '("FCT" lpar arrangement rpar)',
"frm": '"FRM" lpar power rpar lpar power (ws power)* rpar lpar message rpar',
"power": '"AUS" / "ENG" / "FRA" / "GER" / "ITA" / "RUS" / "TUR"',
"lpar": '~"\s*\(\s*"',
"rpar": '~"\s*\)\s*"',
"ws": '~"\s+"',
"reply": "yes / rej / bwx / huh",
"message": "press_message / reply",
"press_message": "prp / ccl / fct / try / frm",
"arrangement": "pce / aly_vss / drw / slo / not / nar",
"try_tokens": '"PRP" / "PCE" / "ALY" / "VSS" / "DRW" / "SLO" / "NOT" / "YES" / "REJ" / "BWX" / "FCT"',
"try_tokens": '"PRP" / "PCE" / "ALY" / "VSS" / "DRW" / "SLO" / "NOT" / "NAR" / "YES" / "REJ" / "BWX" / "FCT"',
}

# prov_no_coast: all province tokens without coasts
Expand All @@ -65,30 +93,7 @@ def from_level(level: DAIDE_LEVEL, allow_just_arrangment: bool = False):
LEVEL_20: GRAMMAR_DICT = {
"xdo": '"XDO" lpar order rpar',
"dmz": '"DMZ" lpar power (ws power)* rpar lpar province (ws province)* rpar',
"order": "hld / mto / sup / cvy / move_by_cvy / retreat / build",
"hld": 'lpar unit rpar "HLD"',
"mto": 'lpar unit rpar "MTO" ws province',
"sup": 'lpar unit rpar "SUP" lpar unit rpar ("MTO" ws prov_no_coast)?',
"cvy": 'lpar unit rpar "CVY" lpar unit rpar "CTO" ws province',
"move_by_cvy": 'lpar unit rpar "CTO" ws province ws "VIA" lpar prov_sea (ws prov_sea)* rpar',
"retreat": "rto / dsb",
"rto": 'lpar unit rpar "RTO" ws province',
"dsb": 'lpar unit rpar "DSB"',
"build": "bld / rem / wve",
"bld": 'lpar unit rpar "BLD"',
"rem": 'lpar unit rpar "REM"',
"wve": 'power ws "WVE"',
"unit_type": '"AMY" / "FLT"',
"unit": "power ws unit_type ws province",
"prov_no_coast": "prov_land_sea / prov_landlock / prov_sea",
"prov_coast": '(lpar "STP" ws "SCS" rpar) / (lpar "STP" ws "SCS" rpar) / (lpar "SPA" ws "NCS" rpar) / (lpar "SPA" ws "SCS" rpar) / (lpar "BUL" ws "ECS" rpar) / (lpar "BUL" ws "SCS" rpar)',
"province": "prov_land_sea / prov_landlock / prov_sea / prov_coast",
"coast": '"NCS" / "ECS" / "SCS" / "WCS"',
"prov_land_sea": '"ALB" / "ANK" / "APU" / "ARM" / "BEL" / "BER" / "BRE" / "BUL" / "CLY" / "CON" / "DEN" / "EDI" / "FIN" / "GAS" / "GRE" / "HOL" / "KIE" / "LON" / "LVN" / "LVP" / "MAR" / "NAF" / "NAP" / "NWY" / "PIC" / "PIE" / "POR" / "PRU" / "ROM" / "RUM" / "SEV" / "SMY" / "SPA" / "STP" / "SWE" / "SYR" / "TRI" / "TUN" / "TUS" / "VEN" / "YOR" / "WAL"',
"prov_landlock": '"BOH" / "BUD" / "BUR" / "MOS" / "MUN" / "GAL" / "PAR" / "RUH" / "SER" / "SIL" / "TYR" / "UKR" / "VIE" / "WAR" ',
"prov_sea": '"ADR" / "AEG" / "BAL" / "BAR" / "BLA" / "BOT" / "EAS" / "ENG" / "HEL" / "ION" / "IRI" / "LYO" / "MAO" / "NAO" / "NTH" / "NWG" / "SKA" / "TYS" / "WES"',
"supply_center": '"ANK" / "BEL" / "BER" / "BRE" / "BUD" / "BUL" / "CON" / "DEN" / "EDI" / "GRE" / "HOL" / "KIE" / "LON" / "LVP" / "MAR" / "MOS" / "MUN" / "NAP" / "NWY" / "PAR" / "POR" / "ROM" / "RUM" / "SER" / "SEV" / "SMY" / "SPA" / "STP" / "SWE" / "TRI" / "TUN" / "VEN" / "VIE" / "WAR"',
"arrangement": f"{TRAIL_TOKEN}mto / xdo / dmz",
"arrangement": f"{TRAIL_TOKEN}xdo / dmz",
"try_tokens": f'{TRAIL_TOKEN}"XDO" / "DMZ"',
}

Expand All @@ -115,7 +120,7 @@ def from_level(level: DAIDE_LEVEL, allow_just_arrangment: bool = False):
"orr": '"ORR" lpar arrangement rpar (lpar arrangement rpar)+',
"cho": '"CHO" lpar (~"\d+ \d+") rpar (lpar arrangement rpar)+',
"arrangement": f"{TRAIL_TOKEN}cho",
"try_tokens": f'{TRAIL_TOKEN}"CHO"', # This isn't included in the originla daide spec but I think they just forgot it.
"try_tokens": f'{TRAIL_TOKEN}"CHO"', # This isn't included in the original daide spec but I think they just forgot it.
}

# Queries and Insistencies
Expand All @@ -127,7 +132,7 @@ def from_level(level: DAIDE_LEVEL, allow_just_arrangment: bool = False):
"sug": '"SUG" lpar arrangement rpar',
"fct": '("FCT" lpar qry rpar) / ("FCT" lpar "NOT" lpar qry rpar rpar) / ("FCT" lpar arrangement rpar)',
"reply": f"{TRAIL_TOKEN}fct / thk / idk",
"try_tokens": f'{TRAIL_TOKEN}"INS" / "QRY" / "IDK" / "IDK" / "SUG"',
"try_tokens": f'{TRAIL_TOKEN}"INS" / "QRY" / "THK" / "IDK" / "SUG"',
"press_message": f"{TRAIL_TOKEN}thk / ins / qry / sug",
}

Expand All @@ -144,8 +149,6 @@ def from_level(level: DAIDE_LEVEL, allow_just_arrangment: bool = False):
"exp": '"EXP" lpar turn rpar lpar message rpar',
"idk": '("IDK" lpar exp rpar) / ("IDK" lpar qry rpar)',
"sry": '"SRY" lpar exp rpar',
"turn": 'season ws ~"\d{4}"',
"season": '"SPR" / "SUM" / "FAL" / "AUT" / "WIN"',
"press_message": f"{TRAIL_TOKEN}exp",
"try_tokens": f'{TRAIL_TOKEN}"EXP" / "SRY"',
}
Expand Down Expand Up @@ -189,10 +192,11 @@ def from_level(level: DAIDE_LEVEL, allow_just_arrangment: bool = False):
"pob": '"POB" lpar why rpar',
"idk": '"IDK" lpar qry_wht_prp_ins_sug rpar',
"reply": f"{TRAIL_TOKEN}why / pob / idk",
"try_tokens": f'{TRAIL_TOKEN}"IDK" / "WHY" / "POB"',
"try_tokens": f'{TRAIL_TOKEN}"WHY" / "POB"',
}

LEVELS: Tuple[GRAMMAR_DICT] = (
LEVEL_0,
LEVEL_10,
LEVEL_20,
LEVEL_30,
Expand Down Expand Up @@ -243,7 +247,7 @@ def _create_daide_grammar_dict(level: DAIDE_LEVEL = 30) -> GRAMMAR_DICT:
GRAMMAR_DICT: Dictionary representing all rules for passed daide level
"""

level_idxs = list(range(int((level / 10))))
level_idxs = list(range(int((level / 10) + 1)))
grammar: GRAMMAR_DICT = {}

for level_idx in level_idxs:
Expand Down

0 comments on commit 5873016

Please sign in to comment.