Quote from: Wally Gator on October 23, 2012, 01:45:45 AM
Victor, can you provide an example of your play on this?
Yes, with Wiesbaden actuals for Oct 19th, as promised:
[attachmini=1]
Our members are dedicated to PASSION and PURPOSE without drama!
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts MenuQuote from: Wally Gator on October 23, 2012, 01:45:45 AM
Victor, can you provide an example of your play on this?
// C-sharp
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Text.RegularExpressions;
/*
* Source code provided as a compliment. Use for your own learning.
* Feel free to submit your modifications for inclusion at: http://betselection.cc
* Do *not* publicly distribute modified versions (as to keep one (1) canonical version).
* Thanks for appreciating this program. Enjoy!
* Vic
*/
// Main program's namespace
namespace BetSelection_cc_Random_Unique_Line_Generator_v0_1
{
// Program's form
public partial class Form1 : Form
{
/// <summary>
/// Constructor
/// </summary>
public Form1()
{
InitializeComponent();
}
/// <summary>
/// Start-up routine
/// </summary>
private void Form1_Load(object sender, EventArgs e)
{
// Check numbers's radio
rbN.Checked = true;
// Set tooltips
setTooltip(bFile, "Save to file", "Click to pick target file");
setTooltip(bClipboard, "Copy to clipboard", "Copies generated lines to clipboard");
setTooltip(tbSep, "Escape sequences:", "\\n = new line. \\t = tabulator.");
}
/// <summary>
/// Handle generate button
/// </summary>
private void bGenerate_Click(object sender, EventArgs e)
{
// Declare a string array for lines
string[] lines = new string[0];
// Declare single string for all lines
string all_lines = "";
// Act on selected radio button
switch(getCheckedRadioButton().Name)
{
// Numbers
case "rbN":
// Set lines
lines = generateRandomLines(37);
break;
// Splits
case "rbS":
lines = generateRandomLines(18);
break;
// Streets
case "rbSt":
lines = generateRandomLines(12);
break;
// Double-streets
case "rbDS":
lines = generateRandomLines(6);
break;
// Dozens/columns
case "rbDC":
lines = generateRandomLines(3);
break;
}
// Set all_lines
foreach(string line in lines)
{
// Append current line
all_lines += line + Environment.NewLine;
}
/* Handle Clipboard or File*/
// Message
string msg = "";
switch (((Button)sender).Name)
{
// Set lines into clipboard
case "bClipboard":
// Clear it
Clipboard.Clear();
// Set data to it
Clipboard.SetText(all_lines);
// Set message
msg = "Generated lines have been copied to clipboard.";
break;
// Write lines to file
case "bFile":
// Prepare save file dialog
sfdLines.Filter = "Text files|*.txt|All files|*.*";
sfdLines.Title = "Save generated lines to file";
// Show save file dialog
sfdLines.ShowDialog();
// Check if there's something
if (sfdLines.FileName != "")
{
// Insert lines into file
File.WriteAllText(sfdLines.FileName, all_lines);
// Set message
msg = "Saved all generated lines to:" + Environment.NewLine + sfdLines.FileName;
}
else
{
// Cut the flow
return;
}
break;
}
// Show success message
MessageBox.Show(msg, "Success!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
/// <summary>
/// Ancillary function to assist in generation
/// </summary>
/// <param name="elements">Items to hold</param>
/// <returns>String array with a random sequence of elements on each string</returns>
string[] generateRandomLines(byte elements)
{
// String array to hold all lines
string[] lines = new string[Convert.ToInt32(nudTimes.Value)];
// Byte array to hold a generated line
byte[] line = new byte[elements];
// Set amount to add. 0 for singles and splits, 1 for the rest
byte add = Convert.ToByte(elements == 37 || elements == 18 ? 0 : 1);
// Set variable for splits translation
string[] splits = new string[] {"1/4", "2/5", "3/6", "7/10", "8/11", "9/12", "13/16", "14/17", "15/18", "19/22", "20/23", "21/24", "25/28", "26/29", "27/30", "31/34", "32/35", "33/36"};
// Populate with sequential values
for (byte seq = 0; seq < line.Length; ++seq)
{
// Set current
line[seq] = Convert.ToByte(seq + add);
}
// Generation loop
for (int g = 0; g < Convert.ToInt32(nudTimes.Value); ++g)
{
// Declare separator
string sep = tbSep.Text;
// Check if separator must be set to newline or tab
switch (tbSep.Text)
{
// New line
case "\\n":
sep = Environment.NewLine;
break;
// Tab
case "\\t":
sep = "\t";
break;
}
// Prepare a "good-enough" seed
int seed = Convert.ToInt32(Regex.Replace(Guid.NewGuid().ToString().ToLower(), "[a-z-]", "").Substring(0, 9));
// Shuffle
new Random(seed + g).Shuffle(line);
// Declare variable for resulting line
string r_line = "";
// Loop through elements in order to build the line string
for (byte l = 0; l < line.Length; ++l)
{
// Add current, accounting for split, separator and excluding last instance of it
r_line += (elements == 18 ? splits[line[l]] : line[l].ToString()) + (l != line.Length - 1 ? sep : "");
}
// Add it
lines[g] = r_line;
}
// Return result
return lines;
}
/// <summary>
/// Retrieve currently checked location
/// </summary>
/// <returns>The checked RadioButton</returns>
private RadioButton getCheckedRadioButton()
{
// Iterate through form controls
foreach (Control c in this.Controls)
{
// Check if it's a RadioButton
if (c is RadioButton)
{
// Cast
RadioButton r = c as RadioButton;
// Test for check
if(r.Checked)
{
// It's checked, return it
return r;
}
}
}
// Nothing
return null;
}
/// <summary>
/// Launches BetSelection site when program ends.
/// </summary>
private void Form1_FormClosing(Object sender, FormClosingEventArgs e)
{
// Launch BetSelection.cc in default browser
System.Diagnostics.Process.Start("http://betselection.cc");
}
/// <summary>
/// Creates and attaches a tooltip to control
/// </summary>
/// <param name="ctrl">Control to which the tooltip wil be attached to</param>
/// <param name="title">Tooltip's title</param>
/// <param name="text">Tooltip's text</param>
private void setTooltip(Control ctrl, string title, string text)
{
ToolTip ttToolTip = new ToolTip();
ttToolTip.ToolTipTitle = title;
ttToolTip.UseFading = true;
ttToolTip.UseAnimation = true;
ttToolTip.ShowAlways = true;
ttToolTip.AutoPopDelay = 5000;
// Shorter initial delay for separator
ttToolTip.InitialDelay = (ctrl.Name == "tbSep" ? 100 : 1000);
ttToolTip.ReshowDelay = 500;
ttToolTip.SetToolTip(ctrl, text);
}
/// <summary>
/// Status label link
/// </summary>
private void tsslLink_Click(object sender, EventArgs e)
{
// Launch BetSelection.cc site
System.Diagnostics.Process.Start("http://betselection.cc");
}
/// <summary>
/// Handles MouseEnter event for RadioButtons
/// </summary>
private void rb_MouseEnter(object sender, EventArgs e)
{
// Change to red
((RadioButton)sender).ForeColor = Color.Red;
}
/// <summary>
/// Handles MouseLeave event for RadioButtons
/// </summary>
private void rb_MouseLeave(object sender, EventArgs e)
{
// Change back to black
((RadioButton)sender).ForeColor = Color.Black;
}
}
// Generics to enable Shuffle
static class RandomExtensions
{
// Shuffle method
public static void Shuffle<T>(this Random RNG, T[] array)
{
// Knuth-Fisher-Yates shuffling
for (int i = array.Length - 1; i > 0; i--)
{
int n = RNG.Next(i + 1);
Swap(ref array[i], ref array[n]);
}
}
// Swap method
static void Swap<T>(ref T lhs, ref T rhs)
{
T temp;
temp = lhs;
lhs = rhs;
rhs = temp;
}
}
}
// Required for RandomExtensions
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class
| AttributeTargets.Method)]
public sealed class ExtensionAttribute : Attribute { }
}
Quote from: seykid31 on October 20, 2012, 02:39:11 PM
this is being played for real in a casino?
#include <windows.h>
#include <algorithm>
#include <vector>
#include <sstream>
#include <iterator>
#include <ctime>
// Resolve namespace
using namespace std;
// Set class name
const char g_szClassName[] = "vWindowCLS";
// Text to print
ostringstream g_oss;
// Unique number struct
struct c_unique {
int current;
c_unique() {current=0;}
int operator()() {return ++current;}
} UniqueNumber;
// Rectangle structure
RECT g_rect;
/*
* Generates a random double-street line,
* prints it to main form and places it on the keyboard
*/
void gen_line(HWND hwnd)
{
// Create a vector holding numbers 1 to 6
vector<int> vec (6);
// Fill it with numbers 1 to 6
generate( vec.begin(), vec.end(), UniqueNumber );
// Seed rand
srand(rand() % time(0));
// Shuffle the vector
random_shuffle( vec.begin(), vec.end() );
// Reset g_oss
g_oss.str("");
// Convert all but the last element to avoid a trailing ","
copy(vec.begin(), vec.end()-1, ostream_iterator<int>(g_oss, ","));
// Now add the last element with no delimiter
g_oss << vec.back();
/* Set clipboard to generated line */
if(OpenClipboard(hwnd))
{
// Declare memory block
HGLOBAL glob;
// Allocate memory
glob = GlobalAlloc(GMEM_FIXED,32);
// Copy text
memcpy(glob,g_oss.str().c_str(),11);
// Flush clipboard
EmptyClipboard();
// Set new data
SetClipboardData(CF_TEXT,glob);
// Close clipboard
CloseClipboard();
// Unlock memory
GlobalUnlock(glob);
}
/* Invalidate rectangle */
// Get rect
GetClientRect(hwnd, &g_rect);
// Invalidate rectangle
InvalidateRect(hwnd, &g_rect, true);
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CREATE: // Program load
case WM_LBUTTONUP: // Left-click
case WM_RBUTTONUP: // Right-click
// Call gen_line
gen_line(hwnd);
break;
// Close window
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_PAINT:
/* Paint the text*/
HDC hDC;
PAINTSTRUCT ps;
hDC = BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &g_rect);
// Top, regular font
DrawText(hDC, "Last random line:", -1, &g_rect,
DT_SINGLELINE | DT_CENTER | DT_TOP);
// Bottom, regular font
DrawText(hDC, "Victor/VLS @ www.HobbyCode.tk", -1, &g_rect,
DT_SINGLELINE | DT_CENTER | DT_BOTTOM);
// Center, big font
HFONT hf;
long lfHeight;
lfHeight = -MulDiv(28, GetDeviceCaps(hDC, LOGPIXELSY), 72);
hf = CreateFont(lfHeight, 0, 0, 0, 0, TRUE, 0, 0, 0, 0, 0, 0, 0, "Times New Roman");
SelectObject(hDC, hf);
DrawText(hDC, g_oss.str().c_str(), -1, &g_rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
// Finish paint
EndPaint(hwnd, &ps);
break;
// Destroy window
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"Click to generate",
WS_OVERLAPPEDWINDOW &~ WS_MAXIMIZEBOX,
CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
NULL, NULL, hInstance, NULL);
if(hwnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}