grendel25
grendel25
  • Threads: 1
  • Posts: 2
Joined: May 26, 2015
May 26th, 2015 at 4:35:29 PM permalink
Greetings. I registered just to ask this question. Thanks for any help:

I compiled the C++ source code found here:

It was my first compilation and all went swimmingly well. I ran some tests but ended up with more questions.

I don't really understand which variables I can change and I want to know if it's testing what I hope it's testing. I think I figured that I can change the "bet" variable in line '35' to whatever my bet size is. I also think that I can change the "bank" quantity on line '59' to be the actual amount of the bank. Is that right?

But... I have some bigger questions about the source code... Can I set it up to run a specific number set of bets to be cancelled? For example, I'm specifically interested to run the following cancellation:


1,1,2,2,2,1,1


What cancellation is it already doing? Any idea how I'd change it or manipulate to test different cancellation factors?

Here's the source code if it's easier than going to the link:



//
// cancellation system analyzer
// 10/19/1998
//

#include <iostream.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <stdio.h>

void tenbet();

int main()
{
char ch;

do
{
tenbet();

cerr << "Play again? ";
cin >> ch;
}
while ((ch == 'y') || (ch == 'Y'));

return 0;
}

void tenbet()
{
int maxloss, num, bet[1000], lpt, rpt, i, j, curbet, bank, result[2], randwin, g;

long totbet, spins;

cerr << "Enter maximum loss "; cin >> maxloss;
cerr << "Enter number of trials "; cin >> num;
cerr << "Roulette(1) or craps(2)? "; cin >> g;

result[0] = 0;
result[1] = 0;
totbet = 0;
spins = 0;

if (g == 1)
{
randwin = 32767 * 18/38;
}
else
{
randwin = 32767 * 244 / 495;
}

for (i = 1; i <= num; i++)
{
bank = 0;
lpt = 1;
rpt = 10;

for (j = 1; j <= 10; j++)
{
bet
= 1;
}

do
{
if (rpt == lpt)
{
curbet = bet[rpt];
}
else
{
curbet = bet[lpt] + bet[rpt];
}

while ((maxloss+bank < curbet)&&(maxloss+bank > 0))
{
spins++;

if (maxloss + bank >= bet[lpt])
{
totbet += bet[lpt];

if (rand() <= randwin)
{
bank += bet[lpt];
lpt++;
}
else
{
bank -= bet[lpt];
bet[lpt] *= 2;
}
}
else
{
totbet += (maxloss + bank);

if (rand() <= randwin)
{
bet[lpt] -= (maxloss + bank);
bank += (maxloss + bank);
}
else
{
bank -= (maxloss + bank);
}
}

if (rpt == lpt)
{
curbet = bet[rpt];
}
else
{
curbet = bet[lpt] + bet[rpt];
}
}

if (maxloss + bank > 0)
{
totbet+=curbet;
spins++;

if (rand() <= randwin)
{
lpt++;
rpt--;
bank += curbet;
}
else
{
rpt++;
bet[rpt] = curbet;
bank -= curbet;
}
}
}
while ((lpt <= rpt) && (maxloss + bank > 0));

if (maxloss + bank == 0)
{
result[1]++;
}
else
{
result[0]++;
}

if (i % 100000 == 0)
{
cerr << i << "\n";
}
}

cerr << "Maximum loss: " << maxloss << "\n";
cerr << "Probability of loss: " << (float)(result[1])/(float)(num) << "\n";
cerr << "Average spins: " << (float)(spins)/(float)(num) << "\n";
cerr << "Average bet: " << (float)(totbet)/(float)(num)<<"\n";
cerr << "Wins: " << result[0]<<"\nLosses: "<<result[1]<<"\n";
cerr << "Total bet: " << totbet<<"\n";
cerr << "Total win/loss: " << (result[0]*10)-(result[1]*maxloss) << "\n";
cerr << "Total spins: " << spins << "\n";
cerr << "Net loss: " << (float)((result[0]*10)-(result[1]*maxloss))/(float)totbet << "\n";
}

MathExtremist
MathExtremist
  • Threads: 88
  • Posts: 6526
Joined: Aug 31, 2010
May 26th, 2015 at 4:54:29 PM permalink
That compiled with no warnings? It looks like you're intending to set bet
=1 for j in [1..10] but you're missing the index. The line just says bet = 1 and it's almost always a bug to set an unindexed array variable to an integer. Especially in the context of the rest of the code, it doesn't look like you're trying to do pointer arithmetic.

I think you can get rid of that for j loop and manually initialize the bet array to be whatever numbers you want.

Edit, so it turns out that the array index just doesn't print in this forum. Ignore the first part of what I said and just replace the for j loop with a manual array init.
"In my own case, when it seemed to me after a long illness that death was close at hand, I found no little solace in playing constantly at dice." -- Girolamo Cardano, 1563
grendel25
grendel25
  • Threads: 1
  • Posts: 2
Joined: May 26, 2015
May 26th, 2015 at 5:14:59 PM permalink
Quote: MathExtremist

That compiled with no warnings? It looks like you're intending to set bet

=1 for j in [1..10] but you're missing the index. The line just says bet = 1 and it's almost always a bug to set an unindexed array variable to an integer. Especially in the context of the rest of the code, it doesn't look like you're trying to do pointer arithmetic.

I think you can get rid of that for j loop and manually initialize the bet array to be whatever numbers you want.

Edit, so it turns out that the array index just doesn't print in this forum. Ignore the first part of what I said and just replace the for j loop with a manual array init.



Oops... I did have to change some things. I had to get rid of the .h in line '6' and I had to add "using namespace std;" between the last #include line and the "void tenbet(); line.

I'm not really sure how to insert a manual array init. Can you show me what that would look like?
MathExtremist
MathExtremist
  • Threads: 88
  • Posts: 6526
Joined: Aug 31, 2010
May 26th, 2015 at 6:29:27 PM permalink
http://www.cplusplus.com/doc/tutorial/arrays/
"In my own case, when it seemed to me after a long illness that death was close at hand, I found no little solace in playing constantly at dice." -- Girolamo Cardano, 1563
  • Jump to: