473,405 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

PERL Craps Game

This is my script it works fine but it comes out on my webpage as just text how can i change this around and make it so if i like click a button a 2 different numbers come up almost like the 2 dice and remember how much i make each roll. Is there anyway anyone can help me? I can show you what it looks like in the browser right now if you ask i can show you if that will help. Thanks i really need this because its a project i have to get finished. If anyone i mean anyone can help me i will be greatful.Thanks

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. # How many games would you like to roll?
  4. $iterations = 1000;
  5.  
  6. for ($count = $iterations; $count >= 1; $count--) {
  7.  
  8. print "$count \n";
  9.  
  10. # Bankroll per game. Rules are set up for a $5 bet on a 3x/4x/5x table.
  11. $bankroll = 200;
  12.  
  13. $rollcount = 0;
  14. $high = 200;
  15.  
  16. $itson = 1;
  17.  
  18. while ($itson == 1) {
  19.  
  20. $die1 = int(rand() * 6) + 1;
  21. $die2 = int(rand() * 6) + 1;
  22. $roll = $die1 + $die2;
  23. $rollcount = $rollcount + 1;
  24.  
  25. if ($roll == 7 || $roll == 11) {
  26. $bankroll = $bankroll + 5;
  27. # print "W $roll $bankroll $rollcount\n";
  28. if ($bankroll > $high) {
  29. $high = $bankroll;
  30. }
  31. }
  32.  
  33. elsif ($roll == 2 || $roll == 3 || $roll == 12) {
  34. $bankroll = $bankroll - 5;
  35. # print "L $roll $bankroll $rollcount\n";
  36. }
  37.  
  38. else {
  39. $setnum = $roll;
  40. $notcrapped = 1;
  41. while ($notcrapped == 1) {
  42.  
  43. $die1 = int(rand() * 6) + 1;
  44. $die2 = int(rand() * 6) + 1;
  45. $roll = $die1 + $die2;
  46. $rollcount = $rollcount + 1;
  47.  
  48. if ($roll == $setnum) {
  49. $bankroll = $bankroll + 35;
  50. # print "W $roll $bankroll $rollcount\n";
  51. if ($bankroll > $high) {
  52. $high = $bankroll;
  53. }
  54. $notcrapped = 0;
  55. }
  56.  
  57. if ($roll == 7) {
  58.  
  59. if ($setnum == 4 || $setnum == 10) {
  60. $bankroll = $bankroll - 20;
  61. }
  62.  
  63. if ($setnum == 5 || $setnum == 9) {
  64. $bankroll = $bankroll - 25;
  65. }
  66.  
  67. if ($setnum == 6 || $setnum == 8) {
  68. $bankroll = $bankroll - 30;
  69. }
  70.  
  71. # print "L $roll $bankroll $rollcount\n";
  72. $notcrapped = 0;
  73. }
  74. }
  75. }
  76.  
  77. # Game ends when you have less than $5
  78. if ($bankroll < 5) {
  79. $losses = $losses + 1;
  80. $itson = 0;
  81. }
  82.  
  83. # It also ends if youmake $1000
  84. if ($bankroll >= 1000) {
  85. $wins = $wins + 1;
  86. $itson = 0;
  87. }
  88.  
  89. }
  90.  
  91. if ($high > $biggest) {
  92. $biggest = $high;
  93. }
  94.  
  95. if ($rollcount > $mostrolls) {
  96. $mostrolls = $rollcount;
  97. }
  98.  
  99. $bigrollcount = $bigrollcount + $rollcount;
  100. $bighigh = $bighigh + $high;
  101.  
  102. }
  103.  
  104. print "$iterations Iterations \n";
  105. print "Ave Rollcounts: " . sprintf("%.3f", $bigrollcount/$iterations) . "\n";
  106. print "Ave Rollcounts Hours: " . sprintf("%.3f", int($bigrollcount/$iterations)/180) . "\n";
  107. print "Most Rollcounts: $mostrolls\n";
  108. # Most Rollcounts Days assumes 3 rolls/minute.
  109. print "Most Rollcounts Days: " . sprintf("%.3f", ($mostrolls/180)/24) ."\n";
  110. print "Ave Most Won: " . ($bighigh/$iterations) . "\n";
  111. print "Biggest Win: $biggest\n";
  112. print "$wins Wins | $losses Losses";
  113.  
  114.  
Nov 21 '09 #1
18 4284
no one can help me with what im looking for? i want kind of like a form so when i click something 2 numbers come up and according to the rules if i get a certain number i win and if i dont i lose. Also something that will keep track of how much i win and if i get to $1000 game over and if i get to $5 dollars the game is over.
Nov 23 '09 #2
numberwhun
3,509 Expert Mod 2GB
First, please be patient. I know you posted this on Saturday, but considering everyone here are volunteers, people tend to do other things on the weekend.

As far as your script goes, if you are wanting this to print to your browser, then you need to make sure that your web server is setup to execute Perl scripts as cgi. You should reference documentation for whatever web server you are using.

I don't know what extension you have on your script (whether it is .pl or .cgi), but if you don't tell your web server to execute it, it will just display the script as text.

There are probably some Perl CGI tutorials you can reference as well for learning Perl CGI.


Regards,

Jeff
Nov 23 '09 #3
This is the site: http://ctech.smccme.edu/~rhodge/cw/c...i-bin/craps.pl

i want like some type of button or something so when i click it the two numbers come up resembling a dice and then it shows me if i win or lose and if i win i get money and if i lose i lose moeny thats as simple as it needs to be.

How do i tell it to execute it? Im like running my own web server so.
Nov 23 '09 #4
numberwhun
3,509 Expert Mod 2GB
I hate to say this, but this sounds too much like a homework problem for me to just give you the code. You are going to have to do the legwork. If you do not know how to display information in the browser from Perl, I again suggest you go through a CGI tutorial.

As for displaying dice for the numbers, you will need pics of each side in order to do that and display the correct dice based on the numbers rolled.

Regards,

