round_walk.py 805 Bytes
Newer Older
Ahmad Reza's avatar
Ahmad Reza committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import logging
import random


NE = 0
E = 1
SE = 2
SW = 3
W = 4
NW = 5


direction = [NE, E, SE, SW, W, NW]

ttl = 0
dir = NE
max = 0



21
def solution(sim):
Ahmad Reza's avatar
Ahmad Reza committed
22

23
    for particle in sim.get_particle_list():
Ahmad Reza's avatar
Ahmad Reza committed
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
        global ttl
        global max
        global dir

        if sim.get_actual_round() == 0:
            max = 0
            ttl = 0
            dir = NE

        if (ttl==0 and (dir==NE or dir==SW)):
            max = max+1

        if ttl==0:
            print("Round ", sim.get_actual_round())
            ttl=max
            if dir==NE:
                dir=NW
            elif dir==NW:
                dir=SW
            elif dir==SW:
                dir=SE
            elif dir==SE:
                dir=NE

        particle.create_location()
        particle.move_to(dir)
        ttl = ttl - 1