File: HACKING.html

package info (click to toggle)
freecell-solver 5.0.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,256 kB
  • sloc: ansic: 28,700; perl: 10,050; xml: 5,600; python: 1,339; sh: 533; cpp: 275; makefile: 20; javascript: 8
file content (448 lines) | stat: -rw-r--r-- 12,811 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta charset="UTF-8"/>
<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"/><![endif]-->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta name="generator" content="Asciidoctor 1.5.7.1"/>
<meta name="author" content="Shlomi Fish"/>
<title>Freecell Solver "Hacking"-Related Issues</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400,700"/>
<link rel="stylesheet" href="./asciidoctor.css"/>
</head>
<body class="article">
<div id="header">
<h1>Freecell Solver "Hacking"-Related Issues</h1>
<div class="details">
<span id="author" class="author">Shlomi Fish</span><br/>
<span id="email" class="email"><a href="mailto:shlomif@cpan.org">shlomif@cpan.org</a></span><br/>
</div>
</div>
<div id="content">
<div class="sect1">
<h2 id="benchmarking">Benchmarking a Freecell Solver Release</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Requirements: perl-5.14.x or above, CMake, gcc, bash and a working
pthreads-devel package.</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Use the git version control system to clone the repository and get a working
copy.</p>
</li>
<li>
<p>Create a fresh build directory like
<code>mkdir "$HOME"/progs/freecell/git/fc-solve/fc-solve/source/../build"</code>
and cd to it.</p>
</li>
<li>
<p>Run <code>../source/Tatzer -l fc_bench -l extra_speed</code> (for a Freecell-only capable solver)
or <code>../source/Tatzer -l bench</code> (for a solver that can solve all supported
games). Also append these options:</p>
<div class="olist loweralpha">
<ol class="loweralpha" type="a">
<li>
<p><code>--max-bench-threads-num=4</code> , where 4 is the maximal
number of threads you&#8217;d like to run which is a function of the number of
processors/cores your computer has.</p>
</li>
<li>
<p><code>--prefix=$HOME/opt/fc-solve</code> for setting the installation prefix to
install to.</p>
</li>
</ol>
</div>
</li>
<li>
<p>Type <code>make</code> to build everything.</p>
</li>
<li>
<p>Type <code>make install</code>.</p>
</li>
<li>
<p>Type <code>export FCS_PGO_THEME="-l lg" ;  bash pgo.bash</code> to prepare a GCC Profile-Guided Optimizations (PGO)
executable.</p>
</li>
<li>
<p>Then you can run a shell script like this one:</p>
<div class="listingblock">
<div class="content">
<pre>num_threads=4 ; for t in $(seq 1 8) ; do sudo_renice bash -c "$(printf 'ARGS="--worker-step 16 $FCS_PGO_THEME" bash ../scripts/time-threads-num.bash %d %d' $num_threads $num_threads)" ; done</pre>
</div>
</div>
<div class="paragraph">
<p>Where sudo_renice is something like:</p>
</div>
<div class="paragraph">
<p><a href="https://github.com/shlomif/shlomif-computer-settings/blob/master/shlomif-settings/home-bin-executables/bin/sudo_renice" class="bare">https://github.com/shlomif/shlomif-computer-settings/blob/master/shlomif-settings/home-bin-executables/bin/sudo_renice</a></p>
</div>
</li>
<li>
<p>To see the results, you can use <code>perl ../scripts/time-fcs.pl
DUMPS-<strong>/</strong></code> and copy-and-paste the results to the Freecell Solver developers
with specifications of your computer that are as detailed as possible.</p>
</li>
</ol>
</div>
</div>
</div>
<div class="sect1">
<h2 id="test_suite">Getting the test suite up and running</h2>
<div class="sectionbody">
<div class="paragraph">
<p>These are instruction how to get the test suite up and running:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Install the dependencies: Subversion, CMake (3.x or later only), make,
gcc, g\++, valgrind, perl5 (at least perl-5.14)</p>
<div class="ulist">
<ul>
<li>
<p>On Debian:</p>
<div class="listingblock">
<div class="content">
<pre>apt-get install subversion cmake make gcc g++ valgrind perl</pre>
</div>
</div>
</li>
<li>
<p>On Mageia:</p>
<div class="listingblock">
<div class="content">
<pre>urpmi subversion cmake make gcc g++ valgrind perl perl-devel</pre>
</div>
</div>
</li>
</ul>
</div>
</li>
<li>
<p>Install the dependencies of the test suite:</p>
<div class="ulist">
<ul>
<li>
<p>Download <code>local::lib</code> from <a href="https://metacpan.org/release/local-lib" class="bare">https://metacpan.org/release/local-lib</a>
and follow the instructions to set it up.</p>
</li>
<li>
<p>Restart bash (no need to restart the computer, just open a new terminal
window).</p>
<div class="listingblock">
<div class="content">
<pre>export PERL_MM_USE_DEFAULT=1
perl -Mlocal::lib -MCPAN -e 'install Task::FreecellSolver::Testing'</pre>
</div>
</div>
</li>
</ul>
</div>
</li>
<li>
<p>Install the development headers of
libtap ( <a href="https://www.shlomifish.org/open-source/projects/libtap/" class="bare">https://www.shlomifish.org/open-source/projects/libtap/</a> or perhaps
<a href="https://github.com/mpapierski/libtap" class="bare">https://github.com/mpapierski/libtap</a> )</p>
<div class="ulist">
<ul>
<li>
<p>On Mageia:</p>
<div class="listingblock">
<div class="content">
<pre>urpmi libtap-devel</pre>
</div>
</div>
</li>
<li>
<p>On Debian:</p>
<div class="listingblock">
<div class="content">
<pre>tar -xvf /home/shlomif/Desktop/tap-1.01.tar.gz
cd tap-1.01
./configure --prefix="$HOME/apps/libtap"
make CFLAGS+=-UHAVE_LIBPTHREAD
make install
# For gcc finding tap.h in the includes
echo 'export CPATH="$HOME/apps/libtap/include:$CPATH"' &gt;&gt; ~/.bashrc
# For CMake finding libtap.
echo 'export CMAKE_PREFIX_PATH="$HOME/apps/libtap:$CMAKE_PREFIX_PATH"' &gt;&gt; ~/.bashrc</pre>
</div>
</div>
</li>
</ul>
</div>
</li>
<li>
<p>Check out the latest Freecell Solver sources:</p>
<div class="listingblock">
<div class="content">
<pre>git clone https://github.com/shlomif/fc-solve</pre>
</div>
</div>
<div class="paragraph">
<p>(You can also use <a href="http://bundler.caurea.org/" class="bare">http://bundler.caurea.org/</a> ).</p>
</div>
</li>
<li>
<p><code>$ cd fc-solve/fc-solve/source/</code></p>
</li>
<li>
<p><code>$ mkdir build ; cd build</code></p>
</li>
<li>
<p>Configure the Freecell Solver build</p>
<div class="listingblock">
<div class="content">
<pre>../Tatzer</pre>
</div>
</div>
</li>
<li>
<p>Build Freecell Solver:</p>
<div class="listingblock">
<div class="content">
<pre>make</pre>
</div>
</div>
</li>
<li>
<p>Test Freecell Solver:</p>
<div class="listingblock">
<div class="content">
<pre>make test</pre>
</div>
</div>
</li>
</ol>
</div>
</div>
</div>
<div class="sect1">
<h2 id="split_fcc_fc_solver">Running the split_fcc_fc_solver</h2>
<div class="sectionbody">
<div class="paragraph">
<p>The split_fcc_fc_solver (where "FCC" is "fully-connected-components") is
an experimental solver whose design is documented in <a href="../docs/split-fully-connected-components-based-solver-planning.txt">the planning document</a>
and in <a href="../docs/fully-connected-components-based-solver-planning.txt">another one</a> .</p>
</div>
<div class="paragraph">
<p>To run it use in the bash shell, either <code>bash ../scripts/split-fcc&#8212;&#8203;all-in-one.bash</code> which roughly expands to:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>mkdir -p ../B
cd ../B
../source/Tatzer -l pdfs
make
. ../scripts/split-fcc-SOURCE-ME.bash
startup
depth_run 1
depth_run 2
depth_run 3
depth_run 4
# And so forth with consecutive indices</pre>
</div>
</div>
<div class="paragraph">
<p>Note that currently some of the runs fail only to succeed on a rerun (
a <a href="https://en.wikipedia.org/wiki/Heisenbug">Heisenbug</a> ) - at least on
Shlomi Fish&#8217;s local system. If you can investigate why it happens and propose a
fix, we will appreciate it.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="style_guidelines">Style Guidelines</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Freecell Solver uses its own style (largely based on the Allman style:
<a href="http://en.wikipedia.org/wiki/Indent_style#Allman_style" class="bare">http://en.wikipedia.org/wiki/Indent_style#Allman_style</a> ),
based on the preferences of its primary author (Shlomi Fish). The style is
largely enforced by the "clang-format" formatter (using its 7.0.0 version
currently). Some guidelines for the style will be given here.</p>
</div>
<div class="sect2">
<h3 id="four-spaces">4 Spaces for Indentation</h3>
<div class="paragraph">
<p>The Freecell Solver source code should be kept free of horizontal
tabs (\t, HT, \x09) and use spaces alone. Furthermore, there should be
a 4 wide space indentation inside blocks:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>if (COND())
{
    int i;

    printf("%s\n", "COND() is successful!");

    for (i=0 ; i &lt; 10 ; i++)
    {
        ...
    }
}</pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="curly-braces">Curly Braces Alignment</h3>
<div class="paragraph">
<p>The opening curly brace of an if-statement or a for-statement should be
placed below the statement on the same level as the other line, and the
inner block indented by 4 spaces. A good example can be found in the previous
section. Here are some bad examples:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>if ( COND() ) {
    /* Bad because the opening brace is on the same line.
}</pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre>if ( COND() )
    {
    /* Bad because the left and right braces are indented along with
    the block. */
    printf(....)
    }</pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre>/* GNU Style - fear and loathing. */
if ( COND() )
  {
    printf(....)
  }</pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="comments-precede">Comments should precede the lines performing the action</h3>
<div class="paragraph">
<p>Comments should come one line before the line that they explain:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>/* Check if it can be moved to something on the same stack */
for ( dc = 0 ; dc &lt; c-1 ; dc++ )
{
    .
    .
    .
}</pre>
</div>
</div>
<div class="paragraph">
<p><code>TODO: Fill in</code></p>
</div>
</div>
<div class="sect2">
<h3 id="one-line-clauses">One line clauses should be avoided</h3>
<div class="paragraph">
<p>One should avoid one-line clauses inside the clauses of <code>if</code>, <code>else</code>,
<code>elsif</code>, <code>while</code>, etc. Instead one should wrap the single statements inside
blocks. This is to avoid common errors with extraneous semicolons:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>/* Bad: */
if (COND())
    printf ("%s\n", "Success!");

/* Good: */
if (COND())
{
    printf ("%s\n", "Success!");
}

/* Bad: */
while (COND())
    printf("%s\n", "I'm still running.");

/* Good: */
while (COND())
{
    printf("%s\n", "I'm still running.");
}</pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="id-naming">Identifier Naming Conventions</h3>
<div class="paragraph">
<p>Here are some naming conventions for identifiers:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Please do not use capital letters (including not <code>CamelCase</code>) - use
all lowercase letters with words separated by underscores. Remember, C is
case sensitive.</p>
</li>
<li>
<p>Note, however, that comments should be phrased in proper English, with
proper Capitalization and distinction between uppercase and lowercase
letters. So should the rest of the Freecell Solver internal and external
documentation.</p>
</li>
<li>
<p>Some commonly used abbreviations:</p>
</li>
</ol>
</div>
<div class="listingblock">
<div class="content">
<pre>max - maximum
num - numbers
cols - columns
dest - destination
src - source
ds - dest stack
stack - usually the source stack
ptr - pointer
val - value
c - the card index/position within the column
befs - Best First Search (one of the types of searches used by Freecell Solver)
a_star - also refers to "befs" from historical reasons (should be converted
to "befs" in the non-external interface.)
dfs - Depth-First Search (one of the types of searches used by Freecell Solver)</pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="if-0">Don&#8217;t comment-out - use #if 0 to temporarily remove code</h3>
<div class="paragraph">
<p>Code should not be commented-out using gigantic <code>/* &#8230;&#8203; */</code> comments. Instead,
it should be out-blocked using <code>#if 0&#8230;&#8203;#endif</code>.</p>
</div>
<div class="paragraph">
<p>In Perl code, one can use the following POD paradigm to remove a block of
code:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>=begin Removed

Removed code here.

=end Removed

=cut</pre>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="footer">
<div id="footer-text">
Last updated 2018-10-24 23:30:03 IDT
</div>
</div>
</body>
</html>