Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Battle script

by vladb (Vicar)
on Jun 06, 2002 at 13:01 UTC ( #172173=note: print w/replies, xml ) Need Help??


in reply to Battle script

Weird,

I believe one could come up with pretty much anything and it'll fit your description. Just the other day I wrote this line of code,
my $max_lines = 100; . . . while ($line--) { . . . # do stuff . . . }
So, basically, variable $max_lines leaves variable $line in the dumps if you consider $line-- as a variable loosing HP, {GRIN}.

UPDATE:

Or how abut this:
my $playera = 100; my $playerb = 100; print "player A HP | player B HP\n"; while (1) { $playera -= rand(10); $playerb -= rand(10); print "$playera | $playerb\n"; die (($playera < $playerb) ? "player A lost!" : "player B lost!") if ($playera < 0 || $playerb < 0); }
This 'game' playes out as follows:
player A HP | player B HP 94.0023803710938 | 99.3478393554688 88.4292602539063 | 96.0552978515625 88.1494140625 | 94.9520874023438 86.5380859375 | 93.8046264648438 82.1652221679688 | 84.6536254882813 75.5804443359375 | 76.0702514648438 69.7055053710938 | 75.4898071289063 67.3040771484375 | 68.40087890625 63.6215209960938 | 64.7930908203125 58.9315795898438 | 60.8502197265625 50.4647827148438 | 57.1435546875 40.8901977539063 | 49.0029907226563 34.7552490234375 | 39.5355224609375 27.4127197265625 | 33.8937377929688 24.0670776367188 | 31.5869140625 19.4973754882813 | 22.3440551757813 10.3622436523438 | 14.5086669921875 9.0966796875 | 11.1148071289063 7.37579345703125 | 9.4158935546875 2.77679443359375 | 0.14801025390625 -1.7657470703125 | -7.55615234375 player B lost! at temp.pl line 11.
you says: "The barer the bones, the better"

I guess my code is as 'bare' as you can get (unless some monk out there wants to challange me)! ;-)

_____________________
$"=q;grep;;$,=q"grep";for(`find . -name ".saves*~"`){s;$/;;;/(.*-(\d+) +-.*)$/; $_=["ps -e -o pid | "," $2 | "," -v "," "];`@$_`?{print"+ $1"}:{print" +- $1"}&&`rm $1`; print$\;}

Replies are listed 'Best First'.
Re: Re: Battle script
by Dog and Pony (Priest) on Jun 06, 2002 at 13:29 UTC
    A variation where the stronger one strikes (potentially)harder (and the one that gets the upper hand has the advantage):
    > perl -e "$a=$b=100;while($a>0&&$b>0){$a-=rand($b/10);$b-=rand($a/10) +;print qq($a | $b\n)}"

    You have moved into a dark place.
    It is pitch black. You are likely to be eaten by a grue.
      Oh no! You have inadvertantly tipped the scale of battle to favour the a opponent by the fact of its first attack and the effect which this has on the probability (random seed) for the retalitory attack of b - But what if the battle forces of b launch a preemptory attack?

      Consider the following where Quantum::Entanglement has been used such that the victor is truly not known until the battle has been fought!

      #!/usr/bin/perl use Quantum::Entanglement; my $opponent1 = entangle(1, 'a', 1, 'b'); my $opponent2 = p_op($opponent1, 'eq', 'a', sub{'b'}, sub{'a'}); $a = $b = 100; $opponent1 = "$opponent1"; $opponent2 = "$opponent2"; { no strict 'refs'; while ($$opponent1 > 0 && $$opponent2 > 0){ $$opponent1 -= rand($$opponent2 / 10); $$opponent2 -= rand($$opponent1 / 10); print qq($$opponent1 | $$opponent2\n) } print "And the winner is ... '", (($$opponent1 < 0) ? $opponent1 : $opponent2), "'\n"; }

      Yes, I was bored :-)

       

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://172173]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2021-07-28 06:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?