Javascript (E6) 316 350 392 487 537 590
Board size limited to 6x6 to save runtime. With the same character count the limit could be 9x9. Any number of pieces
F=(d,b,h)=>{R=s=>[...s].reverse(),Q=(n,i,k)=>{h[n]&&[t=h[n][1],t[0].map((c,i)=>t.map(r=>r[i]))].map(e=>[e,R(e),e.map(R),R(e).map(R)].map(s=>{for(i=36;i--;)k=b.map(x=>[...x]),s.some((u,q)=>!(w=b[~~(i/6)+q])||u.some((v,p)=>(c=i%6+p,v&&!(v=w[c]!=1)&&!(w[c]=n+2)||v)))||Q(n+1),b=k}))||console.log(b.join('\n'))},Q(0)}
History
316 - Slooower! The board is copied again for each recursive call. (Ab)using slower functions chosen for shorter names. The main loop on board rows and colums coalesced into one for. Also put a limit for board size up to 6x6 (not for short code, but for acceptable runtime)
350 - Golfed using more array traversing function and less loops
392 - Algorithm not changed: try to place a piece, if ok try next, recursive, but
use arrays only and not strings and use a single global board and not copy it during recursion (so it must be able to put a piece AND to remove it)
...
Ungolfed a bit
F = (d,b,h)=>{
R = s => [...s].reverse(), // ... instead of slice that is faster
Q = (n,i,k) => // Recursive function, fake param i to avoid vars
{
h[n] && // If there is still a piece to place, try to place it
[t=h[n][1], t[0].map((c,i) => t.map(r => r[i]))]
.map(e => // for e in :piece, transposed piece
[e, R(e), e.map(R), R(e).map(R)]
.map(s =>
{ // for s in : base piece, reversed, mirrored, diagonal
for(i = 36; i--;) // 6x6: could be higher but slows down
k = b.map(x=>[...x]), // save copy of board (again ... instead of slice)
s.some( (u,q) => // traverse with 'some' to exit early if invalid position
!(w=b[~~(i/6)+q])
|| u.some((v,p) => (c=i%6+p, v && !(v=w[c]!=1) && !(w[c]=n+2)||v))
) || Q(n+1), // if piece place, recurse
b=k // recover the board from the copy
}
)) // if no more pieces, output result
|| console.log(b.join('\n' /** ,Q=_=>0 **/)) // remove comment to stop at first solution found
},
Q(0) // First call
}
Usage
Test in javascript console (Firefox)
Input parameters as array.
Time to finish is 50 sec on my PC, so Firefox will complain...
F(
[5,5],
[[1,1,0,0,0],[1,1,0,0,0],[1,1,1,0,1],[1,1,1,1,1],[0,0,1,1,1]],
[
[[2,4],[[1,0],[1,0],[1,1],[1,0]]],
[[1,2],[[1],[1]]],
[[2,3],[[0,1],[1,1],[0,1]]],
[[2,3],[[0,1],[1,1],[1,1]]]
])
Another test case:
F(
[6,5],
[[0,1,1,1,1,0],[1,1,1,1,1,0],[1,1,1,1,1,0],[0,1,1,1,1,0],[0,0,1,1,1,1]],
[
[[2,4],[[1,0],[1,0],[1,1],[1,1]]],
[[3,3],[[1,1,0],[0,1,1],[0,1,1]]],
[[3,3],[[0,0,1],[1,1,1],[1,0,0]]],
[[2,4],[[0,1],[1,1],[0,1],[0,1]]]
]
)
Output / 2+2 solutions found, firefox console skip repeated console output
0,2,2,2,2,0
3,3,4,2,2,0
3,3,4,4,4,0
0,3,3,5,4,0
0,0,5,5,5,5
0,4,4,2,2,0
3,3,4,2,2,0
3,3,4,4,2,0
0,3,3,5,2,0
0,0,5,5,5,5
[5,5],[[1,1,0,0,0],[1,1,0,0,0],[1,1,1,0,1],[1,1,1,1,1],[0,0,1,1,1]], [[[2,4],[1,0],[1,0],[1,1],[1,0]],[[1,2],[1],[1]],[[2,3],[0,1],[1,1],[0,1]],[[2,3],[0,1],[1,1],[1,1]]]
\$\endgroup\$