Skip to content

Commit

Permalink
added fps to initializer player
Browse files Browse the repository at this point in the history
  • Loading branch information
lunathanael committed Mar 12, 2024
1 parent 901638a commit 34469dd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
9 changes: 6 additions & 3 deletions clash_royale/envs/game_engine/game_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def __init__(self,
width: int=18,
height: int=32,
resolution: Tuple[int, int]=(128, 128),
fps: int=30
) -> None:
"""
The game_engine should be initialized with settings such as resolution
Expand All @@ -50,12 +51,13 @@ def __init__(self,
self.width: int = width # Width of arena
self.height: int = height # Height of arena
self.resolution: Tuple[int, int] = resolution
self.fps: int = fps

self.arena: Arena = Arena(width=self.width, height=self.height)
self.player1: Player = Player(deck1)
self.player2: Player = Player(deck2)
self.player1: Player = Player(deck1, fps)
self.player2: Player = Player(deck2, fps)

self.scheduler: Scheduler = Scheduler(fps=30) # counting frames
self.scheduler: Scheduler = Scheduler(fps) # counting frames
self.game_scheduler: GameScheduler = DefaultScheduler(self.scheduler) # determining elixir etc.

def reset(self) -> None:
Expand Down Expand Up @@ -103,6 +105,7 @@ def apply(self, player_id: int, action: Tuple[int, int, int] | None) -> None:
assert action[1] >= 0 and action[1] < self.height
assert action[2] >= 0 and action[2] < 4

curr_player: Player
if player_id == 0:
curr_player = self.player1
else:
Expand Down
11 changes: 6 additions & 5 deletions clash_royale/envs/game_engine/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ class Player():
"""

def __init__(self,
deck: List[Card]) -> None:
deck: List[Card],
fps: int) -> None:
"""
Player component is initialized with deck of string,
specifying the cards' names in the deck.
"""

self.elixir: int = 0
self.fps: int = fps

random.shuffle(deck)
self.deck: Queue = Queue(maxsize = 8)
Expand Down Expand Up @@ -51,15 +53,14 @@ def get_pseudo_legal_cards(self) -> list[Card]:

def step(self,
elixir_rate: float,
fps: int,
frame: int) -> None:
frames: int=1) -> None:
"""
Called with the value of elixir_rate and frame to update the elixir of player after 'frame' number of frames
to better customize the elixir_rate that can vary depends on game modes.
"""

self.elixir += (elixir_rate / fps) * frame
self.elixir += (elixir_rate / self.fps) * frames

def pop(self, card_index: int) -> None:

Expand Down Expand Up @@ -89,4 +90,4 @@ def play_card(self, card_index: int) -> None:
elixir_cost: float = self.hand[card_index].elixir_cost
assert(elixir_cost <= self.elixir)
self.pop(card_index)
self.elixir -= elixir_cost
self.elixir -= elixir_cost

0 comments on commit 34469dd

Please sign in to comment.