Help on Craps Game (PERL scripting)

Simple Craps Game Using PERL

Page 1 of 1

6 Replies - 3132 Views - Last Post: 03 December 2009 - 10:31 AM

#1 Rhodge09   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 20-November 09

Help on Craps Game (PERL scripting)

Post icon  Posted 20 November 2009 - 12:32 PM

I have this code and im trying to make it so it can work in a browser but all that comes up is the text. What do i have to change so that this game actually works do i have to make forms or anything like that. I had someone say that i had to change it into PHP or CGI but i dont quite know how to do it.



#!/usr/bin/perl

# How many games would you like to roll?
$iterations = 1000;

for ($count = $iterations; $count >= 1; $count--) {

print "$count \n";

# Bankroll per game. Rules are set up for a $5 bet on a 3x/4x/5x table.
$bankroll = 200;

$rollcount = 0;
$high = 200;

$itson = 1;

while ($itson == 1) {

$die1 = int(rand() * 6) + 1;
$die2 = int(rand() * 6) + 1;
$roll = $die1 + $die2;
$rollcount = $rollcount + 1;

if ($roll == 7 || $roll == 11) {
$bankroll = $bankroll + 5;
# print "W $roll $bankroll $rollcount\n";
if ($bankroll > $high) {
$high = $bankroll;
}
}

elsif ($roll == 2 || $roll == 3 || $roll == 12) {
$bankroll = $bankroll - 5;
# print "L $roll $bankroll $rollcount\n";
}

else {
$setnum = $roll;
$notcrapped = 1;
while ($notcrapped == 1) {

$die1 = int(rand() * 6) + 1;
$die2 = int(rand() * 6) + 1;
$roll = $die1 + $die2;
$rollcount = $rollcount + 1;

if ($roll == $setnum) {
$bankroll = $bankroll + 35;
# print "W $roll $bankroll $rollcount\n";
if ($bankroll > $high) {
$high = $bankroll;
}
$notcrapped = 0;
}

if ($roll == 7) {

if ($setnum == 4 || $setnum == 10) {
$bankroll = $bankroll - 20;
}

if ($setnum == 5 || $setnum == 9) {
$bankroll = $bankroll - 25;
}

if ($setnum == 6 || $setnum == 8) {
$bankroll = $bankroll - 30;
}

# print "L $roll $bankroll $rollcount\n";
$notcrapped = 0;
}
}
}

# Game ends when you have less than $5
if ($bankroll < 5) {
$losses = $losses + 1;
$itson = 0;
}

# It also ends if youmake $1000
if ($bankroll >= 1000) {
$wins = $wins + 1;
$itson = 0;
}

}

if ($high > $biggest) {
$biggest = $high;
}

if ($rollcount > $mostrolls) {
$mostrolls = $rollcount;
}

$bigrollcount = $bigrollcount + $rollcount;
$bighigh = $bighigh + $high;

}

print "$iterations Iterations \n";
print "Ave Rollcounts: " . sprintf("%.3f", $bigrollcount/$iterations) . "\n";
print "Ave Rollcounts Hours: " . sprintf("%.3f", int($bigrollcount/$iterations)/180) . "\n";
print "Most Rollcounts: $mostrolls\n";
# Most Rollcounts Days assumes 3 rolls/minute.
print "Most Rollcounts Days: " . sprintf("%.3f", ($mostrolls/180)/24) ."\n";
print "Ave Most Won: " . ($bighigh/$iterations) . "\n";
print "Biggest Win: $biggest\n";
print "$wins Wins | $losses Losses";

Is This A Good Question/Topic? 0
  • +

Replies To: Help on Craps Game (PERL scripting)

#2 dsherohman   User is offline

  • Perl Parson
  • member icon

Reputation: 227
  • View blog
  • Posts: 654
  • Joined: 29-March 09

Re: Help on Craps Game (PERL scripting)

Posted 21 November 2009 - 06:59 AM

Note: For future reference, please enclose your code within [code] tags.

View PostRhodge09, on 20 Nov, 2009 - 07:32 PM, said:

