func (b *Board) Resize(cfg Config) (*ResizeResult, error) {
	usedTilePositions := make([]tile.Position, 0, len(b.UsedTiles))
	var movedTiles []tile.Tile
	for _, tp := range b.UsedTiles {
		switch {
		case cfg.NumCols <= int(tp.X), cfg.NumRows <= int(tp.Y):
			if err := b.RemoveTile(tp.Tile); err != nil {
				return nil, err
			}
			if err := b.AddTile(tp.Tile); err != nil {
				return nil, err
			}
			movedTiles = append(movedTiles, tp.Tile)
		default:
			usedTilePositions = append(usedTilePositions, tp)
		}
	}
	b.Config = cfg
	sort.Slice(usedTilePositions, func(i, j int) bool {
		a, b := usedTilePositions[i], usedTilePositions[j]
		// top-bottom, left-right
		switch {
		case a.Y == b.Y:
			return a.X < b.X
		default:
			return a.Y > b.Y
		}
	})
	unusedTiles := make([]tile.Tile, len(b.UnusedTiles))
	for i, id := range b.UnusedTileIDs {
		unusedTiles[i] = b.UnusedTiles[id]
	}
	rr := ResizeResult{
		Tiles:         unusedTiles,
		TilePositions: usedTilePositions,
	}
	if len(movedTiles) > 0 {
		rr.Info = "moving " + strconv.Itoa(len(movedTiles)) + " tile(s) to the unused area of the narrower/shorter board"
	}
	return &rr, nil
}
// Resize resizes the board to use the new config.  Any board size change information is returned in the message.
Resize resizes the board to use the new config.  Any board size change information is returned in the message.
// Resize resizes the board to use the new config . Any board size change information is returned in the message .
func (b *Board) Resize(cfg Config) (*ResizeResult, error) {
	usedTilePositions := make([]tile.Position, 0, len(b.UsedTiles))
	var movedTiles []tile.Tile
	for _, tp := range b.UsedTiles {
		switch {
		case cfg.NumCols <= int(tp.X), cfg.NumRows <= int(tp.Y):
			if err := b.RemoveTile(tp.Tile); err != nil {
				return nil, err
			}
			if err := b.AddTile(tp.Tile); err != nil {
				return nil, err
			}
			movedTiles = append(movedTiles, tp.Tile)
		default:
			usedTilePositions = append(usedTilePositions, tp)
		}
	}
	b.Config = cfg
	sort.Slice(usedTilePositions, func(i, j int) bool {
		a, b := usedTilePositions[i], usedTilePositions[j]
		switch {
		case a.Y == b.Y:
			return a.X < b.X
		default:
			return a.Y > b.Y
		}
	})
	unusedTiles := make([]tile.Tile, len(b.UnusedTiles))
	for i, id := range b.UnusedTileIDs {
		unusedTiles[i] = b.UnusedTiles[id]
	}
	rr := ResizeResult{
		Tiles:         unusedTiles,
		TilePositions: usedTilePositions,
	}
	if len(movedTiles) > 0 {
		rr.Info = "moving " + strconv.Itoa(len(movedTiles)) + " tile(s) to the unused area of the narrower/shorter board"
	}
	return &rr, nil
}
func ( b * Board ) Resize ( cfg Config ) ( * ResizeResult , error ) { usedTilePositions := make ( [ ] tile . Position , 0 , len ( b . UsedTiles ) ) var movedTiles [ ] tile . Tile for _ , tp := range b . UsedTiles { switch { case cfg . NumCols <= int ( tp . X ) , cfg . NumRows <= int ( tp . Y ) : if err := b . RemoveTile ( tp . Tile ) ; err != nil { return nil , err } if err := b . AddTile ( tp . Tile ) ; err != nil { return nil , err } movedTiles = append ( movedTiles , tp . Tile ) default : usedTilePositions = append ( usedTilePositions , tp ) } } b . Config = cfg sort . Slice ( usedTilePositions , func ( i , j int ) bool { a , b := usedTilePositions [ i ] , usedTilePositions [ j ] switch { case a . Y == b . Y : return a . X < b . X default : return a . Y > b . Y } } ) unusedTiles := make ( [ ] tile . Tile , len ( b . UnusedTiles ) ) for i , id := range b . UnusedTileIDs { unusedTiles [ i ] = b . UnusedTiles [ id ] } rr := ResizeResult { Tiles : unusedTiles , TilePositions : usedTilePositions , } if len ( movedTiles ) > 0 { rr . Info = " " + strconv . Itoa ( len ( movedTiles ) ) + " " } return & rr , nil }
Resize resizes the board to use the new config.
Resize resizes the board to use the new config .
// top-bottom, left-right