TNelen / BlackBox

'BlackBox is a free-to-play game for friends. Available in the play store'
Mozilla Public License 2.0
3 stars 0 forks source link

Make code generation exclude 1's and 0's #183

Closed Nuytemans-Dieter closed 4 years ago

Nuytemans-Dieter commented 4 years ago

Differences between 0 and O, I and 1 are hardly noticeable in the app. Excluding 1 and 0 from the code generation will prevent confusion. Additionally, user input can be altered when containing 1's and 0's, by replacing those by I's and O's respectively.

Ik had net goe idee voor Blackbox. Bij group code meeste verwarring kan zijn omdat 1 op L lijkt en 0 op O. Wat als we die 0 en 1 gwn niet includen bij het generatie algoritme voor die code?
Nuytemans-Dieter commented 4 years ago

I implemented this in d44c66e7b82b5fa81af31c765377d9d62aec65fa and ran a test (iteration of 1000 code generations of length 5). I'll post the results below.

Generated character Frequency of occurence
2 133 (2.66% )
3 146 (2.92% )
4 137 (2.74% )
5 141 (2.82% )
6 139 (2.78% )
7 162 (3.24% )
8 152 (3.04% )
9 178 (3.56% )
A 164 (3.28% )
B 153 (3.06% )
C 154 (3.08% )
D 154 (3.08% )
E 122 (2.44% )
F 138 (2.76% )
G 144 (2.88% )
H 148 (2.96% )
I 168 (3.36% )
J 147 (2.94% )
K 140 (2.80% )
L 164 (3.28% )
M 163 (3.26% )
N 146 (2.92% )
O 165 (3.30% )
P 162 (3.24% )
Q 138 (2.76% )
R 151 (3.02% )
S 145 (2.90% )
T 160 (3.2% )
U 162 (3.24% )
V 158 (3.16% )
W 151 (3.02% )
Y 161 (3.22% )
Z 154 (3.08% )

Edit: this was the code used for testing:

  void testGroupcodeGeneration() async {
    Map<String, int> frequency = Map<String, int>();
    int totalChars = 0;

    for(int i=0; i < 1000; i++)
    {
      print('Code $i...');
      String code = await database.generateUniqueGroupCode();
      totalChars += code.length;

      for(int j=0; j < code.length; j++) {
        String char = code[j];
        if (frequency.containsKey( char ))
          frequency[char] = frequency[char] + 1;
        else
          frequency[char] = 1;
      }
    }

    List<String> sortedKeys = frequency.keys.toList()..sort();
    for(String key in sortedKeys)
    {
      print( key + ': ' + frequency[key].toString() + ' (' + (frequency[key] / totalChars * 100).toString() + '% )');
    }
  }