473,915 Members | 3,885 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PERL Craps Game

17 New Member
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 4317
Rhodge09
17 New Member
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 Recognized Expert Moderator Specialist
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
Rhodge09
17 New Member
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 Recognized Expert Moderator Specialist
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
Rhodge09
17 New Member
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 Recognized Expert Moderator Specialist
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
Rhodge09
17 New Member
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 Recognized Expert Moderator Specialist
CGI outputs HTML. Do you know HTML? If not, I suggest a tutorial on that as well.

Regards,

Jeff
Nov 25 '09 #9
Rhodge09
17 New Member
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

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

Similar topics

0
4735
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 vesrion of BAC software for our backend, see www.buildacommunity.com
6
2793
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 having trouble doing it all without using global variables though, so I have another post in this group about local variable usage and how to pass it, but just when I thought I'd got it, my program has a segmentation fault. I'm not exactly sure...
1
4918
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 , decrease the wager by the value entered by the player(done also!). fot each continuation of the game, the player must be asked if he wants to increase/ decrease the wager, he must enter a new value. otherwise the wager remains the same. (I can't do...
1
6685
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 what their money is after their roll. and have to ask if they want to play again. #include <iostream> #include <cstdlib> #include <time.h> using namespace std; const int NUM_GAMES = 10000;
2
3652
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 of Craps, simulate the play of a game, using the console to output the results of each roll and a WIN/LOSE message. Example output for a couple of runs is shown. The player rolls two 6-sided dice (hint: use 1 + (int)(Math.random() * 6) ) to...
3
1839
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 all in advance // gamble with Craps
1
8467
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 dice in a craps round is called the “come out roll.” A come out roll of 7 or 11 automatically wins, and a come out roll of 2, 3, or 12 automatically loses. If 4, 5, 6, 8, 9, or 10 is rolled on the come out roll, that number becomes “the point.” The...
3
3273
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
9883
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11359
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
11069
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10543
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9734
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5944
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4346
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3370
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.