Changes

Jump to navigation Jump to search
Line 23: Line 23:  
=== Strategy ===
 
=== Strategy ===
   −
The default strategy is simple: choose a random direction and go there if the dot is open.
+
In this strategy, the turtle moves down, regardless of whether the dot is open.
 +
<pre>
 +
def _turtle_strategy(self, turtle):
 +
    turtle[1] +=1
 +
    return turtle
 +
</pre>
 +
 
 +
In this strategy, the turtle moves down until it is blocked.
 +
<pre>
 +
def _turtle_strategy(self, turtle):
 +
    if not self._dots[self._grid_to_dot((turtle[0], turtle[1]+1))].type:
 +
      turtle[1] +=1
 +
    return turtle
 +
</pre>
 +
 
 +
In this strategy, the turtle searches for an open dot, looking clockwise.
    
<pre>
 
<pre>
 
def _turtle_strategy(self, turtle):
 
def _turtle_strategy(self, turtle):
 
     c = turtle[1] % 2
 
     c = turtle[1] % 2
    n = int(uniform(0, 6))
   
     for i in range(6):
 
     for i in range(6):
         col = turtle[0] + CIRCLE[c][(i + n) % 6][0]
+
         col = turtle[0] + CIRCLE[c][i][0]
         row = turtle[1] + CIRCLE[c][(i + n) % 6][1]
+
         row = turtle[1] + CIRCLE[c][i][1]
 
         if not self._dots[self._grid_to_dot((col, row))].type:
 
         if not self._dots[self._grid_to_dot((col, row))].type:
 
             return [col, row]
 
             return [col, row]
Line 37: Line 51:  
</pre>
 
</pre>
   −
In this version, the turtle moves down, regardless of whether the dot is open.
+
In the '''default strategy''', the turtle choose a random direction and goes there if the dot is open.
 +
 
 
<pre>
 
<pre>
 
def _turtle_strategy(self, turtle):
 
def _turtle_strategy(self, turtle):
     turtle[1] +=1
+
     c = turtle[1] % 2
 +
    n = int(uniform(0, 6))
 +
    for i in range(6):
 +
        col = turtle[0] + CIRCLE[c][(i + n) % 6][0]
 +
        row = turtle[1] + CIRCLE[c][(i + n) % 6][1]
 +
        if not self._dots[self._grid_to_dot((col, row))].type:
 +
            return [col, row]
 
     return turtle
 
     return turtle
 
</pre>
 
</pre>
   −
In this version, the turtle moves down until it is blocked.
+
In this strategy, the turtle will go off the edge if it can.
<pre>
  −
def _turtle_strategy(self, turtle):
  −
    if not self._dots[self._grid_to_dot((turtle[0], turtle[1]+1))].type:
  −
      turtle[1] +=1
  −
    return turtle
  −
</pre>
     −
In this version, the turtle will go off the edge if it can.
   
<pre>
 
<pre>
 
def _turtle_strategy(self, turtle):
 
def _turtle_strategy(self, turtle):

Navigation menu