Skip to content

Instantly share code, notes, and snippets.

@Introscopia
Last active March 10, 2024 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Introscopia/8ea9a271181dfa70f0fac10dd9a4c3b6 to your computer and use it in GitHub Desktop.
Save Introscopia/8ea9a271181dfa70f0fac10dd9a4c3b6 to your computer and use it in GitHub Desktop.
Statistical study for a 6d6-based "Dice Poker"
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <time.h>
#include <math.h>
#include <string.h>
#include "multidimensional.h"
int compare_ints (const void * a, const void * b){
return ( *(int*)a - *(int*)b );
}
int longest_sequence( int *a, int len ){
int mseq = 0;
int seq = 0;
for (int i = 1; i < len; ++i ){
if( a[i] == a[i-1]+1 ){
if( seq == 0 ) seq = 2;
else seq += 1;
}
else if( a[i] != a[i-1] ){
if( seq > mseq ) mseq = seq;
seq = 0;
}
}
if( seq > mseq ) mseq = seq;
return seq;
}
#define RESET() six_of_a_kind = 0; \
five_of_a_kind = 0; \
four_of_a_kind = 0; \
three_of_a_kind = 0;\
two_trios = 0; \
full_house = 0; \
fuller_house = 0; \
pair = 0; \
two_pair = 0; \
three_pair = 0; \
four_in_a_row = 0; \
five_in_a_row = 0; \
six_in_a_row = 0; \
pure_pair = 0;
#define COUNTEM(D) int c [6] = {0,0,0,0,0,0}; \
for (int i = 0; i < D; ++i ){ \
c[ a[i]-1 ] += 1; \
} \
int of_a_kind [5] = {0,0,0,0,0}; \
for (int i = 0; i < 6; ++i ){ \
if( c[i] <= 1 ) continue; \
if( c[i] > 6 ) of_a_kind[ 4 ] += 1; \
else of_a_kind[ c[i] - 2 ] += 1; \
} \
bool par=0, row4=0, row5=0, par2=0, par3=0, fh=0, ffh=0; \
if( of_a_kind[4] ) six_of_a_kind += 1; \
if( of_a_kind[3] ) five_of_a_kind += 1; \
if( of_a_kind[2] >= 1 && of_a_kind[0] >= 1 ){fuller_house += 1; ffh = 1;} \
if( of_a_kind[2] ) four_of_a_kind += 1; \
if( of_a_kind[1] >= 2 ) two_trios += 1; \
if( of_a_kind[1] >= 1 && of_a_kind[0] >= 1 ){full_house += 1; fh = 1;} \
if( of_a_kind[1] >= 1 ) three_of_a_kind += 1; \
if( of_a_kind[0] >= 3 ){three_pair += 1; par3 = 1;} \
if( of_a_kind[0] >= 2 ){two_pair += 1; par2 = 1;} \
if( of_a_kind[0] >= 1 ){pair += 1; par = 1;} \
int seq = longest_sequence( a, D ); \
if( seq >= 6 ) six_in_a_row += 1; \
if( seq == 5 ){five_in_a_row += 1; row5 = 1;} \
if( seq == 4 ){four_in_a_row += 1; row4 = 1;} \
if( par && !row4 && !row5 && !par2 && !par3 && !fh && !ffh ){ \
pure_pair += 1; \
}
#define PRINTOUT(D) total = powf(6,D); \
printf("total: %d\n", (int)total ); \
total = 1.0 / total; \
printf("six_of_a_kind: %.4f %% (%d)\n", 100 * (total * six_of_a_kind), six_of_a_kind ); \
printf("five_of_a_kind: %.4f %% (%d)\n", 100 * (total * five_of_a_kind), five_of_a_kind ); \
printf("four_of_a_kind: %.4f %% (%d)\n", 100 * (total * four_of_a_kind), four_of_a_kind ); \
printf("three_of_a_kind: %.4f %% (%d)\n", 100 * (total * three_of_a_kind), three_of_a_kind ); \
printf("two_trios: %.4f %% (%d)\n", 100 * (total * two_trios), two_trios ); \
printf("full_house: %.4f %% (%d)\n", 100 * (total * full_house), full_house ); \
printf("fuller_house: %.4f %% (%d)\n", 100 * (total * fuller_house), fuller_house ); \
printf("pair: %.4f %% (%d)\n", 100 * (total * pair), pair ); \
printf("pure_pair: %.4f %% (%d)\n", 100 * (total * pure_pair), pure_pair ); \
printf("two_pair: %.4f %% (%d)\n", 100 * (total * two_pair), two_pair ); \
printf("three_pair: %.4f %% (%d)\n", 100 * (total * three_pair), three_pair ); \
printf("four_in_a_row: %.4f %% (%d)\n", 100 * (total * four_in_a_row), four_in_a_row ); \
printf("five_in_a_row: %.4f %% (%d)\n", 100 * (total * five_in_a_row), five_in_a_row ); \
printf("six_in_a_row: %.4f %% (%d)\n", 100 * (total * six_in_a_row), six_in_a_row );
#define CLEANPRINT(D) total = 1.0 / powf(6,D); \
printf("data[%d][0] = %.4f;\n", D-6, 100 * (total * six_of_a_kind) ); \
printf("data[%d][1] = %.4f;\n", D-6, 100 * (total * five_of_a_kind) ); \
printf("data[%d][2] = %.4f;\n", D-6, 100 * (total * four_of_a_kind) ); \
printf("data[%d][3] = %.4f;\n", D-6, 100 * (total * three_of_a_kind) ); \
printf("data[%d][4] = %.4f;\n", D-6, 100 * (total * two_trios) ); \
printf("data[%d][5] = %.4f;\n", D-6, 100 * (total * full_house) ); \
printf("data[%d][6] = %.4f;\n", D-6, 100 * (total * fuller_house) ); \
printf("data[%d][7] = %.4f;\n", D-6, 100 * (total * pair) ); \
printf("data[%d][8] = %.4f;\n", D-6, 100 * (total * two_pair) ); \
printf("data[%d][9] = %.4f;\n", D-6, 100 * (total * three_pair) ); \
printf("data[%d][10] = %.4f;\n", D-6, 100 * (total * four_in_a_row) ); \
printf("data[%d][11] = %.4f;\n", D-6, 100 * (total * five_in_a_row) ); \
printf("data[%d][12] = %.4f;\n", D-6, 100 * (total * six_in_a_row) );
int main(int argc, char const *argv[]){
/* 6D6 scores
printf( "six_of_a_kind:.... % 5g, % 5g\n", 6 / 6.0, 18000 / 6.0 );
printf( "five_of_a_kind:... % 5g, % 5g\n", 180 / 6.0, 18000 / 180.0 );
printf( "four_of_a_kind:... % 5g, % 5g\n", 2250 / 6.0, 18000 / 2250.0 );
printf( "three_of_a_kind:.. % 5g, % 5g\n", 14700 / 6.0, 18000 / 14700.0 );
printf( "two_trios:........ % 5g, % 5g\n", 300 / 6.0, 18000 / 300.0 );
printf( "full_house:....... % 5g, % 5g\n", 7200 / 6.0, 18000 / 7200.0 );
printf( "fuller_house:..... % 5g, % 5g\n", 450 / 6.0, 18000 / 450.0 );
printf( "pair:............. % 5g, % 5g\n", 36450 / 6.0, 18000 / 36450.0 );
printf( "two_pair:......... % 5g, % 5g\n", 18000 / 6.0, 18000 / 18000.0 );
printf( "three_pair:....... % 5g, % 5g\n", 1800 / 6.0, 18000 / 1800.0 );
printf( "four_in_a_row:.... % 5g, % 5g\n", 6480 / 6.0, 18000 / 6480.0 );
printf( "five_in_a_row:.... % 5g, % 5g\n", 3600 / 6.0, 18000 / 3600.0 );
printf( "six_in_a_row:..... % 5g, % 5g\n", 720 / 6.0, 18000 / 720.0 );
*/
/* 7D6 scores
printf( "six_of_a_kind:.... % 7g, % 7g\n", 216.0, 126000 / 216.0 );
printf( "five_of_a_kind:... % 7g, % 7g\n", 3150.0, 126000 / 3150.0 );
printf( "four_of_a_kind:... % 7g, % 7g\n", 26250.0, 126000 / 26250.0 );
printf( "three_of_a_kind:.. % 7g, % 7g\n", 122850.0, 126000 / 122850.0 );
printf( "two_trios:........ % 7g, % 7g\n", 8400.0, 126000 / 8400.0 );
printf( "full_house:....... % 7g, % 7g\n", 88200.0, 126000 / 88200.0 );
printf( "fuller_house:..... % 7g, % 7g\n", 12600.0, 126000 / 12600.0 );
printf( "pair:............. % 7g, % 7g\n", 229950.0, 126000 / 229950.0 );
printf( "two_pair:......... % 7g, % 7g\n", 126000.0, 126000 / 126000.0 );
printf( "three_pair:....... % 7g, % 7g\n", 37800.0, 126000 / 37800.0 );
printf( "four_in_a_row:.... % 7g, % 7g\n", 42000.0, 126000 / 42000.0 );
printf( "five_in_a_row:.... % 7g, % 7g\n", 33600.0, 126000 / 33600.0 );
printf( "six_in_a_row:..... % 7g, % 7g\n", 15120.0, 126000 / 15120.0 );
*/
//abort();
int six_of_a_kind = 0;
int five_of_a_kind = 0;
int four_of_a_kind = 0;
int three_of_a_kind = 0;
int two_trios = 0;
int full_house = 0;//trio+pair
int fuller_house = 0;//quad+pair
int pair = 0;
int pure_pair = 0;
int two_pair = 0;
int three_pair = 0;
int four_in_a_row = 0;
int five_in_a_row = 0;
int six_in_a_row = 0;
float total = 0;
puts("//ON 6D6");
OPEN_6D()
COUNTEM(6)
CLOSE_6D()
PRINTOUT(6)
RESET()
puts("//ON 7D6");
OPEN_7D()
COUNTEM(7)
CLOSE_7D()
PRINTOUT(7)
RESET()
puts("//ON 8D6");
OPEN_8D()
COUNTEM(8)
CLOSE_8D()
PRINTOUT(8)
RESET()
puts("//ON 9D6");
OPEN_9D()
COUNTEM(9)
CLOSE_9D()
PRINTOUT(9)
return 0;
}
/*
ON 6D6
Hand | frequency/6 | SCORE
six of a kind:.... 1, 3000
five of a kind:... 30, 100
two trios:........ 50, 60
fuller house:..... 75, 40
six in a row:..... 120, 25
three pair:....... 300, 10
four of a kind:... 375, 8
five in a row:.... 600, 5
four in a row:.... 1080, 2.77778
full house:....... 1200, 2.5
three of a kind:.. 2450, 1.22449
two pair:......... 3000, 1
pair:............. 6075, 0.493827
ON 7D6
Hand | frequency | SCORE
six_of_a_kind:.... 216, 583.333
five_of_a_kind:... 3150, 40
two_trios:........ 8400, 15
fuller_house:..... 12600, 10
six_in_a_row:..... 15120, 8.33333
four_of_a_kind:... 26250, 4.8
five_in_a_row:.... 33600, 3.75
three_pair:....... 37800, 3.33333
four_in_a_row:.... 42000, 3
full_house:....... 88200, 1.42857
three_of_a_kind:.. 122850, 1.02564
two_pair:......... 126000, 1
pair:............. 229950, 0.547945
*/
#ifndef MULTIDIMENSIONAL_H_INCLUDED
#define MULTIDIMENSIONAL_H_INCLUDED
#define OPEN_2D() for (int i0 = 1; i0 <= 6; ++i0 ){\
for (int i1 = 1; i1 <= 6; ++i1 ){\
int a [2] = {i0, i1 };\
qsort( a, 2, sizeof(int), compare_ints );
#define CLOSE_2D() }}
#define OPEN_3D() for (int i0 = 1; i0 <= 6; ++i0 ){\
for (int i1 = 1; i1 <= 6; ++i1 ){\
for (int i2 = 1; i2 <= 6; ++i2 ){\
int a [3] = {i0, i1, i2 };\
qsort( a, 3, sizeof(int), compare_ints );
#define CLOSE_3D() }}}
#define OPEN_4D() for (int i0 = 1; i0 <= 6; ++i0 ){\
for (int i1 = 1; i1 <= 6; ++i1 ){\
for (int i2 = 1; i2 <= 6; ++i2 ){\
for (int i3 = 1; i3 <= 6; ++i3 ){\
int a [4] = {i0, i1, i2, i3 };\
qsort( a, 4, sizeof(int), compare_ints );
#define CLOSE_4D() }}}}
#define OPEN_5D() for (int i0 = 1; i0 <= 6; ++i0 ){\
for (int i1 = 1; i1 <= 6; ++i1 ){\
for (int i2 = 1; i2 <= 6; ++i2 ){\
for (int i3 = 1; i3 <= 6; ++i3 ){\
for (int i4 = 1; i4 <= 6; ++i4 ){\
int a [5] = {i0, i1, i2, i3, i4 };\
qsort( a, 5, sizeof(int), compare_ints );
#define CLOSE_5D() }}}}}
#define OPEN_6D() for (int i0 = 1; i0 <= 6; ++i0 ){\
for (int i1 = 1; i1 <= 6; ++i1 ){\
for (int i2 = 1; i2 <= 6; ++i2 ){\
for (int i3 = 1; i3 <= 6; ++i3 ){\
for (int i4 = 1; i4 <= 6; ++i4 ){\
for (int i5 = 1; i5 <= 6; ++i5 ){\
int a [6] = {i0, i1, i2, i3, i4, i5 };\
qsort( a, 6, sizeof(int), compare_ints );
#define CLOSE_6D() }}}}}}
#define OPEN_7D() for (int i0 = 1; i0 <= 6; ++i0 ){\
for (int i1 = 1; i1 <= 6; ++i1 ){\
for (int i2 = 1; i2 <= 6; ++i2 ){\
for (int i3 = 1; i3 <= 6; ++i3 ){\
for (int i4 = 1; i4 <= 6; ++i4 ){\
for (int i5 = 1; i5 <= 6; ++i5 ){\
for (int i6 = 1; i6 <= 6; ++i6 ){\
int a [7] = {i0, i1, i2, i3, i4, i5, i6 };\
qsort( a, 7, sizeof(int), compare_ints );
#define CLOSE_7D() }}}}}}}
#define OPEN_8D() for (int i0 = 1; i0 <= 6; ++i0 ){\
for (int i1 = 1; i1 <= 6; ++i1 ){\
for (int i2 = 1; i2 <= 6; ++i2 ){\
for (int i3 = 1; i3 <= 6; ++i3 ){\
for (int i4 = 1; i4 <= 6; ++i4 ){\
for (int i5 = 1; i5 <= 6; ++i5 ){\
for (int i6 = 1; i6 <= 6; ++i6 ){\
for (int i7 = 1; i7 <= 6; ++i7 ){\
int a [8] = {i0, i1, i2, i3, i4, i5, i6, i7 };\
qsort( a, 8, sizeof(int), compare_ints );
#define CLOSE_8D() }}}}}}}}
#define OPEN_9D() for (int i0 = 1; i0 <= 6; ++i0 ){\
for (int i1 = 1; i1 <= 6; ++i1 ){\
for (int i2 = 1; i2 <= 6; ++i2 ){\
for (int i3 = 1; i3 <= 6; ++i3 ){\
for (int i4 = 1; i4 <= 6; ++i4 ){\
for (int i5 = 1; i5 <= 6; ++i5 ){\
for (int i6 = 1; i6 <= 6; ++i6 ){\
for (int i7 = 1; i7 <= 6; ++i7 ){\
for (int i8 = 1; i8 <= 6; ++i8 ){\
int a [9] = {i0, i1, i2, i3, i4, i5, i6, i7, i8 };\
qsort( a, 9, sizeof(int), compare_ints );
#define CLOSE_9D() }}}}}}}}}
#endif
String[] hands = {"six of a kind", "five of a kind", "four of a kind", "three of a kind", "two trios",
"full house", "fuller house", "pair", "two pair", "three pair", "four in a row",
"five in a row", "six in a row"};
float[][] data = new float[4][13];
//ON 6D6
data[0][0] = 0.0129;
data[0][1] = 0.3858;
data[0][2] = 4.8225;
data[0][3] = 31.5072;
data[0][4] = 0.6430;
data[0][5] = 15.4321;
data[0][6] = 0.9645;
data[0][7] = 78.1250;
data[0][8] = 38.5802;
data[0][9] = 3.8580;
data[0][10] = 13.8889;
data[0][11] = 7.7160;
data[0][12] = 1.5432;
//ON 7D6
data[1][0] = 0.0772;
data[1][1] = 1.1253;
data[1][2] = 9.3771;
data[1][3] = 43.8850;
data[1][4] = 3.0007;
data[1][5] = 31.5072;
data[1][6] = 4.5010;
data[1][7] = 82.1438;
data[1][8] = 45.0103;
data[1][9] = 13.5031;
data[1][10] = 15.0034;
data[1][11] = 12.0027;
data[1][12] = 5.4012;
//ON 8D6
data[2][0] = 0.2647;
data[2][1] = 2.5006;
data[2][2] = 15.5661;
data[2][3] = 54.5125;
data[2][4] = 8.0018;
data[2][5] = 44.0101;
data[2][6] = 10.5024;
data[2][7] = 85.0194;
data[2][8] = 48.7611;
data[2][9] = 20.2546;
data[2][10] = 14.7934;
data[2][11] = 15.0034;
data[2][12] = 11.4026;
//ON 9D6
data[3][0] = 0.6815;
data[3][1] = 4.6886;
data[3][2] = 23.0678;
data[3][3] = 62.4726;
data[3][4] = 15.3368;
data[3][5] = 51.0117;
data[3][6] = 17.2539;
data[3][7] = 85.9804;
data[3][8] = 54.4624;
data[3][9] = 20.2546;
data[3][10] = 13.8282;
data[3][11] = 16.5538;
data[3][12] = 18.9043;
int W = 96;
int H = 64;
size( 1344, 320 );
textAlign( CENTER, CENTER );
for (int i = 0; i < 13; ++i ){
fill( 0 );
textSize(20);
text( hands[i], (i+1)*W +5, 5, W-10, H );
for (int j = 0; j < 4; ++j ){
float k = map( data[j][i], 0, 100, 0, 1 );
if( k < 0.333 ) fill( lerpColor( #F0492C, #EFF02C, map(k, 0,0.333,0,1) ) );
else if( k < 0.666 ) fill( lerpColor( #EFF02C, #2CF044, map(k, 0.333,0.666,0,1) ) );
else fill( lerpColor( #2CF044, #12AEFF, map(k, 0.666,1.0,0,1) ) );
rect( (i+1)*W, (j+1)*H, W, H );
fill( 0 );
String str = nf(data[j][i], 1,2) + "%";
if( data[j][i] > 99.9 && data[j][i] != 100.0 ) str = "99.9%";
textSize(26);
text( str, (i+1.5)*W, (j+1.5)*H );
}
}
fill( 0 );
for (int j = 0; j < 4; ++j ){
text( (j+6)+"D6", W/2, (j+1.5)*H );
}
save("output.png");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment