![]() |
Knight's Tour Generator
Tourneys and the Fast Generation and Obfuscation of Closed Knight's Tours
|
Code for helper functions.. More...
#include "Helpers.h"
#include "Graph.h"
#include "Random.h"
#include "Defines.h"
#include "Includes.h"
#include "Board.h"
#include <sys/time.h>
Go to the source code of this file.
Functions | |
void | fopen_s (FILE **stream, const char *name, const char *fmt) |
fopen_s for *NIX. More... | |
UINT | timeGetTime () |
Something a little bit like timeGetTime for *NIX. More... | |
std::string | MakeFileNameBase (const CTourneyDesc &t, int w) |
Make file name base. More... | |
std::string | NumString (float x) |
Make string from number. More... | |
void | HSVtoRGB (float h, float s, float v, float rgb[3]) |
HSV to RGB color. More... | |
Variables | |
MoveDeltas | g_vecDeltas |
Move deltas for all possible knight's moves. More... | |
void fopen_s | ( | FILE ** | stream, |
const char * | name, | ||
const char * | fmt | ||
) |
Implementation of fopen_s when we're not under Windows.
stream | Output stream. |
name | File name. |
fmt | File format. |
Definition at line 40 of file Helpers.cpp.
void HSVtoRGB | ( | float | h, |
float | s, | ||
float | v, | ||
float | rgb[3] | ||
) |
Convert color in HSV format to RGB format. This is a helper function for generating a pseudorandom color. All parameters are floating point values in \([0,1]\).
h | [in] Hue. |
s | [in] Saturation. |
v | [in] Value. |
rgb | [out] Array of three RGB values. |
Definition at line 149 of file Helpers.cpp.
std::string MakeFileNameBase | ( | const CTourneyDesc & | t, |
int | w | ||
) |
Make the base of a file name (without the extension) based on a tourney. dwscription. If the generator type is GeneratorType::Unknown, then the file name base returned will be "Unknown". If the generator type or cycle type is not one of the ones hard-coded in the switch statements in this function, then the file name base returned will be "Error".
t | Tourney descriptor. |
w | Board width (defaults to -1, which means "none". |
Definition at line 88 of file Helpers.cpp.
std::string NumString | ( | float | x | ) |
Make a compact string representation of a floating point number, that is, if it's close enough to an integer, then don't use decimal point notation, otherwise use 1 digit after the decimal point. This saves space when rendering massive knight's tours to an SVG file. The floating point number is assumed to be positive, otherwise the null string is returned.
x | The number to be processed. |
Definition at line 123 of file Helpers.cpp.
UINT timeGetTime | ( | ) |
Well, it kinda-sorta is like the Windows version of timeGetTime(), but not really. Since it will be used to seed a PRNG, all that really matters is that it returns something different each time is is called. It can be slow but hopefully we'll only used it a few times during initialization.
Definition at line 52 of file Helpers.cpp.
MoveDeltas g_vecDeltas |
Move deltas (horizontal and vertical displacements) for the 8 knight's moves indexed counterclockwise from \((2, -1)\) (the origin is at top left of the board, positive \(x\) is rightwards, and positive \(y\) is downwards.
Definition at line 68 of file Helpers.cpp.