mirror of
https://github.com/evgen-app/chess_rpg_backend.git
synced 2024-11-22 01:27:00 +03:00
fixed deck create, added function to generate room
This commit is contained in:
parent
71d811100b
commit
7e48242780
48
common/debug.py
Normal file
48
common/debug.py
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
from common.generators import gen_ton
|
||||||
|
from game.models import Player, Deck, Hero
|
||||||
|
from room.services.room_create import sync_create_room
|
||||||
|
|
||||||
|
|
||||||
|
def _check_players_score(players):
|
||||||
|
for player in players:
|
||||||
|
for player2 in players:
|
||||||
|
if player != player2:
|
||||||
|
s_min = players[player] * 0.95
|
||||||
|
s_max = players[player] * 1.05
|
||||||
|
if s_min <= players[player2] <= s_max:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def generate_room():
|
||||||
|
players = {}
|
||||||
|
|
||||||
|
for _ in range(2):
|
||||||
|
player = Player.objects.create(ton_wallet=gen_ton())
|
||||||
|
players[player] = player.get_last_deck().score()
|
||||||
|
|
||||||
|
while _check_players_score(players):
|
||||||
|
player = Player.objects.create(ton_wallet=gen_ton())
|
||||||
|
players[player] = player.get_last_deck().score()
|
||||||
|
|
||||||
|
for player in players:
|
||||||
|
for player2 in players:
|
||||||
|
if player != player2:
|
||||||
|
s_min = players[player] * 0.95
|
||||||
|
s_max = players[player] * 1.05
|
||||||
|
if s_min <= players[player2] <= s_max:
|
||||||
|
p1 = player
|
||||||
|
p2 = player2
|
||||||
|
|
||||||
|
room_slug = sync_create_room(
|
||||||
|
p1.get_last_deck().id,
|
||||||
|
p1.id,
|
||||||
|
players[p1],
|
||||||
|
p2.get_last_deck().id,
|
||||||
|
p2.id,
|
||||||
|
players[p2],
|
||||||
|
)
|
||||||
|
print(f"ws://127.0.0.1:8000/room/{room_slug}")
|
||||||
|
print(f"Authorization: {p1.get_access_token()}")
|
||||||
|
print(f"Authorization: {p2.get_access_token()}")
|
||||||
|
return None
|
|
@ -167,6 +167,7 @@ class HeroInDeck(models.Model):
|
||||||
db_table = "hero_in_deck"
|
db_table = "hero_in_deck"
|
||||||
verbose_name = "Hero in deck"
|
verbose_name = "Hero in deck"
|
||||||
verbose_name_plural = "Heroes in decks"
|
verbose_name_plural = "Heroes in decks"
|
||||||
|
ordering = ["y", "x"]
|
||||||
|
|
||||||
|
|
||||||
class PlayerAuthSession(models.Model):
|
class PlayerAuthSession(models.Model):
|
||||||
|
|
|
@ -9,9 +9,9 @@ def create_first_deck(player: Player):
|
||||||
|
|
||||||
for x in range(8):
|
for x in range(8):
|
||||||
for y in range(2):
|
for y in range(2):
|
||||||
if (x != 3 and y != 0) or (x != 4 and y != 0):
|
positions.append((x, y))
|
||||||
positions.append((x, y))
|
positions.remove((3, 0))
|
||||||
print(positions)
|
positions.remove((4, 0))
|
||||||
random.shuffle(positions)
|
random.shuffle(positions)
|
||||||
|
|
||||||
types = (
|
types = (
|
||||||
|
|
|
@ -6,15 +6,15 @@ from game.models import Player, Deck
|
||||||
from room.models import Room, PlayerInRoom, GameState, HeroInGame
|
from room.models import Room, PlayerInRoom, GameState, HeroInGame
|
||||||
|
|
||||||
|
|
||||||
@sync_to_async
|
def sync_create_room(
|
||||||
def create_room(
|
|
||||||
deck_id_1: int,
|
deck_id_1: int,
|
||||||
player_id_1: int,
|
player_id_1: int,
|
||||||
player_score_1: int,
|
player_score_1: int,
|
||||||
deck_id_2: int,
|
deck_id_2: int,
|
||||||
player_id_2: int,
|
player_id_2: int,
|
||||||
player_score_2: int,
|
player_score_2: int,
|
||||||
) -> str:
|
):
|
||||||
|
|
||||||
room = Room.objects.create(slug=generate_charset(16))
|
room = Room.objects.create(slug=generate_charset(16))
|
||||||
player_1 = Player.objects.get(id=player_id_1)
|
player_1 = Player.objects.get(id=player_id_1)
|
||||||
player_2 = Player.objects.get(id=player_id_2)
|
player_2 = Player.objects.get(id=player_id_2)
|
||||||
|
@ -58,3 +58,8 @@ def create_room(
|
||||||
y=8 - hero_in_deck.y,
|
y=8 - hero_in_deck.y,
|
||||||
)
|
)
|
||||||
return room.slug
|
return room.slug
|
||||||
|
|
||||||
|
|
||||||
|
@sync_to_async
|
||||||
|
def create_room(**kwargs):
|
||||||
|
return sync_create_room(**kwargs)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user