I have this code and im trying to make it so it can work in a browser but all that comes up is the text. What do i have to change so that this game actually works do i have to make forms or anything like that. I had someone say that i had to change it into PHP or CGI but i dont quite know how to do it.

If you're getting the source code back when you access your code's URL, then, yes, the issue is that the web server is treating it as a plain text document rather than as a program to be executed.

You'll need to contact your web host about how to do this on their server, but the most common ways are to change the file's extension to .cgi or to move it into a /cgi-bin/ directory. You may also need to change the file's permissions on the server to make it executable.

If you control the web server yourself, please state the operating system and web server software you're using (e.g., Linux/Apache, Windows XP/IIS, etc.) and someone should be able to tell you how to configure that combination of OS/server to allow CGI execution.
Was This Post Helpful? 0
  • +
  • -

#3 Rhodge09   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 20-November 09

Re: Help on Craps Game (PERL scripting)

Posted 21 November 2009 - 11:24 AM

View Postdsherohman, on 21 Nov, 2009 - 05:59 AM, said:

Note: For future reference, please enclose your code within [code] tags.

View PostRhodge09, on 20 Nov, 2009 - 07:32 PM, said:

I have this code and im trying to make it so it can work in a browser but all that comes up is the text. What do i have to change so that this game actually works do i have to make forms or anything like that. I had someone say that i had to change it into PHP or CGI but i dont quite know how to do it.

If you're getting the source code back when you access your code's URL, then, yes, the issue is that the web server is treating it as a plain text document rather than as a program to be executed.

You'll need to contact your web host about how to do this on their server, but the most common ways are to change the file's extension to .cgi or to move it into a /cgi-bin/ directory. You may also need to change the file's permissions on the server to make it executable.

If you control the web server yourself, please state the operating system and web server software you're using (e.g., Linux/Apache, Windows XP/IIS, etc.) and someone should be able to tell you how to configure that combination of OS/server to allow CGI execution.




I put this at the top of the script and all that comes out is text on the webpage..this is the site : http://ctech.smccme....gi-bin/craps.pl


use CGI ':standard';
use CGI::Carp "fatalsToBrowser";

So you said i should move it into a cgi directory ya im controlling the web server myself so ya.

This post has been edited by Rhodge09: 21 November 2009 - 11:51 AM

Was This Post Helpful? 0
  • +
  • -

#4 Rhodge09   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 20-November 09

Re: Help on Craps Game (PERL scripting)

Posted 02 December 2009 - 10:08 PM

If this helps i want something just like this..

http://ctech.smccme..../craps/craps.pl

if you want the code i have as of right now and you think you can help me a little at a time i'd appreciate it.
Was This Post Helpful? 0
  • +
  • -

#5 dsherohman   User is offline

  • Perl Parson
  • member icon

Reputation: 227
  • View blog
  • Posts: 654
  • Joined: 29-March 09

Re: Help on Craps Game (PERL scripting)

Posted 03 December 2009 - 05:01 AM

As I said in my earlier response, if your browser is displaying the source code of your script when you access its URL, then this is a server configuration issue. It is not a Perl issue and no change to your Perl code can fix it because the web server is not executing the code.

Also as I said in my earlier response,

Quote

If you control the web server yourself, please state the operating system and web server software you're using (e.g., Linux/Apache, Windows XP/IIS, etc.) and someone should be able to tell you how to configure that combination of OS/server to allow CGI execution.

If we don't know what web server you're running, then we can't tell you how to configure it properly. (And, technically, as a server config issue, this probably belongs over in the Web Servers & Hosting forum. I'm sure you'll be able to get an answer here once you describe your server setup, but you might get one quicker over there.)
Was This Post Helpful? 0
  • +
  • -

#6 Rhodge09   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 20-November 09

Re: Help on Craps Game (PERL scripting)

Posted 03 December 2009 - 08:11 AM

Well i re did my code and it works now
Was This Post Helpful? 0
  • +
  • -

#7 Rhodge09   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 20-November 09

Re: Help on Craps Game (PERL scripting)

Posted 03 December 2009 - 10:31 AM

http://ctech.smccme..../craps/craps.pl

Thats my site
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1