Jeff
Nov 24 '09 #5
Well the script i have up top i now know is only for shell command line program. But for just wanting a button and when i click it the pictures change and by that number either i win or lose. Im just trying to figure out how to even start this. Thanks for replying jeff
Nov 24 '09 #6
numberwhun
3,509 Expert Mod 2GB
What you are looking to do in order to produce the output you are looking for, is to write some CGI code. With the CGI module, you can produce HTML output to have displayed in a browser. Using that code, you can write Perl code to input the name of an image depending on the number rolled. (That's just an idea, btw, on how to do the dice pictures).

I would definitely go over to CPAN and learn the CGI module. You will then understand how to create a web page with Perl.

Regards,

Jeff
Nov 24 '09 #7
Ya i'd have to save images of all sides of the dice and depending on what get's rolled it can tell me if i win or lose thats what im looking for your on the right topic but where would i input the "button" and images into this code
Nov 24 '09 #8
numberwhun
3,509 Expert Mod 2GB
CGI outputs HTML. Do you know HTML? If not, I suggest a tutorial on that as well.

Regards,

Jeff
Nov 25 '09 #9
If this helps i want something just like this..

http://ctech.smccme.edu/~zeke/cw/save/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.
Dec 3 '09 #10
numberwhun
3,509 Expert Mod 2GB
The script that you showed more than likely outputs the html using a CGI module. What you are asking to do should not be that hard, but will require a little work. The hardest part is the processing behind the scenes.

But, you didn't tell us whether this is homework or a class project? They usually assign remedial projects like these to get you used to coding and concepts. Is this homework or a class project?

Regards,

Jeff
Dec 3 '09 #11
Project why? I'll show you my code if you want and maybe then you can help me
Dec 3 '09 #12
Im not quite done with the calculations yet or if i even need them?


Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. use CGI ':standard';
  3. use CGI::Carp "fatalsToBrowser";
  4.  
  5. print header;
  6.  
  7. &form;
  8. &input;
  9. &cal;
  10.  
  11. ######sub routines#########
  12.  
  13. sub form{
  14.  
  15. print"
  16.  
  17. <form method=post action=craps.pl>
  18. <input type=hidden name=dice1 value=dice1>
  19. <input type=hidden name=dice2 value=dice2>
  20. <input type=hidden name=total value=total>
  21. <input type=hidden name=ctrl value=crtl>
  22. <input type=submit value='Throw Again'>
  23. </form>
  24.  
  25. <img src=images/1.gif><img src=images/3.gif><hr>
  26. <img src=images/blank.gif><img src=images/blank.gif>
  27.  
  28. ";
  29.  
  30. ######param###############
  31.  
  32. sub input{
  33.  
  34. $dice1=param('dice1');
  35. $dice2=param('dice2');
  36. $total=param('total');
  37. $ctrl=param('ctrl');
  38.  
  39. }
  40.  
  41. #######calculations########
  42.  
  43. sub cal{
  44.  
  45. ($dice1+$dice2);
  46.  
  47. }
Dec 3 '09 #13
RonB
589 Expert Mod 512MB
numberwhun FYI this Q is cross posted in several other forums.

http://codingforums.com/showthread.php?t=183612
http://forums.devshed.com/perl-progr...me-655550.html
http://forums.devshed.com/perl-progr...me-657929.html

and probably several others

BTW, I'm aka FishMonger
Dec 3 '09 #14
and yet no one has helped me yet
Dec 4 '09 #15
RonB
589 Expert Mod 512MB
We've helped, but it appears to me that you're looking for someone to do your assignment for you.

You're in a college course. One would assume that you would have learned enough study skills to take the info that we've given you and work out some of the details on your own, test some code, and then ask followup questions on the parts you don't understand.

Your original question on devshed included a complete, and I assume, working script that was designed as a console program. You can take that script and with little effort alter the print statements for use in a web version.
Dec 4 '09 #16
Im not using that script anymore i have made my own i just need to know how when i click the submit button to make the 2 images change through 6 random ones.
Dec 4 '09 #17
numberwhun
3,509 Expert Mod 2GB
@RonB Thanks for letting me know about those other postings. They certainly answered a question or two that have gone unanswered. Also Ron, please check your PMs.

@Rhodge09 From looking at the other links, I see you admitted in another forum that this is definitely school work. If you read the forum rules, you will see that you cannot expect answers to homework/school work. But, we will certainly guide you in the right direction.

That said, I see your code and it looks like you are off to a start. As far as the calculations go, if you don't write them, Perl won't do it for you. This code should include all it needs to run. If you already had a working script on the command line, then you just need to add the CGI parts to it to get it to where you want.

(By the way, what's wrong with command line output programs? :) )

Anywho, try to incorporate your code and if you have any issues, please ask questions. Also, do not forget to "use strict;" and "use warnings;".

Regards,

Jeff
Dec 4 '09 #18
I predict Rhodge drops the class and switches majors before the year is over. Can't handle perl scripting? Come now! Show some effort!
Dec 11 '09 #19

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Greg | last post by:
We're looking for CGI/PERL programmer who can help us integrate CamFrogWeb's video conferencing software with our site's user management system (login system) Our site uses customized...
6
by: tigrfire | last post by:
I've been working on a program to try and play a game of Craps, based on a version I found elsewhere - I didn't code the original, but I added a few things such as a balance and wager system. I'm...
1
by: nemesis | last post by:
help!!! IMy problem is that I don't know how to make the increase/decrease part work. The specification given to me by my teacher was: if the layer wins, double the wager (done!), and if loses ,...
1
by: lblock | last post by:
i have this code that plays the game of craps, but i need to be able to take how much they brought and how much they want to bet. show the number on the dice and tell them it they won or lose and...
2
by: mer000 | last post by:
Can you guys help me out? I'm trying to create a very simple game of craps but having some trouble. Below are the rules and requirements. Much appreciated! Given the following rules for the game...
3
by: whitehatmiracle | last post by:
SOS When i comile this program, im getting 13 errors all saying "prompt_for_bet and get_bet are not memebers of class Player" Where am i going wrong? Can anyone plzz enlighten me? Thnking u...
1
by: Shark2026 | last post by:
Hi there I need to make a Craps game for my class. Here are the parameters for it. In the game of craps, a pass line bet proceeds as follows. Two six-sided dice are rolled; the first roll of the...
3
by: boardwiz | last post by:
On the youtube video "best winning craps system # 1 the guy say you can play Craps like it were Chess. Is this true?
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.