Post Reply 
(42S) NIM
07-12-2014, 08:33 PM (This post was last modified: 06-15-2017 01:20 PM by Gene.)
Post: #1
(42S) NIM
This implementation of the strategy game Nim is how it was played in the film L'Année dernière à Marienbad using 4 heaps with 1, 3, 5 and 7 objects (e.g. matches or coins).
However it is not played using the misère game condition. But this isn't difficult to change.

It's a boring game: you always have to start. The calculator always wins.

Code:
00 { 142-Byte Prgm }
01▶LBL "NIM"
02 SF 21
03 1
04 STO 01
05 3
06 STO 02
07 5
08 STO 03
09 7
10 STO 04
11 "A"
12 KEY 1 XEQ 01
13 "B"
14 KEY 2 XEQ 02
15 "C"
16 KEY 3 XEQ 03
17 "D"
18 KEY 4 XEQ 04
19 MENU
20▶LBL 00
21 CLA
22 RCL 01
23 AIP
24 ⊦"   "
25 RCL 02
26 AIP
27 ⊦"   "
28 RCL 03
29 AIP
30 ⊦"   "
31 RCL 04
32 AIP
33 AVIEW
34 GTO 00
35▶LBL 01
36 1
37 GTO 05
38▶LBL 02
39 2
40 GTO 05
41▶LBL 03
42 3
43 GTO 05
44▶LBL 04
45 4
46▶LBL 05
47 X<>Y
48 RCL IND ST Y
49 X<Y?
50 RTN
51 X<>Y
52 STO- IND ST Z
53 RCL 01
54 RCL 02
55 XOR
56 RCL 03
57 XOR
58 RCL 04
59 XOR
60 X=0?
61 RTN
62 STO 00
63 4
64▶LBL 06
65 RCL 00
66 RCL IND ST Y
67 XOR
68 RCL- ST L
69 X<0?
70 GTO 07
71 Rv
72 DSE ST X
73 GTO 06
74 RTN
75▶LBL 07
76 STO+ IND ST Y
77 END

Example:
XEQ "NIM"
1 3 5 7
A B C D

1 D
1 3 4 6
A B C D

1 C
1 3 3 1
A B C D

1 B
1 2 3 0
A B C D

1 A
0 2 2 0
A B C D

2 B
0 0 0 0
A B C D

If you wanted to play using the misère game condition the last move would have just taken 1 object from heap C.


Attached File(s)
.zip  nim.zip (Size: 305 bytes / Downloads: 9)
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 2 Guest(s)