Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Hi ;))

I was just browsing some of my old directories here,
and found my first 'do-it-myself-before-I-make-good-use-
of-Perl-program' ...

Its hashweeper, written the day after my two day perl
course, oh, sweet memories

Usage: X Y <ENTER></UL> X Y M <ENTER> for marking a hash(mine;))) or again for de-markin +g ;))<BR>
For your enjoyement, including the original debugging info
#!/usr/local/bin/perl -w use strict; sub CleanBoard($$); my @Board; for(my $i=0;$i<=21;++$i) { for(my $j=0;$j<=21;++$j) { $Board[$i][$j]={'Public'=>'*','Private'=>0}; }; }; sub InitBoard() { for(my $i=0;$i<50;++$i) { my($RandX,$RandY)=(rand(20)+1,rand(20)+1); redo if ($Board[$RandX][$RandY]{'Private'}==9); $Board[$RandX][$RandY]{'Private'}=9; }; for(my $j=1;$j<=20;++$j) { for(my $i=1;$i<=20;++$i) { next if ($Board[$i][$j]{'Private'}==9); for(my $y=$j-1;$y<=$j+1;++$y) { for(my $x=$i-1;$x<=$i+1;++$x) { ++$Board[$i][$j]{'Private'} if ($Board[$x][$y]{'Private'}==9); }; }; }; }; }; sub PrintBoard() { for(my $i=1;$i<=20;++$i) { print "\n$i\t"; for(my $j=1;$j<=20;++$j) { print "$Board[$i][$j]{'Public'} "; }; }; print "\nPlease give X and Y: "; }; sub CleanBoard($$) { my($x,$y)=@_; return if($Board[$x][$y]{'Public'} eq 'M'); return if(($x<1)||($x>20)||($y<1)||($y>20)); return if($Board[$x][$y]{'Private'}==9); return if($Board[$x][$y]{'Public'} ne '*'); $Board[$x][$y]{'Public'}=$Board[$x][$y]{'Private'}; return if($Board[$x][$y]{'Private'}!=0); print "I'm now in CleanBoard with X: $x, and Y: $y\n"; CleanBoard($x-1,$y); CleanBoard($x+1,$y); CleanBoard($x,$y-1); CleanBoard($x,$y+1); CleanBoard($x-1,$y-1); CleanBoard($x-1,$y+1); CleanBoard($x+1,$y-1); CleanBoard($x+1,$y+1); }; sub PlayGame() { while(<>) { chomp; my($y,$x,$Mark)=split; exit if($y eq "q"); if (($Mark)&&(lc($Mark) eq 'm')) { print "Got a mark!\n"; if ($Board[$x][$y]{'Public'} eq '*') { print "It even is a good one!!!\n"; $Board[$x][$y]{'Public'}='M'; } elsif ($Board[$x][$y]{'Public'} eq 'M') { $Board[$x][$y]{'Public'}='*'; }; PrintBoard(); next; }; if ($Board[$x][$y]{'Private'}==9) { print "BOOOOOOOOM!!!!!!!\n"; exit; }; CleanBoard($x,$y); PrintBoard(); }; }; InitBoard(); PrintBoard(); PlayGame();

Oh, don't worry... I got better at Perl ;)))

Rgrds,
    ChOas

    In reply to Hashsweeper, my first Perl program by ChOas

    Title:
    Use:  <p> text here (a paragraph) </p>
    and:  <code> code here </code>
    to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2019-03-18 17:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How do you Carpe diem?





    Results (85 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!