有将数字游戏



这个有奖数字游戏是街头赌博骗局,整体结果是庄家赢的概率大!

#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;

typedef struct result
{
 int num;
 int money;
}result;
#define result_statut_size 26
 
result result_statut[result_statut_size] = {
 {14,35},
 {15,5},
 {12,30},
 {11,5},
 {10,15},
 {19,5},
 {20,50},
 {7,5},
 {22,40},
 {30,5},
 {24,35},
 {29,5},
 {26,35},
 {27,-5},
 {28,35},
 {25,5},
 {5,10},
 {23,5},
 {6,5},
 {21,6},
 {8,50},
 {9,5},
 {18,35},
 {17,10},
 {16,15},
 {13,5}
};

#define success 1
#define fail 0
int find_result(int num, result **ppresult, int *pindex)
{
 for (int index =0;index<result_statut_size;++index)
 {
  if (result_statut[index].num == num)
  {
   *ppresult = result_statut +index;
   *pindex = index;
   return success;
  }
 }
 return fail;
}

#define LEFT 0
#define RIGHT 1
//0<=position<=result_statut_size-1
int ispay(const result *presult, int position, int LorR)
{
 int pos = presult->num%result_statut_size;
 if (LEFT == LorR)
 {
  //往左走
  if (pos > position + 1)
  {
   return result_statut[result_statut_size - 1 - (pos - position - 1) - 1].money;
  }
  else if (pos <= position + 1)
  {
   return result_statut[position - pos + 1].money;
  }
  else
  {
   printf("往左走error");
   exit(0);
  }
 }
 else
 {
  //往右走
  if ((position + pos - 1) > (result_statut_size - 1))
  {
   return result_statut[position + pos - result_statut_size - 1].money;
  }
  else if ((position + pos - 1) <= (result_statut_size - 1))
  {
   return result_statut[position + pos - 1].money;
  }
  else
  {
   printf("往右走error!");
   exit(0);
  }
 }
}

int gene_total = 0;//结果总数
int gene_result[5];//5个筛子的结果
int pay_way_total = 0;//需要支付给庄家的结果总数
void gene(int num)
{
 if (num <= 0)
 {
  return;
 }
 for (int i = 1; i <= 6; ++i)
 {
  gene_result[num-1] = i;
  gene(num - 1);
  if (0 == num - 1)
  {
   ++gene_total;
   //printf("%d\t%d\t%d\t%d\t%d\t%d\n", gene_result[0], gene_result[1], gene_result[2],  gene_result[3], gene_result[4], gene_total);
   result *ps;
   int position;
   if (success == find_result(gene_result[0] + gene_result[1] + gene_result[2] + gene_result[3] + gene_result[4],
    &ps, &position))
   {
    if (ispay(ps, position,LEFT) < 0)
    {
     pay_way_total += 1;
     printf("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\tLEFT\n", gene_result[0], gene_result[1], gene_result[2], gene_result[3], gene_result[4],
      gene_total,
      ps->num,
      ps->money,
      pay_way_total);
    }
    if (ispay(ps, position, RIGHT) < 0)
    {
     pay_way_total += 1;
     printf("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\tRIGHT\n",
      gene_result[0],
      gene_result[1],
      gene_result[2],
      gene_result[3],
      gene_result[4],
      gene_total,
      ps->num,
      ps->money,
      pay_way_total);
    }
   }
   else
   {
    printf("find fail\n");
    exit(0);
   }
  }
 }
 return;
}

int main()
{
 gene(5);
 system("pause");
 return 0;
}