func (g *Game) handleGameSwap(ctx context.Context, m message.Message, send messageSender) error {
	switch {
	case g.status != game.InProgress:
		return gameWarningNotInProgress
	case len(m.Game.Board.UnusedTiles) != 1:
		return gameWarning("no tile specified for swap")
	case len(g.unusedTiles) == 0:
		return gameWarning("no tiles left to swap, user what you have to finish")
	}
	tid := m.Game.Board.UnusedTileIDs[0]
	t := m.Game.Board.UnusedTiles[tid]
	p := g.players[m.PlayerName]
	if err := p.Board.RemoveTile(t); err != nil {
		return err
	}
	g.unusedTiles = append(g.unusedTiles, t)
	g.ShuffleUnusedTilesFunc(g.unusedTiles)
	var newTiles []tile.Tile
	for i := 0; i < 3 && len(g.unusedTiles) > 0; i++ {
		newTiles = append(newTiles, g.unusedTiles[0])
		if err := p.Board.AddTile(g.unusedTiles[0]); err != nil {
			return err
		}
		g.unusedTiles = g.unusedTiles[1:]
	}
	for n := range g.players {
		m2 := message.Message{
			Type:       message.ChangeGameTiles,
			PlayerName: n,
			Game: &game.Info{
				TilesLeft: len(g.unusedTiles),
			},
		}
		switch {
		case n == m.PlayerName:
			m2.Info = fmt.Sprintf("swapping %v tile", string(t.Ch))
			m2.Game.Board = board.New(newTiles, nil)
		default:
			m2.Info = fmt.Sprintf("%v swapped a tile", m.PlayerName)
		}
		send(m2)
	}
	return nil
}
// handleGameSwap swaps a tile for the player for three others, if possible.
handleGameSwap swaps a tile for the player for three others, if possible.
// handleGameSwap swaps a tile for the player for three others if possible .
func (g *Game) handleGameSwap(ctx context.Context, m message.Message, send messageSender) error {
	switch {
	case g.status != game.InProgress:
		return gameWarningNotInProgress
	case len(m.Game.Board.UnusedTiles) != 1:
		return gameWarning("no tile specified for swap")
	case len(g.unusedTiles) == 0:
		return gameWarning("no tiles left to swap, user what you have to finish")
	}
	tid := m.Game.Board.UnusedTileIDs[0]
	t := m.Game.Board.UnusedTiles[tid]
	p := g.players[m.PlayerName]
	if err := p.Board.RemoveTile(t); err != nil {
		return err
	}
	g.unusedTiles = append(g.unusedTiles, t)
	g.ShuffleUnusedTilesFunc(g.unusedTiles)
	var newTiles []tile.Tile
	for i := 0; i < 3 && len(g.unusedTiles) > 0; i++ {
		newTiles = append(newTiles, g.unusedTiles[0])
		if err := p.Board.AddTile(g.unusedTiles[0]); err != nil {
			return err
		}
		g.unusedTiles = g.unusedTiles[1:]
	}
	for n := range g.players {
		m2 := message.Message{
			Type:       message.ChangeGameTiles,
			PlayerName: n,
			Game: &game.Info{
				TilesLeft: len(g.unusedTiles),
			},
		}
		switch {
		case n == m.PlayerName:
			m2.Info = fmt.Sprintf("swapping %v tile", string(t.Ch))
			m2.Game.Board = board.New(newTiles, nil)
		default:
			m2.Info = fmt.Sprintf("%v swapped a tile", m.PlayerName)
		}
		send(m2)
	}
	return nil
}
func ( g * Game ) handleGameSwap ( ctx context . Context , m message . Message , send messageSender ) error { switch { case g . status != game . InProgress : return gameWarningNotInProgress case len ( m . Game . Board . UnusedTiles ) != 1 : return gameWarning ( " " ) case len ( g . unusedTiles ) == 0 : return gameWarning ( " " ) } tid := m . Game . Board . UnusedTileIDs [ 0 ] t := m . Game . Board . UnusedTiles [ tid ] p := g . players [ m . PlayerName ] if err := p . Board . RemoveTile ( t ) ; err != nil { return err } g . unusedTiles = append ( g . unusedTiles , t ) g . ShuffleUnusedTilesFunc ( g . unusedTiles ) var newTiles [ ] tile . Tile for i := 0 ; i < 3 && len ( g . unusedTiles ) > 0 ; i ++ { newTiles = append ( newTiles , g . unusedTiles [ 0 ] ) if err := p . Board . AddTile ( g . unusedTiles [ 0 ] ) ; err != nil { return err } g . unusedTiles = g . unusedTiles [ 1 : ] } for n := range g . players { m2 := message . Message { Type : message . ChangeGameTiles , PlayerName : n , Game : & game . Info { TilesLeft : len ( g . unusedTiles ) , } , } switch { case n == m . PlayerName : m2 . Info = fmt . Sprintf ( " " , string ( t . Ch ) ) m2 . Game . Board = board . New ( newTiles , nil ) default : m2 . Info = fmt . Sprintf ( " " , m . PlayerName ) } send ( m2 ) } return nil }
handleGameSwap swaps a tile for the player for three others, if possible.
handleGameSwap swaps a tile for the player for three others if possible .