A true workhorse programmed in C++
[attachimg=1] (http://betselection.cc/free-releases/(release)-last-dozencolumn-generator-v0-2/?action=dlattach;attach=991)
Download: [attachmini=2]
Takes a file with one number per line (must contain number only, no blanks or other characters).
Outputs one processed file for dozens and one processed file for columns.
If Debug CheckBox is ticked, the program outputs debug files. Useful to check the correctness of your data input or results.
Enjoy!
Vic
#include <windows.h>
#include <fstream>
#include <deque>
#include <string>
// Identifiers.
#define IDC_BUTTON 2000
#define IDC_CHECK 2001
// Globals
HINSTANCE instance;
HWND hwnd;
HFONT h_font;
std::deque<int> dozens; // Deque as LIFO queue for dozens
std::deque<int> columns; // Deque as LIFO queue for columns
bool debug; // Holds last state for debug
// Prototypes
int GetDozen(int num);
int GetColumn(int num);
// Declare window procedure
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
// Class name as global
char szClassName[ ] = "LastDCGen";
// Program's entrypoint
int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
{
instance = hThisInstance;
MSG messages;
WNDCLASSEX wincl;
/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);
/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
/* BG Color */
wincl.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;
/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0,
szClassName, /* Classname */
"LastDC Lw Generator", /* Title Text */
WS_OVERLAPPEDWINDOW &~ WS_MAXIMIZEBOX &~ WS_MINIMIZEBOX, /* no min/max button */
CW_USEDEFAULT,
CW_USEDEFAULT,
196, /* Width */
100, /* Height */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL
);
// Center it
RECT rc;
int screenWidth = GetSystemMetrics(SM_CXSCREEN);
int screenHeight = GetSystemMetrics(SM_CYSCREEN);
GetWindowRect(hwnd, &rc);
SetWindowPos(hwnd, 0, (screenWidth - rc.right)/2, (screenHeight - rc.bottom)/2, 0, 0, SWP_NOZORDER|SWP_NOSIZE);
// Set Font
h_font = CreateFont(-13, 0, 0, 0, FW_NORMAL, 0,
0, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Times New Roman");
/* Make the window visible on the screen */
ShowWindow (hwnd, nFunsterStil);
/* Run the message loop. */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}
// Window Procedure
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
// Handle messages
switch (message)
{
// Form creation
case WM_CREATE:
// Last window
HWND wnd;
// Create Button
wnd = CreateWindowEx(0x00000000, "Button", "Select file", 0x50010001, 8, 16, 96, 32, hwnd, (HMENU) IDC_BUTTON, instance, NULL);
SendMessage(wnd, WM_SETFONT, (WPARAM) h_font, TRUE);
// Create CheckBox
wnd = CreateWindowEx(0x00000000, "Button", "Debug", 0x50010003, 112, 17, 96, 32, hwnd, (HMENU) IDC_CHECK, instance, NULL);
SendMessage(wnd, WM_SETFONT, (WPARAM) h_font, TRUE);
// Emulate button press
break;
// Handle user command
case WM_COMMAND:
switch (LOWORD(wParam))
{
// CheckBox
case IDC_CHECK:
if (IsDlgButtonChecked(hwnd, IDC_CHECK) == BST_CHECKED)
{
// Checked
debug = true;
}
else
{
// Unckecked
debug = false;
}
break;
// Button
case IDC_BUTTON:
// Open file name
OPENFILENAME ofn;
// Memory buffer to contain file name
char szFile[MAX_PATH+1];
// Open a file
ZeroMemory( &ofn , sizeof( ofn ) );
ofn.lStructSize = sizeof ( ofn );
ofn.hwndOwner = NULL ;
ofn.lpstrFile = szFile ;
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = sizeof( szFile );
ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0";
ofn.nFilterIndex =1;
ofn.lpstrFileTitle = NULL ;
ofn.nMaxFileTitle = 0 ;
ofn.lpstrInitialDir = NULL ;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST ;
// Invoke file dialog
if (GetOpenFileName( &ofn ))
{
// ifstream from file
std::ifstream file(ofn.lpstrFile);
// base name
std::string ofbase;
// Set base to opened file
ofbase = ofn.lpstrFile;
// Remove extension
if (ofbase.find(".")!=std::string::npos)
{
ofbase.erase(ofbase.find_last_of("."), std::string::npos);
}
// Set dozen and column files
std::string ofdozn(ofbase); // dozens base
std::string ofcoln(ofbase); // columns base
ofdozn.append("-dozens.txt"); // Append to dozens file
ofcoln.append("-columns.txt"); // Append to columns file
std::ofstream ofdoz(ofdozn.c_str()); // ofstream for dozens
std::ofstream ofcol(ofcoln.c_str()); // ofstream for columns
std::ofstream ofcoldb; // ofstream for dozens debug
std::ofstream ofdozdb; // ofstream for columns debug
// Set debug files
if (debug)
{
std::string ofdozdbn(ofbase); // dozens debug
std::string ofcoldbn(ofbase); // columns debug
ofdozdbn.append("-dozens_debug.txt"); // Append to dozens debug
ofcoldbn.append("-columns_debug.txt"); // Append to columns debug
ofdozdb.open(ofdozdbn.c_str()); // Open dozen debug
ofcoldb.open(ofcoldbn.c_str()); // Open column debug
}
// string for line
std::string s;
// Walk file
while (std::getline(file, s))
{
// Resize to two characters
s.resize(2);
// Halt if it isn't numeric
for (int i = 0; i < s.length(); ++i)
{
// Check
if (!isdigit(s[i]))
{
// skip iteration
continue;
}
}
// Set number
int number = atoi(s.c_str());
// Check it's 0-36 (roulette range)
if (number < 0 || number > 36)
{
// skip iteration
continue;
}
// Get current dozen
int dozen = GetDozen(number);
// Check if empty
if (dozens.size() == 0)
{
// Add element to deque's front
dozens.push_front(dozen);
// Skip iteration
continue;
}
// Look for an instance in deque
if (std::find(dozens.begin(), dozens.end(), dozen) != dozens.end())
{
// win to regular file
ofdoz << "W" << std::endl;
// win to debug file
if (debug)
{
ofdozdb << number << " " << dozen << " " << "W" << std::endl;
}
}
else
{
// lose
ofdoz << "L" << std::endl;
// lose to debug file
if (debug)
{
ofdozdb << number << " " << dozen << " " << "L" << std::endl;
}
}
// Handle one element
if (dozens.size() == 1 )
{
// Check for the same
if (dozen != dozens[0])
{
// Add second element to deque's front
dozens.push_front(dozen);
}
// Skip iteration
continue;
}
// Handle two elements
if (dozen != dozens[1])
{
// Pop first one
dozens.pop_back();
// Add new element to deque's front
dozens.push_front(dozen);
}
/* Columns */
// Get current column
int column = GetColumn(number);
// Check if empty
if (columns.size() == 0)
{
// Add element to deque's front
columns.push_front(column);
// Skip iteration
continue;
}
// Look for an instance in deque
if (std::find(columns.begin(), columns.end(), column) != columns.end())
{
// win to regular file
ofcol << "W" << std::endl;
// win to debug file
if (debug)
{
ofcoldb << number << " " << column << " " << "W" << std::endl;
}
}
else
{
// lose
ofcol << "L" << " " << std::endl;
// lose to debug file
if (debug)
{
ofcoldb << number << " " << column << " " << "L" << std::endl;
}
}
// Handle one element
if (columns.size() == 1 )
{
// Check for the same
if (column != columns[0])
{
// Add second element to deque's front
columns.push_front(column);
}
// Skip iteration
continue;
}
// Handle two elements
if (column != columns[1])
{
// Pop first one
columns.pop_back();
// Add new element to deque's front
columns.push_front(column);
}
}
// Close ofstreams
ofdoz.close();
ofcol.close();
if (debug)
{
ofdozdb.close();
ofcoldb.close();
}
// Clear deques
dozens.clear();
columns.clear();
// Inform user we have processed everything
MessageBox ( NULL , "Finished!" , "File Name" , MB_OK);
}
}
break;
// Form close
case WM_DESTROY:
// Launch BetSelection.cc
ShellExecute(NULL, "open", "http://betselection.cc", NULL, NULL, SW_SHOWNORMAL);
// Good bye!
PostQuitMessage (0);
break;
// Process other messages
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
/* Roulette Functions */
// Determines the dozen that a number belongs to
// Returns 0, 1, 2, 3.
int GetDozen(int num)
{
switch (num)
{
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
case 12:
// First dozen
return 1;
case 13:
case 14:
case 15:
case 16:
case 17:
case 18:
case 19:
case 20:
case 21:
case 22:
case 23:
case 24:
// Second dozen
return 2;
case 25:
case 26:
case 27:
case 28:
case 29:
case 30:
case 31:
case 32:
case 33:
case 34:
case 35:
case 36:
// Third dozen
return 3;
default:
// No dozen
return 0;
}
}
// Determines the column that a number belongs to
// Returns 0, 1, 2, 3.
int GetColumn(int num)
{
switch (num)
{
case 1:
case 4:
case 7:
case 10:
case 13:
case 16:
case 19:
case 22:
case 25:
case 28:
case 31:
case 34:
// First column
return 1;
case 2:
case 5:
case 8:
case 11:
case 14:
case 17:
case 20:
case 23:
case 26:
case 29:
case 32:
case 35:
// Second column
return 2;
case 3:
case 6:
case 9:
case 12:
case 15:
case 18:
case 21:
case 24:
case 27:
case 30:
case 33:
case 36:
// Third column
return 3;
default:
// No column
return 0;
}
}