Print a success message when Selfish Git's tests pass.
[troncode.git] / players / WallFollowerPlayer.py
blob4c1900810dfbcac3a58208f5d421d7b87ce639ea
1 from troncode_values import *
3 class WallFollowerPlayer( object ):
4 """Sticks as close to the wall as possible."""
6 def __init__( self ):
7 pass
9 def GetColour( self ):
10 return ( 255, 255, 253 )
12 def GetName():
13 return "WallFollower"
14 GetName = staticmethod( GetName )
16 def GetDir( self, position, direction, gameboard ):
17 """Stick as close as possible to any wall you find."""
19 ret_dir = direction
21 # Turn left if we can
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
31 for i in range( 4 ):
32 if gameboard.GetRelativePixel( position, ret_dir, 1, 0 ) == 0:
33 break
34 ret_dir = gameboard.TurnRight( ret_dir )
36 return ret_dir