Morpion solitaire: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
SqrtNegInf (talk | contribs) m (→{{header|Perl}}: future-proof for 5.36, use new bitwise string operator) |
||
Line 994: | Line 994: | ||
Picks a move at random from all possible moves at each step. A sample game is shown. |
Picks a move at random from all possible moves at each step. A sample game is shown. |
||
The largest score found so far (from just random play) is 92, also shown below. |
The largest score found so far (from just random play) is 92, also shown below. |
||
<syntaxhighlight lang="perl"> |
<syntaxhighlight lang="perl">use strict; |
||
use strict; # https://rosettacode.org/wiki/Morpion_solitaire |
|||
use warnings; |
use warnings; |
||
use List::Util qw( none ); |
use List::Util qw( none ); |
||
Line 1,145: | Line 1,143: | ||
move count: 92 |
move count: 92 |
||
</pre> |
</pre> |
||
A faster, shorter version without the single step display. |
A faster, shorter version without the single step display. |
||
<br> |
|||
Uses the same kind of block shift/or technology I used in "Forest fire" and have used |
Uses the same kind of block shift/or technology I used in "Forest fire" and have used |
||
for Conway's Life. |
for Conway's Life. |
||
<syntaxhighlight lang="perl"> |
<syntaxhighlight lang="perl">use strict; |
||
use strict; # https://rosettacode.org/wiki/Morpion_solitaire |
|||
use warnings; |
use warnings; |
||
use |
use feature 'bitwise'; |
||
use List::Util 'none'; |
|||
local $_ = <<END; |
local $_ = <<END; |
||
Line 1,169: | Line 1,166: | ||
$_ = tr/X./ /r . tr/./ /r . tr/X./ /r; # expand to 30x30 and spaces |
$_ = tr/X./ /r . tr/./ /r . tr/X./ /r; # expand to 30x30 and spaces |
||
my @moves; |
my($count, @moves, %used) = 0; |
||
my %used; |
|||
my $count = 0; |
|||
while( 1 ) |
while( 1 ) |
||
{ |
{ |
||
Line 1,177: | Line 1,172: | ||
for my $i ( 1, 30 .. 32 ) # directions 1 - 30 / 31 | 32 \ |
for my $i ( 1, 30 .. 32 ) # directions 1 - 30 / 31 | 32 \ |
||
{ |
{ |
||
my $combined = tr/X \n/A\0/r | |
my $combined = tr/X \n/A\0/r |. |
||
(substr $_, $i) =~ tr/X \n/B\0/r | |
(substr $_, $i) =~ tr/X \n/B\0/r |. |
||
(substr $_, 2 * $i) =~ tr/X \n/D\0/r | |
(substr $_, 2 * $i) =~ tr/X \n/D\0/r |. |
||
(substr $_, 3 * $i) =~ tr/X \n/H\0/r | |
(substr $_, 3 * $i) =~ tr/X \n/H\0/r |. |
||
(substr $_, 4 * $i) =~ tr/X \n/P\0/r; |
(substr $_, 4 * $i) =~ tr/X \n/P\0/r; |
||
while( $combined =~ /[OW\[\]\^]/g ) # exactly four Xs and one space |
while( $combined =~ /[OW\[\]\^]/g ) # exactly four Xs and one space |