-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbeaver.py
More file actions
executable file
·72 lines (58 loc) · 1.41 KB
/
beaver.py
File metadata and controls
executable file
·72 lines (58 loc) · 1.41 KB
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Jun 16 13:57:19 2020
@author: aidan
"""
import time
import numpy as np
from random import *
import turing
t0 = time.time()
n = 3
N1 = 200
N2 = 10000
m = turing.machine(n)
t = turing.tape(int(2.1*N1))
'''
2 state solution
m.lst[0].set_write([1,1])
m.lst[1].set_write([1,1])
m.lst[0].set_move([1,-1])
m.lst[1].set_move([-1, 0]
m.lst[0].set_halt([False, False])
m.lst[1].set_halt([False, True])
m.lst[0].set_state([1, 0])
m.lst[1].set_state([0, 1])
'''
scores = [1]
for i in range(N2):
t = turing.tape(int(2.1*N1))
halt_flag = True
#Random guessing
for j in range(n):
m.lst[j].set_write([randint(0,1), randint(0,1)])
m.lst[j].set_move([randint(-1,1), randint(-1,1)])
m.lst[j].set_state([randint(0,n-1), randint(0,n-1)])
m.lst[j].set_halt([False, False])
#Set the halt
m.lst[randint(0,n-1)].set_halt([False, True])
#Current space
pos = t.start
#Iteration count
count = 0
while(m.lst[m.st].halt[t.t[pos]] == False):
pos = m.run(t, pos)
count += 1
if (count > N1):
halt_flag = False
break
score = sum(t.t)
if (halt_flag):
if (score > max(scores)):
print(score)
print(m)
scores.append(score)
scores.sort()
print("Highscore: ", scores[-1])
print("Time: %.2f" %(time.time() - t0))