func (g *Game) handleAddPlayer(ctx context.Context, m message.Message, send messageSender) error {
	newTiles := g.unusedTiles[:g.NumNewTiles]
	g.unusedTiles = g.unusedTiles[g.NumNewTiles:]
	b, err := m.Game.Board.Config.New(newTiles)
	if err != nil {
		return err
	}
	p, err := g.PlayerCfg.New(b)
	if err != nil {
		return fmt.Errorf("creating player: %w", err)
	}
	g.players[m.PlayerName] = p
	m2, err := g.resizeBoard(m)
	if err != nil {
		return fmt.Errorf("creating board message: %w", err)
	}
	m2.Info = "joining game"
	send(*m2)
	gamePlayers := m2.Game.Players
	for n := range g.players { // send info to other players
		if n == m.PlayerName {
			continue
		}
		m3 := message.Message{
			Type:       message.ChangeGameTiles,
			PlayerName: n,
			Info:       fmt.Sprintf("%v joined the game", m.PlayerName),
			Game: &game.Info{
				TilesLeft: len(g.unusedTiles),
				Players:   gamePlayers,
			},
		}
		send(m3)
	}
	g.handleInfoChanged(send)
	return nil
}
// handleAddPlayer adds the player to the game.
handleAddPlayer adds the player to the game.
// handleAddPlayer adds the player to the game .
func (g *Game) handleAddPlayer(ctx context.Context, m message.Message, send messageSender) error {
	newTiles := g.unusedTiles[:g.NumNewTiles]
	g.unusedTiles = g.unusedTiles[g.NumNewTiles:]
	b, err := m.Game.Board.Config.New(newTiles)
	if err != nil {
		return err
	}
	p, err := g.PlayerCfg.New(b)
	if err != nil {
		return fmt.Errorf("creating player: %w", err)
	}
	g.players[m.PlayerName] = p
	m2, err := g.resizeBoard(m)
	if err != nil {
		return fmt.Errorf("creating board message: %w", err)
	}
	m2.Info = "joining game"
	send(*m2)
	gamePlayers := m2.Game.Players
	for n := range g.players { 
		if n == m.PlayerName {
			continue
		}
		m3 := message.Message{
			Type:       message.ChangeGameTiles,
			PlayerName: n,
			Info:       fmt.Sprintf("%v joined the game", m.PlayerName),
			Game: &game.Info{
				TilesLeft: len(g.unusedTiles),
				Players:   gamePlayers,
			},
		}
		send(m3)
	}
	g.handleInfoChanged(send)
	return nil
}
func ( g * Game ) handleAddPlayer ( ctx context . Context , m message . Message , send messageSender ) error { newTiles := g . unusedTiles [ : g . NumNewTiles ] g . unusedTiles = g . unusedTiles [ g . NumNewTiles : ] b , err := m . Game . Board . Config . New ( newTiles ) if err != nil { return err } p , err := g . PlayerCfg . New ( b ) if err != nil { return fmt . Errorf ( " " , err ) } g . players [ m . PlayerName ] = p m2 , err := g . resizeBoard ( m ) if err != nil { return fmt . Errorf ( " " , err ) } m2 . Info = " " send ( * m2 ) gamePlayers := m2 . Game . Players for n := range g . players { if n == m . PlayerName { continue } m3 := message . Message { Type : message . ChangeGameTiles , PlayerName : n , Info : fmt . Sprintf ( " " , m . PlayerName ) , Game : & game . Info { TilesLeft : len ( g . unusedTiles ) , Players : gamePlayers , } , } send ( m3 ) } g . handleInfoChanged ( send ) return nil }
handleAddPlayer adds the player to the game.
handleAddPlayer adds the player to the game .
// send info to other players