Powershell, 143 141 136136 130 bytes
-2 bytes: Yeah, one zero as delimiter is enough.
-5 bytes: The bottom zero border is enough.
$a=,0*5+($args|%{$_+0})+,0*5
for($n=16;$n){$a[($i=$a$n=16;$i=$a.IndexOf($n))]=0{$a[$i]=$n=0
[int]$n=-1,1+-6..-4+4..6|%6|?{$a[$i+$_]}|measure ($v=$a[$i+$_])-ma|% ma*gt$n}|%{$n=$v}}
$a|%{$s+=$_}
$s
$f = {
$a=,0*5+($args|%{$_+0})+,0*5
for($n=16;$n){
$i=$a$n=16;$i=$a.IndexOf($n)){
$a[$i]=0$a[$i]=$n=0
[int]$n=-1,1+-6..-4+4..6|%6|?{($v=$a[$i+$_])-gt$n}|%{
$a[$i+$_]$n=$v
}|measure -maximum|% maximum
}
$a|%{$s+=$_}
$s
}
@(
,( 0 , ( 4, 3, 2, 1), ( 5, 6, 7, 8), (12, 11, 10, 9), (13, 14, 15, 16) )
,( 0 , ( 8, 1, 9, 14), (11, 6, 5, 16), (13, 15, 2, 7), (10, 3, 12, 4) )
,( 1 , ( 1, 2, 3, 4), ( 5, 6, 7, 8), ( 9, 10, 11, 12), (13, 14, 15, 16) )
,( 3 , (10, 15, 14, 11), ( 9, 3, 1, 7), (13, 5, 12, 6), ( 2, 8, 4, 16) )
,( 12 , ( 3, 7, 10, 5), ( 6, 8, 12, 13), (15, 9, 11, 4), (14, 1, 16, 2) )
,( 34 , ( 8, 9, 3, 6), (13, 11, 7, 15), (12, 10, 16, 2), ( 4, 14, 1, 5) )
,( 51 , ( 8, 11, 12, 9), (14, 5, 10, 16), ( 7, 3, 1, 6), (13, 4, 2, 15) )
,( 78 , (13, 14, 1, 2), (16, 15, 3, 4), ( 5, 6, 7, 8), ( 9, 10, 11, 12) )
,( 102, ( 9, 10, 11, 12), ( 1, 2, 4, 13), ( 7, 8, 5, 14), ( 3, 16, 6, 15) )
,( 103, ( 9, 10, 11, 12), ( 1, 2, 7, 13), ( 6, 16, 4, 14), ( 3, 8, 5, 15) )
) | % {
$expected, $a = $_
$result = &$f @a
"$($result-eq$expected): $result"
}
FirstFirst, add righttop and bottom borders of 0 and make a single dimensional array:
#0 #0 #0 #0 0
# # # # 0
# # # # 0
# # # # 0
0# 0# 0# 0# 0
↓
#0 #0 #0 #0 0 # # # # 0 # # # # 0 # # # # 0 0# 0# 0# 0# 0
SecondPowershell returns $null if you try to get the value behind the end of the array.
Second, loop biggest neighbor pile started from 16 to non-zero-maximum. And nullify it (The Hungry Mouse eats it).
for($n=16;$n){
$i=$a$n=16;$i=$a.IndexOf($n)){
$a[$i]=0$a[$i]=$n=0
[int]$n=-1,1+-6..-4+4..6|%6|?{($v=$a[$i+$_])-gt$n}|%{
$a[$i+$_]$n=$v
}|measure -maximum|% maximum
}
ThirdThird, sum of the remaining piles.