1 from troncode_values
import *
3 class WallFollowerPlayer( object ):
4 """Sticks as close to the wall as possible."""
10 return ( 255, 255, 253 )
14 GetName
= staticmethod( GetName
)
16 def GetDir( self
, position
, direction
, gameboard
):
17 """Stick as close as possible to any wall you find."""
22 if gameboard
.GetRelativePixel( position
, direction
, 0, -1 ) == 0:
23 ret_dir
= gameboard
.TurnLeft( ret_dir
)
25 # Don't enter tunnels of width 1
26 if ( gameboard
.GetRelativePixel( position
, ret_dir
, 1, 1 ) > 0 and
27 gameboard
.GetRelativePixel( position
, ret_dir
, 1, -1 ) > 0 ):
28 ret_dir
= gameboard
.TurnRight( ret_dir
)
30 # Avoid immediate death by turning right
32 if gameboard
.GetRelativePixel( position
, ret_dir
, 1, 0 ) == 0:
34 ret_dir
= gameboard
.TurnRight( ret_dir
)