Morpion solitaire: Difference between revisions
→{{header|Wren}}: Minor tidy and fixed problem with 'mvprintw' now requiring a format specifier.
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
(→{{header|Wren}}: Minor tidy and fixed problem with 'mvprintw' now requiring a format specifier.) |
||
(One intermediate revision by one other user not shown) | |||
Line 994:
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.
<syntaxhighlight lang="perl">
use warnings;
use List::Util qw( none );
Line 1,145 ⟶ 1,143:
move count: 92
</pre>
A faster, shorter version without the single step display.
Uses the same kind of block shift/or technology I used in "Forest fire" and have used
for Conway's Life.
<syntaxhighlight lang="perl">
use warnings;
use
use List::Util 'none';
local $_ = <<END;
Line 1,169 ⟶ 1,166:
$_ = tr/X./ /r . tr/./ /r . tr/X./ /r; # expand to 30x30 and spaces
my($count, @moves, %used) = 0;
while( 1 )
{
Line 1,177 ⟶ 1,172:
for my $i ( 1, 30 .. 32 ) # directions 1 - 30 / 31 | 32 \
{
my $combined = tr/X \n/A\0/r |.
(substr $_, $i) =~ tr/X \n/B\0/r |.
(substr $_, 2 * $i) =~ tr/X \n/D\0/r |.
(substr $_, 3 * $i) =~ tr/X \n/H\0/r |.
(substr $_, 4 * $i) =~ tr/X \n/P\0/r;
while( $combined =~ /[OW\[\]\^]/g ) # exactly four Xs and one space
Line 1,694 ⟶ 1,689:
{{libheader|Wren-fmt}}
An embedded program so we can use the ncurses library.
<syntaxhighlight lang="
import "random" for Random
Line 1,938 ⟶ 1,933:
<br>
We now embed the above script in the following C program, build and run it.
<syntaxhighlight lang="c">/* gcc
#include <stdio.h>
Line 1,982 ⟶ 1,977:
int x = (int)wrenGetSlotDouble(vm, 2);
const char *str = wrenGetSlotString(vm, 3);
mvprintw(y, x, "%s", str);
}
Line 2,079 ⟶ 2,074:
WrenVM* vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
|