-
Notifications
You must be signed in to change notification settings - Fork 0
/
HAD.py
104 lines (89 loc) · 2.31 KB
/
HAD.py
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
from random import randrange
had = [[0,0], [0,1], [0,2], [0, 3], [0,4]]
def vytvor_hada(had, sirka, vyska):
radek = [ "." for i in range(sirka) ]
pole = [ list(radek) for i in range(vyska) ]
if kontrola_kousnuti(had):
return
for a, b in had:
if kontrola_hranic(sirka, vyska, a, b):
pole[a][b] = "o"
else:
return
return pole
def vykresli_pole(pole):
if not pole:
print 'NARAZIL!!'
return
for radek in pole:
print ''.join(radek)
print
def doprava(had):
a,b = had[-1]
b += 1
del had[0]
had.append([a,b])
return had
def doleva(had):
a,b = had[-1]
b -= 1
del had[0]
had.append([a,b])
return had
def nahoru(had):
a,b = had[-1]
a -= 1
del had[0]
had.append([a,b])
return had
def dolu(had):
a,b = had[-1]
a += 1
del had[0]
had.append([a,b])
return had
def kontrola_hranic(sirka, vyska, a, b):
return a < sirka and b < vyska and a >= 0 and b >= 0
def kontrola_kousnuti(had):
for i, prvek1 in enumerate(had):
for prvek2 in had[i+1:]:
if prvek1 == prvek2:
return True
def l(had):
for pohyb in [doleva]:
if had[-1] == had[-2]:
break
had = pohyb(had)
pole_s_hadem = vytvor_hada(had, 10, 10)
vykresli_pole(pole_s_hadem)
if not pole_s_hadem:
break
def p(had):
for pohyb in [doprava]:
if had[-1] == had[-2]:
break
had = pohyb(had)
pole_s_hadem = vytvor_hada(had, 10, 10)
vykresli_pole(pole_s_hadem)
if not pole_s_hadem:
break
def n(had):
for pohyb in [nahoru]:
if had[-1] == had[-2]:
break
had = pohyb(had)
pole_s_hadem = vytvor_hada(had, 10, 10)
vykresli_pole(pole_s_hadem)
if not pole_s_hadem:
break
def d(had):
for pohyb in [dolu]:
if had[-1] == had[-2]:
break
had = pohyb(had)
pole_s_hadem = vytvor_hada(had, 10, 10)
vykresli_pole(pole_s_hadem)
if not pole_s_hadem:
break
pole_s_hadem = vytvor_hada(had, 10, 10)
vykresli_pole(pole_s_hadem)