Skip to content

Commit

Permalink
[功能] 每個回合不換位置只換初始玩家
Browse files Browse the repository at this point in the history
  • Loading branch information
teds-lin committed Feb 24, 2024
1 parent 2ac37f4 commit 00ae6af
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion backend/domain/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import List, Optional, Dict
from dataclasses import dataclass
from random import shuffle
from random import randint

from .player import Player
from .spell import Spell
Expand Down Expand Up @@ -111,7 +112,7 @@ def real_game_can_see(self, player_id: str) -> "Game":
return game_copy

def shuffle_player(self):
shuffle(self.players)
self.current_player = randint(0, len(self.players) - 1)

def to_dict(self) -> dict:
data = {
Expand Down
5 changes: 5 additions & 0 deletions backend/tests/unit/test_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ def test_real_game_can_see(game):
assert len(player_view.players[4].spells) == len(game.players[4].spells)


def test_shuffle_player(game):
game.shuffle_player()
assert game.current_player >= 0 and game.current_player < 5


def test_to_dict(game):
data = game.to_dict()

Expand Down

0 comments on commit 00ae6af

Please sign in to comment.