Skip to content

Commit d775df4

Browse files
committed
Add everything
1 parent 20ac6e1 commit d775df4

10 files changed

+267
-0
lines changed

TuringMachine

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 20ac6e1a21d66c059d34244e08ef0348624dfbe3

TuringMachine.py

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import time, sys
2+
3+
VIEW_DISTANCE = 10
4+
5+
class TuringStrip():
6+
def __init__(self):
7+
self.data = []
8+
9+
def __setitem__(self, n, value):
10+
if(value and (n not in self.data)):
11+
self.data.append(n)
12+
elif((not value) and (n in self.data)):
13+
del self.data[self.data.find(n)]
14+
15+
def __getitem__(self, n):
16+
return (n in self.data)
17+
18+
def disp(phase):
19+
turingString = ""
20+
for i in range(head-VIEW_DISTANCE, head+VIEW_DISTANCE+1):
21+
if(i == 0):
22+
bw = "□■"
23+
else:
24+
bw = "◯●"
25+
turingString += bw[int(t[i])]
26+
sys.stdout.buffer.write(b"\033[34m" + turingString.encode("utf-8") + b"\n")
27+
print((" " * VIEW_DISTANCE) + "^" + (chr(65 + state) if state != -1 else "HALT"))
28+
print(phase + " \n\033[A\033[A\033[A\033[A")
29+
time.sleep(speed)
30+
31+
def turingDo(write, move, nextstate):
32+
global t, head, state
33+
if(write != -1):
34+
t[head] = write
35+
disp("WRITE " + str(write))
36+
head += move
37+
disp("MOVE BY " + str(move))
38+
state = nextstate
39+
disp("TO STATE " + (chr(65 + state) if state != -1 else "HALT"))
40+
41+
state = 0
42+
43+
t = TuringStrip()
44+
45+
head = 0
46+
47+
speed = float(input("\033[32mDelay? " + ("\033[D" * 5)))
48+
49+
disp("STARTING POSITION")
50+
51+
from ThreeStateTwoSymbolBusyBeaver import states
52+
53+
while state != -1:
54+
read = t[head]
55+
turingDo(*states[state][read])
56+
## if(state == "A"):
57+
## if(read):
58+
## turingDo(1, -1, "C")
59+
## else:
60+
## turingDo(1, 1, "B")
61+
## elif(state == "B"):
62+
## if(read):
63+
## turingDo(1, 1, "B")
64+
## else:
65+
## turingDo(1, -1, "A")
66+
## elif(state == "C"):
67+
## if(read):
68+
## turingDo(1, 1, "HALT")
69+
## else:
70+
## turingDo(1, -1, "B")
71+
print("\n\n")

Turing_3_2_BB.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/python3
2+
# 3 2 BB
3+
# | | ___/¯¯\__
4+
# | | | |
5+
# 3 state, 2 symbol busy beaver
6+
states = (
7+
( #A (index 0)
8+
(1, 1, 1), #0, (BitToWrite, MoveBy, NextStateIndex)
9+
(1, -1, 2) #1
10+
), ( #B (index 1)
11+
(1, -1, 0),
12+
(1, 1, 1)
13+
), ( #C (index 2)
14+
(1, -1, 1),
15+
(1, 0, -1)
16+
)
17+
)

Turing_4_2_BB.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/python3
2+
# 4 2 BB
3+
# | | ___/¯¯\__
4+
# | | | |
5+
# 4 state, 2 symbol busy beaver
6+
states = (
7+
( #A (index 0)
8+
(1, 1, 1), #0, (BitToWrite, MoveBy, NextStateIndex)
9+
(1, -1, 1) #1
10+
), ( #B (index 1)
11+
(1, -1, 0),
12+
(0, -1, 2)
13+
), ( #C (index 2)
14+
(1, 1, -1),
15+
(1, -1, 3)
16+
), ( #D (index 3)
17+
(1, 1, 3),
18+
(0, 1, 0)
19+
)
20+
)

Turing_5_2_BB.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/python3
2+
# 5 2 BB
3+
# | | ___/¯¯\__
4+
# | | | |
5+
# 5 state, 2 symbol busy beaver
6+
states = (
7+
( #A (index 0)
8+
(1, 1, 1), #0, (BitToWrite, MoveBy, NextStateIndex)
9+
(1, -1, 2) #1
10+
), ( #B (index 1)
11+
(1, 1, 2),
12+
(1, 1, 1)
13+
), ( #C (index 2)
14+
(1, 1, 3),
15+
(0, -1, 4)
16+
), ( #D (index 3)
17+
(1, -1, 0),
18+
(1, -1, 3)
19+
), ( #E (index 4)
20+
(1, 1, -1),
21+
(0, -1, 0)
22+
)
23+
)

