Skip to content

Commit

Permalink
Update enum_classes.py
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuai-gao committed Dec 12, 2022
1 parent 84d7de5 commit 1d07da3
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 27 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
<!--
Copyright (c) 2022 davidgao
This software is released under the MIT License.
https://opensource.org/licenses/MIT
-->

# Genius Invokation Gym

A simple simulator of the Genius Invokation TCG in Genshin impact
Expand All @@ -14,7 +21,7 @@ Package name `gisim` stands for both `Genshin Impact` and `Genius Invokation`


# Roadmap
- [ ] Encode the game status into a dictionary
- [x] Encode the game status into a dictionary
- [ ] Enable `Judge` to judge validity of a proposed action
- [ ] Define all kinds of messages in the simulator
- [ ] Write message queue to buffer all messages
Expand All @@ -29,4 +36,4 @@ Package name `gisim` stands for both `Genshin Impact` and `Genius Invokation`

顺便好奇一下为什么用invokation而不是invocation,求懂哥指点

新建QQ交流群613071650,欢迎感兴趣的同学入群
新建QQ交流群613071650,欢迎感兴趣的同学入群,欢迎成为Contributor!
5 changes: 4 additions & 1 deletion gisim/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import pkg_resources

from game import *
from agent import *
from judge import *
from global_config import *
__author__ = "David Gao"
__email__ = "davidgao1013@gmail.com"
__version__ = pkg_resources.require("gisim")[0].version
13 changes: 13 additions & 0 deletions gisim/agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'''Player & agent APIs
'''
from typing import OrderedDict
from enum_classes import PlayerID
from abc import ABCMeta, abstractmethod
from actions import *
class Agent(ABCMeta):
def __init__(self, player_id:PlayerID):
self.PLAYER_ID = player_id

@abstractmethod
def take_action(self, game_info:OrderedDict)->Action:
pass
2 changes: 1 addition & 1 deletion gisim/cards/characters/Cryo/KamisatoAyaka.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, player_id:PlayerID, position:Position):
self.NATIONALITY = 'Inazuma'
self.WEAPON_TYPE = 'sword'
self.health_point = 10
self.SKILLS_NUM = 4
self.SKILL_NUM = 4
# Init skills

normal_attack = Skill(name=self.SKILL_NAMES[0], cost={ET.CRYO:1, ET.UNALIGNED:2}, skill_type=ST.NORMAL_ATTACK)
Expand Down
6 changes: 3 additions & 3 deletions gisim/classes/character.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def get_raw_skill(self, id=None, skill_name=None, skill_type=None):
raw_skill (Skill): a Skill object with raw cost and effects (has not been affected by any discounts/enhancement)
'''
if id is not None:
assert 0 <= id <= self.skills_num - 1, f"id should be from 0 to {self.skills_num-1}"
assert 0 <= id <= self.SKILL_NUM - 1, f"id should be from 0 to {self.SKILL_NUM-1}"
return self.skills[id]
elif skill_name is not None:
if skill_name in self.SKILL_NAMES:
Expand Down Expand Up @@ -70,8 +70,8 @@ def health_point(self):

@property
@abstractmethod
def SKILLS_NUM(self):
self.SKILLS_NUM:int
def SKILL_NUM(self):
self.SKILL_NUM:int
...

@property
Expand Down
21 changes: 11 additions & 10 deletions gisim/enum_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ class GameStatus(Enum):
ENDED = 2


class InitializingPhase(Enum):
CHANGE_CARD = 0
SELECT_ACTIVE_CHARACTER = 1


class RunningPhase(Enum):
BEGIN_ROUND = 0 # Including drawing cards automatically
ROLL_DICE = 1
PLAY_CARDS = 2
END_ROUND = 3
class Phase(Enum):
CHANGE_CARD = 0
'''Only happens during initialization'''
SELECT_ACTIVE_CHARACTER = 1
'''Happens during initialization or when a character die'''
BEGIN_ROUND = 2
'''Including drawing cards automatically'''
ROLL_DICE = 3
PLAY_CARDS = 4
'''Or use character skills'''
END_ROUND = 5


class ET(Enum):
Expand Down
8 changes: 4 additions & 4 deletions gisim/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ class Game:
def __init__(self, player1_deck:dict, player2_deck:dict, seed:int=50):
self._random_state = RandomState(seed)
self._status = GameStatus.INITIALIZING
self._phase = InitializingPhase.CHANGE_CARD
self._phase = Phase.CHANGE_CARD
self._seed = seed
self._active_player = self._random_state.randint(1, 3) # Toss coin do determine player 1 or player 2
self.judge = Judge(self, self._random_state)
self._active_player = self._random_state.choice([1, 2]) # Toss coin to determine who act first
self.judge = Judge(self)
self.player1_area = PlayerArea(self, self._random_state, player_id=PlayerID.PLAYER1, deck=player1_deck)
self.player2_area = PlayerArea(self, self._random_state, player_id=PlayerID.PLAYER2, deck=player2_deck)



def encode_game(self, viewer_id:PlayerID):
assert viewer_id in [0, 1, 2], "viewer_id should be one of 0 (judge), 1, 2"
return OrderedDict({'viewer_id': viewer_id, 'status':self._status,
return OrderedDict({'viewer_id': viewer_id, 'status':self._status, 'phase':self._phase,
'player1':self.player1_area.encode(viewer_id),
'player2':self.player2_area.encode(viewer_id)})

Expand Down
3 changes: 0 additions & 3 deletions gisim/player.py

This file was deleted.

8 changes: 5 additions & 3 deletions gisim/player_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from collections import OrderedDict
from typing import TYPE_CHECKING
from enum_classes import *
from cards import get_card
if TYPE_CHECKING:
from .game import Game
from .classes import Character, Summon, Support, StatusEntity
Expand Down Expand Up @@ -51,7 +52,7 @@ class CharacterZone:
def __init__(self, parent:'PlayerArea', characters:list[str]):
self._parent = parent
assert len(characters)==3, "Number of characters should be 3"
self.characters:list['Character'] = [Card('character', characters[k]) for k in range(3)]
self.characters:list['Character'] = [get_card('character', characters[k]) for k in range(3)]

def encode(self):
return [self.characters[k].encode() for k in range(3)]
Expand All @@ -76,12 +77,13 @@ def encode(self):

class DiceZone:

def __init__(self, parent:'PlayerArea'):
def __init__(self, parent:'PlayerArea', random_state:RandomState):
self._parent = parent
self._random_state = random_state
self.dice:list[ET] = []

def roll_dice(self, dice_num=8):
self.dice =
self.dice = [ET(self._random_state.choice(8)) for _ in range(dice_num)]

def encode(self, viewer_id):
if viewer_id == self._parent.PLAYER_ID or viewer_id == 0:
Expand Down

0 comments on commit 1d07da3

Please sign in to comment.