sub GetMoves { my @Moves; for my $y (0..7) { for my $x (0..7) { if ($x != 7) { my $qualityR = TestMove(\@{$_[0]}, $x, $y, 'right'); if ($qualityR > 0) { push(@Moves, [$x, $y, $x+1, $y, $qualityR]) } } if ($y != 7) { my $qualityD = TestMove(\@{$_[0]}, $x, $y, 'down'); if ($qualityD > 0) { push(@Moves, [$x, $y, $x, $y+1, $qualityD]) } } } } return @Moves; } sub TestMove { foreach my $temparray (@{$_[0]}) { push(@TestFeld, [@$temparray]); } if ($_[3] eq 'right') { my $ToSwap = ${$TestFeld[$_[2]]}[$_[1]]; ${$TestFeld[$_[2]]}[$_[1]] = ${$TestFeld[$_[2]]}[$_[1]+1]; ${$TestFeld[$_[2]]}[$_[1]+1] = $ToSwap; } elsif ($_[3] eq 'down') { my $ToSwap = ${$TestFeld[$_[2]]}[$_[1]]; ${$TestFeld[$_[2]]}[$_[1]] = ${$TestFeld[$_[2]+1]}[$_[1]]; ${$TestFeld[$_[2]+1]}[$_[1]] = $ToSwap; } my $quality = GetQuality(\@TestFeld); undef @TestFeld; return $quality; } sub GetQuality { my $ref = $_[0]; my $quality = 0; for my $x (0..7) { my $string = join("", @{@$ref[$x]}); while ($string =~ m/(11111|1111|111)|(22222|2222|222)|(33333|3333|333)|(44444|4444|444)|(55555|5555|555)|(66666|6666|666)|(77777|7777|777)|(88888|8888|888)/g) { $quality += length($&); } undef $string; } for my $y (0..7) { my $string = ""; for my $z (0..7) { $string = $string . ${@$ref[$z]}[$y]; } while ($string =~ m/(11111|1111|111)|(22222|2222|222)|(33333|3333|333)|(44444|4444|444)|(55555|5555|555)|(66666|6666|666)|(77777|7777|777)|(88888|8888|888)/g) { $quality += length($&); } undef $string; } return $quality; }