RRebois / ft_transcendence

1 stars 1 forks source link

Purrinha #28

Open RhesusP opened 3 weeks ago

RhesusP commented 3 weeks ago

Les deux joueurs choisissent un nombre entre 0 et 3 x le nombre de joueurs.

Les deux joueurs choisissent un deuxieme nombre entre 0 et 6.

Lorsqu'un joueur choisi un chiffre, son choix est affiché aux autres joueurs.

En cas d'égalité, les joeurs ne gagnent pas de point. La victoire est concédée au premier ayant 3 points.

Les parties à 4 joueurs ne sont pas des 2v2

https://github.com/RRebois/ft_transcendence/blob/BackthreeJS2nd/frontend/app/js/functions/websocket.js

RhesusP commented 23 hours ago

Remote game flow:

All players can asynchronously choose a number between 0 and 3. When a player choose a number, its frontend send the following websocket message :

{
  action: "pick_initial_number"
  player_id
  player_username
  selected_value
  session_id
  game_code
}

When the current player send its sum guess, it sends :

{
  action: "sum_guessed"
  session_id
  game_code
  player_id : `id of the player sending his guess`
  player_username : `username of the player sending his guess`
  selected_value: `value selected by the player`
}
FelipeBelfort commented 3 hours ago

The game has been adapted to the frontend messages.

While waiting all the players for the match the back sends for each player:

awaited_players: int
connected_players: int
game: game name
game_state: "waiting"
players: {
          username: {id: int, connected: true},
}
session_id: str
status: "waiting"
tournament_id: (always null for purrinha)
winner: str or null

After all players joined the match

awaited_players: int
connected_players: int
game: game name
game_state: {
        available_to_guess: array of int 
        error_message: null or str in case of an error 
        history:{
               username: int (won sets), username: int (won sets)
         }
        players:{
                  player1: {name: username, quantity: bool(already chosen or not) or int(if round == "finished"), 
                  guess: int(-1 if not exists else the guess number)}, 
         }
         result: "waiting" (or the sum of the initial numbers if round == "finished")
         round: "choosing" -> if all players had picked a number "guessing" -> if all actions are make "finished"
         player_turn: int (the id of the player to pick a guess)
         winner: "waiting" or "tie" or "username" (here is the winner of the set)
}
players: {
        username: {id: int, connected: true},
}
session_id: str
status: "started"
tournament_id: (always null for purrinha)
winner: str or null (here is the winner of the whole match)

After each action the 'game_state' will be updated and send to all While there is no match winner it will reset the player's data to relaunch the game