<commit_before>// flippity.cpp - a simple game with flipping digits
//
// Uses CImg and Allegro libraries and xemacs sounds.

#include <chrono>
#include <iostream>
#include <random>

// #include <allegro/sound.h>
#include <allegro.h>

#include "CImg.h"

using namespace std;
using namespace cimg_library;

class RandomInt {
public:
    RandomInt(int low, int high) :dist{low, high} {}
    int operator()() { return dist(re); }
private:
    default_random_engine re;
    uniform_int_distribution<> dist;
};

class Sound {
public:
    Sound(const char *nam) :fnam{nam} { s = load_sample(nam); }
    int play() { return play_sample(s, 128, 128, 1000, false); }
    ~Sound() { destroy_sample(s); }
private:
    SAMPLE *s;
    const char *fnam;
};

void consequences(Sound &correct, Sound &wrong, int &n_remaining, bool is_correct)
{
    if (is_correct) {
	cout << "CORRECT.   ";
	correct.play();
	--n_remaining;
    } else {
	cout << "INCORRECT. ";
	wrong.play();
	++n_remaining;
    }
    cout << n_remaining << " to go!" << endl;
}

constexpr int letter_code(int character)
{
    return (character - 'A') + 10;
}

char next_alphanum(int &last_alphanum, RandomInt &ri_alphanumeric)
{
    int i;

    for (;;) {
	i = ri_alphanumeric();
	if (i == last_alphanum)
	    continue;
	switch (i) {
	    default:
		goto out;
	    case 8:
	    case 0:
	    case letter_code('A'):
	    case letter_code('H'):
	    case letter_code('I'):
	    case letter_code('M'):
	    case letter_code('O'):
	    case letter_code('T'):
	    case letter_code('V'):
	    case letter_code('W'):
	    case letter_code('X'):
	    case letter_code('Y'):
	    case letter_code('i'):
	    case letter_code('l'):
	    case letter_code('o'):
	    case letter_code('v'):
	    case letter_code('w'):
	    case letter_code('x'):
		break;
	}
    }
out:
    last_alphanum = i;

    if (i <= 9)
	return '0' + i;
    i -= 10;
    return 'A' + i;
}

const char *help(int alphanum)
{
    if (alphanum <= 9)
	return "0123456789";
    if (alphanum <= 9 + 26)<commit_msg>Fix bug making non alphanumerics appear<commit_after>// flippity.cpp - a simple game with flipping digits
//
// Uses CImg and Allegro libraries and xemacs sounds.

#include <chrono>
#include <iostream>
#include <random>

// #include <allegro/sound.h>
#include <allegro.h>

#include "CImg.h"

using namespace std;
using namespace cimg_library;

class RandomInt {
public:
    RandomInt(int low, int high) :dist{low, high} {}
    int operator()() { return dist(re); }
private:
    default_random_engine re;
    uniform_int_distribution<> dist;
};

class Sound {
public:
    Sound(const char *nam) :fnam{nam} { s = load_sample(nam); }
    int play() { return play_sample(s, 128, 128, 1000, false); }
    ~Sound() { destroy_sample(s); }
private:
    SAMPLE *s;
    const char *fnam;
};

void consequences(Sound &correct, Sound &wrong, int &n_remaining, bool is_correct)
{
    if (is_correct) {
	cout << "CORRECT.   ";
	correct.play();
	--n_remaining;
    } else {
	cout << "INCORRECT. ";
	wrong.play();
	++n_remaining;
    }
    cout << n_remaining << " to go!" << endl;
}

int encode(int character)
{
    if (character >= 'A' && character <= 'Z')
	return (character - 'A') + 10;
    return (character - 'a') + 10 + 26;
}

char next_alphanum(int &last_alphanum, RandomInt &ri_alphanumeric)
{
    int i;

    for (;;) {
	i = ri_alphanumeric();
	if (i == last_alphanum
	    || i == encode('A')
	    || i == encode('H')
	    || i == encode('I')
	    || i == encode('M')
	    || i == encode('O')
	    || i == encode('T')
	    || i == encode('U')
	    || i == encode('V')
	    || i == encode('W')
	    || i == encode('X')
	    || i == encode('Y')
	    || i == encode('i')
	    || i == encode('l')
	    || i == encode('o')
	    || i == encode('u')
	    || i == encode('v')
	    || i == encode('w')
	    || i == encode('x'))
	    continue;
	switch (i) {
	    default:
		goto out;
	    case 8:
	    case 0:
		break;
	}
    }
out:
    last_alphanum = i;

    if (i <= 9)
	return '0' + i;
    i -= 10;
    if (i < 26)
	return i + 'A';
    i -= 26;
    return 'a' + i;
}

const char *help(int alphanum)
{
    if (alphanum <= 9)
	return "0123456789";
    if (alphanum <= 9 + 26)
{'fraction_non_alphanumeric': 0.17272727272727273, 'fraction_numerical': 0.01722488038277512, 'mean_word_length': 2.8712962962962965, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '287996', 'n_tokens_mistral': 1677, 'n_tokens_neox': 1543, 'n_words': 411}