Added a new, slightly good player, WallFollower.
[troncode.git] / players / WallFollowerPlayer.py
blobe0a0026df926193567483aeeb54c4f0adb566541
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, 200, 128 )
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