-
Notifications
You must be signed in to change notification settings - Fork 0
/
Help.hs
493 lines (438 loc) · 22.5 KB
/
Help.hs
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
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
module Help (help, commands)
where
-- Help facilities
separator = "----------------------------------------------------------\n"
commands :: IO ()
commands = do
putStr $ separator ++
"commands available:\n" ++
"\t+, -, >=., <=., >==, <==, ===, canonize, conjugate, down, guaranteed,\n" ++
"\tinvertible, latex, leftOp, lop, lrp, ls, ls_d, ls_u, rightOp, rop, rs, rs_d, rs_u,\n" ++
"\tscgDiatic, scgInt, scgStar, showRaw, star, test, test2, up, zeta\n\n" ++
"commands available for positions:\n" ++
"\teval, fromData, fromRaw, moves, points, present, presents, readBoard, toGame, toText\n\n" ++
"For more information use: help \"command\". Egs:\n" ++
"> help \"zeta\"\n" ++
"> help \"+\"\n" ++
"> help \"points\"\n" ++
separator
help :: String -> IO ()
help "+" = putStr $ separator ++
"Disjuctive sum of two or more games." ++
"Use: G1 + G2 + ...\n" ++
"Egs:\n" ++
"> let g1 = Nu 5\n" ++
"> g1\n" ++
"5\n" ++
"> let g2 = LE (-1) [Nu 3]\n" ++
"> g2\n" ++
"<^-1|3>\n" ++
"> let g3 = RE [Op [Nu 1, Op [Nu 3] [Nu (-1)]] [Nu (-11)]] (-2)\n" ++
"> g3" ++
"<<1,<3|-1>|-11>|^-2>\n" ++
"> g1+g2+g3\n" ++
"<<<^5|9>,<<^7|11>|<^3|7>,<11|7>>|<^-7|-3>,<9,<11|7>|-3>>|<<9,<11|7>|-3>|^6>>\n" ++
separator
help "-" = putStr $ separator ++
"Two possible uses:\n" ++
"\tAs a unary function of a game -G means the conjugate of game G\n" ++
"\tAs a binary function of two games means G1 + (-G2)\n" ++
"Egs:\n" ++
"> let g1 = Nu 5\n" ++
"> g1\n" ++
"5\n" ++
"> let g2 = LE (-1) [Nu 3]\n" ++
"> g2\n" ++
"<^-1|3>\n" ++
"> -g2\n" ++
"<-3|^1>\n" ++
"> conjugate g2\n" ++
"<-3|^1>\n" ++
"> g1-g2\n" ++
"<2|^6>\n" ++
"> g2-g1\n" ++
"<^-6|-2>\n" ++
separator
help "conjugate" = putStr $ separator ++
"The conjugate of game G = < -gR | -gL > \n" ++
"Eg:\n" ++
"> conjugate (Op [Nu (-1)] [LE 5 [Nu 10]])\n" ++
"<<-10|^-5>|1>\n" ++
separator
help "canonize" = putStr $ separator ++
"Returns the canonical expression of a game\n" ++
"Eg:\n" ++
"> let g = Op [Nu 3, Op [Nu 5] [Op [Nu 2] [Nu 0]]] [Nu 2]\n" ++
"> g\n" ++
"<3,<5|<2|0>>|2>\n" ++
"> canonize g\n" ++
"<3|2>\n" ++
separator
help "followsVoidRule" = putStr $ separator ++
"Checks if the game follows the void rule\n" ++
"Eg:\n" ++
"> followsVoidRule (RE [Op [Nu 4] [Nu (-1)]] (-2))\n" ++
"False\n" ++
"> followsVoidRule (RE [Op [Nu 4] [Nu (-3)]] (-2))\n" ++
"True\n" ++
separator
help "latex" = putStr $ separator ++
"Convert a game into a latex description\n" ++
"Eg:\n" ++
"> latex (RE [Op [Nu 4] [Nu (-3)]] (-2))\n" ++
"\"$$\\<\\<4|-3\\>|\\emptyset^<-2>\\>$$\"\n" ++
separator
help "leftOp" = putStr $ separator ++
"Left options of game G. It returns the respective list of games\n" ++
"Eg:\n" ++
"> leftOp (RE [Op [Nu 4] [Nu (-3)]] (-2))\n" ++
"[<4|-3>]\n" ++
"> leftOp (LE 5 [Op [Nu 4] [Nu (-3)]])\n" ++
"[]\n" ++
separator
help "rightOp" = putStr $ separator ++
"Right options of game G. It returns the respective list of games\n" ++
"Eg:\n" ++
"> rightOp (LE 5 [Op [Op [Nu 10] [Nu 1]] [Nu (-3)]])\n" ++
"[<<10|1>|-3>]\n" ++
"> rightOp (RE [Op [Nu 4] [Nu (-3)]] (-2))\n" ++
"[]\n" ++
separator
help "ls" = putStr $ separator ++
"Left Stop of game G\n" ++
"Eg:\n" ++
"> let g1 = LE (-5) [Op [Op [Nu 10] [Nu 1]] [Nu (3)]]\n" ++
"> g1\n<^-5|<<10|1>|3>>\n" ++
"> ls g1\n" ++
"-5\n" ++
separator
help "rs" = putStr $ separator ++
"Right Stop of game G\n" ++
"Eg:\n" ++
"> let g1 = LE (-5) [Op [Op [Nu 10] [Nu 1]] [Nu (3)]]\n" ++
"> g1\n<^-5|<<10|1>|3>>\n" ++
"> rs g\n" ++
"1\n" ++
separator
help "ls_d" = putStr $ separator ++
"Left Stop pass-allowed of game G\n" ++
"Eg:\n" ++
"> let g1 = LE (-5) [Op [Op [Nu 10] [Nu 1]] [Nu (3)]]\n" ++
"> g1\n<^-5|<<10|1>|3>>\n" ++
"> ls_d g\n" ++
"-5\n" ++
separator
help "ls_u" = putStr $ separator ++
"Left Strong Stop pass-allowed of game G\n" ++
"Eg:\n" ++
"> let g1 = LE (-5) [Op [Op [Nu 10] [Nu 1]] [Nu (3)]]\n" ++
"> g1\n<^-5|<<10|1>|3>>\n" ++
"> ls_u g\n" ++
"3\n" ++
separator
help "rs_d" = putStr $ separator ++
"Right Strong Stop pass-allowed of game G\n" ++
"Eg:\n" ++
"> let g1 = LE (-5) [Op [Op [Nu 10] [Nu 1]] [Nu (3)]]\n" ++
"> g1\n<^-5|<<10|1>|3>>\n" ++
"> rs_ g\n" ++
"-5\n" ++
separator
help "rs_u" = putStr $ separator ++
"Right Stop pass-allowed of game G\n" ++
"Eg:\n" ++
"> let g1 = LE (-5) [Op [Op [Nu 10] [Nu 1]] [Nu (3)]]\n" ++
"> g1\n<^-5|<<10|1>|3>>\n" ++
"> rs_ g\n" ++
"3\n" ++
separator
help "scgDiatic" = putStr $ separator ++
"Transform a diatic Conway's game into a scoring game\n" ++
"Notice that a diatic is a fraction like numerador/2^exponent\n" ++
"Egs: 1/4, 5/16, -7/32, 1/1, etc.\n" ++
"Everything else will produce an infinite Conway's game.\n" ++
"note: SCG stands for Short (ie, finite) Conway Game.\n" ++
"Eg:\n" ++
"> scgDiatic (2,8)\n" ++
"<<0|<0|<0|<0|^0>>>>|<<0|<0|<0|^0>>>|<0|<0|^0>>>>\n" ++
"> scgDiatic (0,1)\n" ++
"0\n" ++
separator
help "scgInt" = putStr $ separator ++
"Transform a integer Conway's game into a scoring game\n" ++
"Notice that a integer n is also the diatic n/2^0\n" ++
"note: SCG stands for Short (ie, finite) Conway Game.\n" ++
"Eg:\n" ++
"> scgInt 0\n" ++
"0\n" ++
"> scgInt (-5)\n" ++
"<^0|<^0|<^0|<^0|<^0|0>>>>>\n" ++
separator
help "scgStar" = putStr $ separator ++
"Transform a Conway's star game *n into a scoring game\n" ++
"Def: * = *1 = <0|0> && *n = <*,*2,...,*(n-1)|*,*2,...,*(n-1)>, n>1\n" ++
"note: SCG stands for Short (ie, finite) Conway Game.\n" ++
"Eg:\n" ++
"> scgStar 1\n" ++
"<0|0>\n" ++
"> scgStar 2\n" ++
"<<0|0>|<0|0>>\n" ++
separator
help "zeta" = putStr $ separator ++
"Order preserving embedding for numbers (integers & diatics)\n" ++
"This can be used instead of scgInt and scgDiatic.\n" ++
"\'zeta n d\' is the representation of number n/d (d>0)\n" ++
"Eg:\n" ++
"> zeta 1 1\n" ++
"<0|^0>\n" ++
"> zeta 1 4\n" ++
"<0|<0|<0|^0>>>\n" ++
"> zeta (-1) 32\n" ++
"<<<<<<^0|0>|0>|0>|0>|0>|0>\n" ++
separator
help "invertible" = putStr $ separator ++
"Checks if a game G is invertible (G-G=0)\n" ++
"Eg:\n" ++
"> invertible (Nu 3)\n" ++
"True\n" ++
separator
help "lrp" = putStr $ separator ++
"Checks if a game is left-r-protected\n" ++
"Eg:\n" ++
"> lrp 2 (Nu 3)\n" ++
"True\n" ++
separator
help "down" = putStr $ separator ++
"Down, ie <*|0>\n" ++
separator
help "up" = putStr $ separator ++
"Up, ie <0|*>\n" ++
separator
help "star" = putStr $ separator ++
"Star, ie <0|0>\n" ++
separator
help ">=." = putStr $ separator ++
"Checks if a game >= number\n" ++
"Eg:\n" ++
"> up >=. 0\n" ++
"True\n" ++
"> not (Nu 5 >=. 0)\n" ++
"False\n" ++
separator
help "<=." = putStr $ separator ++
"Checks if a game <= number\n" ++
"Eg:\n" ++
"> down <=. 0\n" ++
"True\n" ++
separator
help "<==" = putStr $ separator ++
"Checks if game1 <= game2 (returns false if not comparable)\n" ++
"Eg:\n" ++
"> up <== down\n" ++
"False\n" ++
"> Nu 5 <== LE (-4) [Nu 6]\n" ++
"False\n" ++
separator
help ">==" = putStr $ separator ++
"Checks if game1 >= game2 (returns false if not comparable)\n" ++
"Eg:\n" ++
"> up >== down\n" ++
"True\n" ++
"> Nu 5 >== LE (-4) [Nu 6]\n" ++
"False\n" ++
separator
help "===" = putStr $ separator ++
"Checks if game1 == game2 (returns false if not comparable)\n" ++
"Eg:\n" ++
"> up === up\n" ++
"True\n" ++
"> Nu 5 === LE (-4) [Nu 6]\n" ++
"False\n" ++
separator
help ">=?" = putStr $ separator ++
"Tries to check if game1 >= game2, returning Nothing if not comparable\n" ++
"Eg:\n" ++
"> up >=? down\n" ++
"Just True\n" ++
"> Nu 5 >=? LE (-4) [Nu 6]\n" ++
"Nothing\n" ++
separator
help "<=?" = putStr $ separator ++
"Tries to check if game1 <= game2, returning Nothing if not comparable\n" ++
"Eg:\n" ++
"> up <=? down\n" ++
"Just False\n" ++
"> Nu 5 <=? LE (-4) [Nu 6]\n" ++
"Nothing\n" ++
separator
help "==?" = putStr $ separator ++
"Tries to check if game1 == game2, returning Nothing if not comparable\n" ++
"Eg:\n" ++
"> up ==? up\n" ++
"Just True\n" ++
"> Nu 5 ==? LE (-4) [Nu 6]\n" ++
"Nothing\n" ++
separator
help "lop" = putStr $ separator ++
"Extract n-th left/right game\n" ++
"Eg:\n" ++
"> g\n" ++
"<<1|1,<1|1>>,<2|2>|<<<^4|4>|<4|^4>>|-5>>\n" ++
"> lop 1 $ g\n" ++
"<1|1,<1|1>>\n" ++
"> rop 2 . lop 1 $ g\n" ++
"<1|1>\n" ++
"> rop 1 . lop 2 $ g\n" ++
"2\n" ++
separator
help "rop" = putStr $ separator ++
"Extract n-th left/right game\n" ++
"Eg:\n" ++
"> g\n" ++
"<<1|1,<1|1>>,<2|2>|<<<^4|4>|<4|^4>>|-5>>\n" ++
"> lop 1 $ g\n" ++
"<1|1,<1|1>>\n" ++
"> rop 2 . lop 1 $ g\n" ++
"<1|1>\n" ++
"> rop 1 . lop 2 $ g\n" ++
"2\n" ++
separator
help "showRaw" = putStr $ separator ++
"Show the raw Haskell structure of a game\n" ++
"Eg:\n" ++
"> showRaw up\n" ++
"Op [Nu 0] [Op [Nu 0] [Nu 0]]\n" ++
"> let pos = fromData (-1) [\"lr\",\"rl\"]::Kobber\n" ++
"> let g = toGame pos\n" ++
"> g\n" ++
"<<-1|<-1|-1>>|<<-1|-1>|-1>>\n" ++
"> showRaw g\n" ++
"Op [Op [Nu (-1)] [Op [Nu (-1)] [Nu (-1)]]] [Op [Op [Nu (-1)] [Nu (-1)]] [Nu (-1)]]\n" ++
separator
help "test" = putStr $ separator ++
"Test an unary proposition using random generated games\n" ++
"The first argument is a lambda expression, while the 2nd is the required number of tests\n" ++
"Eg:\n" ++
"> test (\\x -> x >=. 0 || (-x) >=. 0) 40\n" ++
"Found a counter example:\n" ++
"Game: <^4.7568|<^2.3046|-6.9642>,<^3.8723|-3.4964>>\n\n" ++
"> test (\\x -> ls x == ls_ x) 100\n" ++
".............................Found a counter example:\n" ++
"Game: <<^-0.8732|-0.0251>,<4.8932|^-1.8782>|^-2.9849>\n\n" ++
"> test (\\x -> ls x >= ls_ x) 75\n" ++
"...........................................................................Tests finished!\n" ++
"\nMore on lambda-expressions: www.cs.bham.ac.uk/~vxs/teaching/Haskell/handouts/lambda.pdf\n" ++
separator
help "test2" = putStr $ separator ++
"Test a binary proposition using random generated games\n" ++
"The first two arguments are lambda expressions, while the 3rd is the required number of tests\n" ++
"Eg:\n" ++
"> test2 (\\x y -> y <=. ls_ (x+x)) 20\n" ++
"Found a counter example:\n" ++
"Game 1: <4.5708|^-0.7437>\n" ++
"Game 2: <4.8928|-11.9910>\n\n" ++
"> test2 (\\x y -> ls_ x >= ls_ y || not(ls_ x >= ls_ y)) 20\n" ++
"....................Tests finished\n" ++
"\nMore on lambda-expressions: www.cs.bham.ac.uk/~vxs/teaching/Haskell/handouts/lambda.pdf\n" ++
separator
--------------------------------
--------------------------------
-- Help facilities for Position (abstract module for games)
help "points" = putStr $
separator ++
"Returns the current points of a position\n" ++
"Eg:\n" ++
"> let pos = fromData 1 [\"lr.\",\"rl.\",\"l.r\"]::Kobber\n"++
"> points pos\n" ++
"1.0\n" ++
separator
help "toText" = putStr $
separator ++
"Returns an one line description of a position\n" ++
"Eg:\n" ++
"> let pos = fromData 1 [\"lr.\",\"rl.\",\"l.r\"]::Kobber\n"++
"> toText pos\n" ++
"\"lr.\\nrl.\\nl.r\\n1\"\n" ++
separator
help "toGame" = putStr $
separator ++
"Returns the game value of a position\n" ++
"Eg:\n" ++
"> let pos = fromData (-1) [\"lr\",\"rl\"]::Kobber\n"++
"> toGame pos\n" ++
"{{-1|{-1|-1}}|{{-1|-1}|-1}}\n" ++
separator
help "fromRaw" = putStr $
separator ++
"Parse a string from an eval report and make the respective position\n" ++
"Eg:\n" ++
"> evalKobber \"kobber1.txt\"\n"++
"-- Read: \"1\\nlr.\\nrl.\\nl.r\"\n...\n"++
"> let pos = fromRaw \"1\\nlr.\\nrl.\\nl.r\"::Kobber\n"++
"> present pos\n" ++
"lr.\nrl.\nl.r\n1 points\n" ++
"> let g = toGame pos\n" ++
"> ls_ g\n" ++
"1.0\n" ++
separator
help "fromData" = putStr $
separator ++
"Given a value and a list of rows, create the respective game\n" ++
"Eg:\n" ++
"> let pos = fromData (-1) [\"lr\",\"rl\"]::Kobber\n"++
"> toGame pos\n" ++
"{{-1|{-1|-1}}|{{-1|-1}|-1}}\n" ++
separator
help "moves" = putStr $
separator ++
"Returns the next moves given a position and a player\n" ++
"Eg:\n" ++
"> let pos = fromData 0 [\"lr\",\"rl\",\"..\"]::Kobber\n"++
"> presents $ moves pos Left\n" ++
".r\nll\n..\n0 points\n.l\nrl\n..\n0 points\n.r\n.l\nl.\n1 points\nll\nr.\n..\n0 points\nlr\nl.\n..\n0 points\n" ++
separator
help "presents" = putStr $
separator ++
"Shows a list of positions\n" ++
"Eg:\n" ++
"> let pos1 = fromData 0 [\"lr\",\"rl\",\"..\"]::Kobber\n"++
"> let pos2 = fromData 2 [\"rr\",\"xx\"]::Kobber\n"++
"> presents $ [pos1,pos2]\n" ++
"lr\nrl\n..\n0 points\nrr\nxx\n2 points\n" ++
separator
help "present" = putStr $
separator ++
"Shows a position\n" ++
"Eg:\n" ++
"> let pos = fromData 0 [\"lr\",\"rl\",\"..\"]::Kobber\n"++
"> present pos\n" ++
"lr\nrl\n..\n0 points\n" ++
separator
help "eval" = putStr $
separator ++
"Eval<G>: Reads a position from game G from a text file and shows a report\n" ++
"Eg:\n" ++
"> evalKobber \"kobber1.txt\"\n"++
"-- Read: \"1\\nlr.\\nrl.\\nl.r\"\n-- Board\n1\nlr.\nrl.\nl.r\n-- Position Value:\n<<2|<1|<2|1>>>,<3|<<1|0>|1>>|<0,<<1|0>,<1|<2|1>>|<0|-1>,<<-1|-2>|-1>>|<<0|-1>|0>>,<<1|0>|<<0|-1>|0>>>\n" ++
"\nIn this eg, the text file \'kobber1.txt\' includes the following:\n \n" ++
" 1\n lr.\n rl.\n l.r\n\n" ++
"All text files start with a number representing the current points, while the remaining file has a position row for each line.\n" ++
"There's also available evalDots for Dots'n'Boxes, with the same functionality. For an eg type\n \n> evalDots \"dots1.txt\"\n (the report will appear...)\n" ++
"> let dots = fromRaw \"1\\nx...xx\\nxx.xxxx\\nxxx.xx\" :: Dots\n" ++
"> present dots\n" ++
"+-+ + + +-+-+\n|#| | |#|#|\n+-+-+-+ +-+-+\n1 points\n" ++
"> ls (toGame dots)\n2.0\n" ++
separator
help "readBoard" = putStr $ separator ++
"Read the raw data from the file presenting some useful information\n" ++
"Eg:\n" ++
"> readBoard \"dots1.txt\"\n" ++
"-- Read: \"1\\nx...xx\\nxx.xxxx\\nxxx.xx\"\n-- Board\n1\n x . . . x x \nx x . x x x x\n x x x . x x \n-- Position Value:\n(1.0,[\"x...xx\",\"xx.xxxx\",\"xxx.xx\"])\n" ++
separator
-- help "" = putStr $ separator ++
-- "\n" ++
-- "Eg:\n" ++
-- "> \n" ++
-- "\n" ++
-- separator
help _ = putStr $ "Unkown command. Please check \'commands\'\n"