-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtic_tac_toe.bf
340 lines (215 loc) · 10.5 KB
/
tic_tac_toe.bf
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
"================================================================
_____________________________________________
| Trevin S || Spring || 2022 |
|_____________||_____________||_____________|
| Tic || Tac || Toe |
|_____________||_____________||_____________|
| Bologna || Programming || Language |
|_____________||_____________||_____________|
TODO:
================================================================
- Fix tie case
- Condense code by adding player counter
- Check to make sure input is a valid number
================================================================"
"Note; Leave 0 Empty! This is the default memory block we use to print."
"Initialize Index memory 1_9 to ' ' (Space)
To hold the vals of (X | O) cells in the game"
>{ :10 + :#10 +#10 +48 }9
"Initialize Index 10 to \n (linebreak)"
:10 _ +10 .
"Initialize Index 11 to ' ' (Space)"
:11 +32
"Initialize Index 12 to '|'"
:12 +124
"Initialize Index 13 to 'X'"
:13 +88
"Initialize Index 14 to 'O'"
:14 +79
:0
"Print the gameboard
================================================================"
Print a row of hyphens
_ +45 .7 _ #10.
Print top row | mem|1| | mem|2| | mem|3| |
_ #12. #1. #12. #2. #12. #3. #12. #10.
Print a row of hyphens
_ +45 .7 _ #10.
Print middle row | mem|4| | mem|5| | mem|6| |
_ #12. #4. #12. #5. #12. #6. #12. #10.
Print a row of hyphens
_ +45 .7 _ #10.
Print bottom row | mem|7| | mem|8| | mem|9| |
_ #12. #7. #12. #8. #12. #9. #12. #10.
Print a row of hyphens
_ +45 .7 _ #10.
"End Gameboard Print
================================================================"
"Start Game Loop
================================================================"
{
"Player 1 Input
================================================================"
#10.
"Print: Player 1 - "
_ +80. _ +108. _ +97. _ +121. _ +101. _ +114. _ +32. _ +49. _ +32. _ +45. _ #11.
"Print: Pick a cell 1 - 9) "
+80. _ +105. _ +99. _ +107. _ +32. _ +97. _ +32. _ +67. _ +101. _ +108. _ +108. _ +32. _ +49. _ +32. _ +45. _ +32. _ +57. _ +41. _ #11.
"Set index 100 to 1, allowing the while loop to continue until valid entry of player"
:100 _ +1
[
"Character input"
:50 _ , :0
#10.
"Go to the index of the selected cell"
:#50
"If the selected cell was written to, ask for another input"
?(#>78){
:0
_ +84._ +104._ +97._ +116._ +32._ +99._ +101._ +108._ +108._ +32._ +105._ +115._ +32._ +97._ +108._ +114._ +101._ +97._ +100._ +121._ +32._ +116._ +97._ +107._ +101._ +110._ +33._ +32._ +80._ +108._ +101._ +97._ +115._ +101._ +32._ +99._ +104._ +111._ +111._ +115._ +101._ +32._ +97._ +110._ +32._ +101._ +109._ +112._ +116._ +121._ +32._ +111._ +110._ +101._ +46._
#10.
"Print: Player 1 -"
_ +80. _ +108. _ +97. _ +121. _ +101. _ +114. _ +32. _ +49. _ +32. _ +45. _ #11.
"Print: Pick a cell 1-9)"
+80. _ +105. _ +99. _ +107. _ +32. _ +97. _ +32. _ +67. _ +101. _ +108. _ +108. _ +32. _ +49. _ +32. _ +45. _ +32. _ +57. _ +41. _ #11.
}
:#50
"Ensure that the selected cell is not already occupied, and put an X in it"
?(#<#14){ :100 _ :#50 _ +#13 :0 }
:100
]
"End Player 1 Input
================================================================"
"Print the gameboard
================================================================"
"Print a row of hyphens"
_ +45 .7 _ #10.
"Print top row | mem|1| | mem|2| | mem|3| |"
_ #12. #1. #12. #2. #12. #3. #12. #10.
"Print a row of hyphens"
_ +45 .7 _ #10.
"Print middle row | mem|4| | mem|5| | mem|6| |"
_ #12. #4. #12. #5. #12. #6. #12. #10.
"Print a row of hyphens"
_ +45 .7 _ #10.
"Print bottom row | mem|7| | mem|8| | mem|9| |"
_ #12. #7. #12. #8. #12. #9. #12. #10.
"Print a row of hyphens"
_ +45 .7 _ #10.
"End Gameboard Print
================================================================"
"Checking for player 1 game win
================================================================"
:0 _
"If a row contains 3 of a kind"
?(#1=#2){ ?(#2=#3){ ?(#1>78){
+71._ +97._ +109._ +101._ +32._ +79._ +118._ +101._ +114._ +46._ +32._ +80._ +108._ +97._ +121._ +101._ +114._ +32._ ?(#1=#13){+49._} ?(#1=#14){+50._} +32._ +87._ +105._ +110._ +115._ +33._ #10. #10. ~
} } }
?(#4=#5){ ?(#5=#6){ ?(#4>78){
+71._ +97._ +109._ +101._ +32._ +79._ +118._ +101._ +114._ +46._ +32._ +80._ +108._ +97._ +121._ +101._ +114._ +32._ ?(#1=#13){+49._} ?(#1=#14){+50._} +32._ +87._ +105._ +110._ +115._ +33._ #10. #10. ~
} } }
?(#7=#8){ ?(#8=#9){ ?(#7>78){
+71._ +97._ +109._ +101._ +32._ +79._ +118._ +101._ +114._ +46._ +32._ +80._ +108._ +97._ +121._ +101._ +114._ +32._ ?(#1=#13){+49._} ?(#1=#14){+50._} +32._ +87._ +105._ +110._ +115._ +33._ #10. #10. ~
} } }
"If a column contains 3 of a kind"
?(#1=#4){ ?(#4=#7){ ?(#1>78){
+71._ +97._ +109._ +101._ +32._ +79._ +118._ +101._ +114._ +46._ +32._ +80._ +108._ +97._ +121._ +101._ +114._ +32._ ?(#1=#13){+49._} ?(#1=#14){+50._} +32._ +87._ +105._ +110._ +115._ +33._ #10. #10. ~
} } }
?(#2=#5){ ?(#5=#8){ ?(#2>78){
+71._ +97._ +109._ +101._ +32._ +79._ +118._ +101._ +114._ +46._ +32._ +80._ +108._ +97._ +121._ +101._ +114._ +32._ ?(#2=#13){+49._} ?(#2=#14){+50._} +32._ +87._ +105._ +110._ +115._ +33._ #10. #10. ~
} } }
?(#3=#6){ ?(#6=#9){ ?(#3>78){
+71._ +97._ +109._ +101._ +32._ +79._ +118._ +101._ +114._ +46._ +32._ +80._ +108._ +97._ +121._ +101._ +114._ +32._ ?(#3=#13){+49._} ?(#3=#14){+50._} +32._ +87._ +105._ +110._ +115._ +33._ #10. #10. ~
} } }
"If a diagnol contains 3 of a kind"
?(#1=#5){ ?(#5=#9){ ?(#1>78){
+71._ +97._ +109._ +101._ +32._ +79._ +118._ +101._ +114._ +46._ +32._ +80._ +108._ +97._ +121._ +101._ +114._ +32._ ?(#1=#13){+49._} ?(#1=#14){+50._} +32._ +87._ +105._ +110._ +115._ +33._ #10. #10. ~
} } }
?(#3=#5){ ?(#5=#7){ ?(#3>78){
+71._ +97._ +109._ +101._ +32._ +79._ +118._ +101._ +114._ +46._ +32._ +80._ +108._ +97._ +121._ +101._ +114._ +32._ ?(#3=#13){+49._} ?(#3=#14){+50._} +32._ +87._ +105._ +110._ +115._ +33._ #10. #10. ~
} } }
"================================================================"
"Player 2 Input
================================================================"
#10.
"Print: Player 2 - "
_ +80. _ +108. _ +97. _ +121. _ +101. _ +114. _ +32. _ +50. _ +32. _ +45. _ #11.
"Print: Pick a cell 1 - 9) "
+80. _ +105. _ +99. _ +107. _ +32. _ +97. _ +32. _ +67. _ +101. _ +108. _ +108. _ +32. _ +49. _ +32. _ +45. _ +32. _ +57. _ +41. _ #11.
"Set index 100 to 1, allowing the while loop to continue until valid entry of player"
:100 _ +1
[
"Character input"
:50 _ , :0
#10.
"Go to the index of the selected cell"
:#50
"If the selected cell was written to, ask for another input"
?(#>78){
:0
_ +84._ +104._ +97._ +116._ +32._ +99._ +101._ +108._ +108._ +32._ +105._ +115._ +32._ +97._ +108._ +114._ +101._ +97._ +100._ +121._ +32._ +116._ +97._ +107._ +101._ +110._ +33._ +32._ +80._ +108._ +101._ +97._ +115._ +101._ +32._ +99._ +104._ +111._ +111._ +115._ +101._ +32._ +97._ +110._ +32._ +101._ +109._ +112._ +116._ +121._ +32._ +111._ +110._ +101._ +46._
#10.
"Print: Player 2 -"
_ +80. _ +108. _ +97. _ +121. _ +101. _ +114. _ +32. _ +50. _ +32. _ +45. _ #11.
"Print: Pick a cell 1-9)"
+80. _ +105. _ +99. _ +107. _ +32. _ +97. _ +32. _ +67. _ +101. _ +108. _ +108. _ +32. _ +49. _ +32. _ +45. _ +32. _ +57. _ +41. _ #11.
}
:#50
"Ensure that the selected cell is not already occupied, and put a O in it"
?(#<#14){ :100 _ :#50 _ +#14 :0 }
:100
]
"End Player 2 Input
================================================================"
"Print the gameboard
================================================================"
"Print a row of hyphens"
_ +45 .7 _ #10.
"Print top row | mem|1| | mem|2| | mem|3| |"
_ #12. #1. #12. #2. #12. #3. #12. #10.
"Print a row of hyphens"
_ +45 .7 _ #10.
"Print middle row | mem|4| | mem|5| | mem|6| |"
_ #12. #4. #12. #5. #12. #6. #12. #10.
"Print a row of hyphens"
_ +45 .7 _ #10.
"Print bottom row | mem|7| | mem|8| | mem|9| |"
_ #12. #7. #12. #8. #12. #9. #12. #10.
"Print a row of hyphens"
_ +45 .7 _ #10.
"End Gameboard Print
================================================================"
"Checking for player 2 game win
================================================================"
:0 _
"If a row contains 3 of a kind"
?(#1=#2){ ?(#2=#3){ ?(#1>78){
+71._ +97._ +109._ +101._ +32._ +79._ +118._ +101._ +114._ +46._ +32._ +80._ +108._ +97._ +121._ +101._ +114._ +32._ ?(#1=#13){+50._} ?(#1=#14){+50._} +32._ +87._ +105._ +110._ +115._ +33._ #10. #10. ~
} } }
?(#4=#5){ ?(#5=#6){ ?(#4>78){
+71._ +97._ +109._ +101._ +32._ +79._ +118._ +101._ +114._ +46._ +32._ +80._ +108._ +97._ +121._ +101._ +114._ +32._ ?(#1=#13){+50._} ?(#1=#14){+50._} +32._ +87._ +105._ +110._ +115._ +33._ #10. #10. ~
} } }
?(#7=#8){ ?(#8=#9){ ?(#7>78){
+71._ +97._ +109._ +101._ +32._ +79._ +118._ +101._ +114._ +46._ +32._ +80._ +108._ +97._ +121._ +101._ +114._ +32._ ?(#1=#13){+50._} ?(#1=#14){+50._} +32._ +87._ +105._ +110._ +115._ +33._ #10. #10. ~
} } }
"If a column contains 3 of a kind"
?(#1=#4){ ?(#4=#7){ ?(#1>78){
+71._ +97._ +109._ +101._ +32._ +79._ +118._ +101._ +114._ +46._ +32._ +80._ +108._ +97._ +121._ +101._ +114._ +32._ ?(#1=#13){+50._} ?(#1=#14){+50._} +32._ +87._ +105._ +110._ +115._ +33._ #10. #10. ~
} } }
?(#2=#5){ ?(#5=#8){ ?(#2>78){
+71._ +97._ +109._ +101._ +32._ +79._ +118._ +101._ +114._ +46._ +32._ +80._ +108._ +97._ +121._ +101._ +114._ +32._ ?(#2=#13){+50._} ?(#2=#14){+50._} +32._ +87._ +105._ +110._ +115._ +33._ #10. #10. ~
} } }
?(#3=#6){ ?(#6=#9){ ?(#3>78){
+71._ +97._ +109._ +101._ +32._ +79._ +118._ +101._ +114._ +46._ +32._ +80._ +108._ +97._ +121._ +101._ +114._ +32._ ?(#3=#13){+50._} ?(#3=#14){+50._} +32._ +87._ +105._ +110._ +115._ +33._ #10. #10. ~
} } }
"If a diagnol contains 3 of a kind"
?(#1=#5){ ?(#5=#9){ ?(#1>78){
+71._ +97._ +109._ +101._ +32._ +79._ +118._ +101._ +114._ +46._ +32._ +80._ +108._ +97._ +121._ +101._ +114._ +32._ ?(#1=#13){+50._} ?(#1=#14){+50._} +32._ +87._ +105._ +110._ +115._ +33._ #10. #10. ~
} } }
?(#3=#5){ ?(#5=#7){ ?(#3>78){
+71._ +97._ +109._ +101._ +32._ +79._ +118._ +101._ +114._ +46._ +32._ +80._ +108._ +97._ +121._ +101._ +114._ +32._ ?(#3=#13){+50._} ?(#3=#14){+50._} +32._ +87._ +105._ +110._ +115._ +33._ #10. #10. ~
} } }
"================================================================"
"End Game Loop
================================================================"
}5