Turing_wiggle.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/python3
2+
3+
states = (
4+
( #A (index 0)
5+
(1, 1, 1), #0, (BitToWrite, MoveBy, NextStateIndex)
6+
(1, 1, 1) #1
7+
), ( #B (index 1)
8+
(1, 0, 2),
9+
(1, -1, 1)
10+
), ( #C (index 2)
11+
(1, 0, 1),
12+
(1, 1, 2)
13+
)
14+
)

Turmite.py

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import time, sys, pygcurse, pygame
2+
3+
VIEW_DISTANCE = 15
4+
FONTSIZE = 10
5+
STATECOLORS = ["red", (0, 255, 255), (0, 255, 0)]
6+
7+
class TuringStrip():
8+
def __init__(self):
9+
self.data = []
10+
11+
def __setitem__(self, nn, value):
12+
n = tuple(nn)
13+
if(value and (n not in self.data)):
14+
self.data.append(n)
15+
elif((not value) and (n in self.data)):
16+
del self.data[self.data.index(n)]
17+
18+
def __getitem__(self, nn):
19+
n = tuple(nn)
20+
return (n in self.data)
21+
22+
def disp():
23+
turingString = ""
24+
for i in range(head[0]-VIEW_DISTANCE, head[0]+VIEW_DISTANCE+1):
25+
for j in range(head[1]-VIEW_DISTANCE, head[1]+VIEW_DISTANCE+1):
26+
if(i == 0 and j == 0):
27+
bw = "◇◆"
28+
elif(i == 0 or j == 0):
29+
bw = "□■"
30+
else:
31+
bw = "◯●"
32+
bw = bw[0] + "█"
33+
turingString += bw[int(t[i, j])]
34+
turingString += "\n"
35+
win.putchars(turingString, fgcolor=(0, 255, 0), bgcolor="black")
36+
i, j = head
37+
if(i == 0 and j == 0):
38+
bw = "◇◆"
39+
elif(i == 0 or j == 0):
40+
bw = "□■"
41+
else:
42+
bw = "◯●"
43+
win.putchar(bw[int(t[i, j])], x=VIEW_DISTANCE, y=VIEW_DISTANCE, fgcolor=STATECOLORS[state])
44+
win.update()
45+
time.sleep(speed)
46+
47+
def turingDo(write, turn, nextstate):
48+
global t, head, dir, state
49+
if(write != -1):
50+
t[head] = write
51+
dir = (dir + turn) % 4
52+
state = nextstate
53+
54+
head = [0, 0]
55+
dir = 3
56+
57+
t = TuringStrip()
58+
pygame.init()
59+
win = pygcurse.PygcurseWindow((VIEW_DISTANCE * 2) + 1,
60+
(VIEW_DISTANCE * 2) + 1,
61+
"Turmites",
62+
font=pygame.font.SysFont("wenquanyimicroheimono", FONTSIZE))
63+
64+
speed = 0.01
65+
state = 0
66+
moves = 0
67+
disp()
68+
69+
from Worm_Lantingtons_Ant import states
70+
71+
import random
72+
while True:
73+
read = t[head]
74+
turingDo(*states[state][read])
75+
if(dir == 0):
76+
head[1] += 1
77+
elif(dir == 1):
78+
head[0] += 1
79+
elif(dir == 2):
80+
head[1] -= 1
81+
elif(dir == 3):
82+
head[0] -= 1
83+
moves += 1
84+
disp()
85+
for event in pygame.event.get():
86+
if event.type == pygame.locals.QUIT:
87+
pygame.quit()
88+
sys.exit()
89+

Worm_CW.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/python3
2+
3+
states = (
4+
( #A (index 0)
5+
(1, 1, 1), #0, (BitToWrite, MoveBy, NextStateIndex)
6+
(1, 1, 0) #1
7+
),
8+
( #B (index 1)
9+
(0, 1, 0),
10+
(0, 1, 0)
11+
)
12+
)

Worm_Lantingtons_Ant.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/python3
2+
3+
states = (
4+
( #A (index 0)
5+
(1, 1, 0), #0, (BitToWrite, TurnBy, NextStateIndex)
6+
(0, -1, 0)
7+
),
8+
)

Worm_One.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/python3
2+
3+
states = (
4+
( #A (index 0)
5+
(1, 1, 0), #0, (BitToWrite, MoveBy, NextStateIndex)
6+
(1, 1, 1) #1
7+
),
8+
( #B (index 1)
9+
(0, 0, 0),
10+
(0, 0, 1)
11+
)
12+
)

0 commit comments

Comments
 (0)