1 from troncode_values
import *
5 class BobsPlayer( object ):
9 self
.trap_gap
= TRAP_GAP
11 def GetColour( self
):
12 return ( 255, 255, 255 )
16 GetName
= staticmethod( GetName
)
18 def GetAnyWallsInRangeAhead( self
, position
, direction
, gameboard
):
20 for i
in range( 1, self
.trap_gap
):
21 if gameboard
.GetRelativePixel( position
, direction
, i
, 0 ) > 0:
26 def GetAnyWallsInRangeRight( self
, position
, direction
, gameboard
):
29 for i
in range( -1, 1 ):
30 for j
in range( 1, self
.trap_gap
):
31 if gameboard
.GetRelativePixel( position
, direction
, i
, j
) > 0:
36 def GetAnyWallsInRangeLeft( self
, position
, direction
, gameboard
):
39 for i
in range( -1, 1 ):
40 for j
in range( -1, -self
.trap_gap
):
41 if gameboard
.GetRelativePixel( position
, direction
, i
, j
) > 0:
46 def GetDir( self
, position
, direction
, gameboard
):
47 """Turn Left Player but turn right occasionally"""
51 density_ahead
= self
.GetAnyWallsInRangeAhead( position
, direction
, gameboard
)
52 density_left
= self
.GetAnyWallsInRangeLeft( position
, ret_dir
, gameboard
)
53 density_right
= self
.GetAnyWallsInRangeRight( position
, ret_dir
, gameboard
)
55 #Avoid hitting something straight ahead up to self.trap_gap pixels away
56 if ( density_ahead
> 0 ):
57 if ( density_left
== 0 ) :
58 ret_dir
= gameboard
.TurnLeft( direction
)
59 self
.counter
=self
.counter
+1
61 elif ( density_right
== 0 ) :
62 ret_dir
= gameboard
.TurnRight( direction
)
63 self
.counter
=self
.counter
-1
65 elif ( density_left
< density_right
) :
66 ret_dir
= gameboard
.TurnLeft( direction
)
67 self
.counter
=self
.counter
+1
69 elif ( density_right
< density_left
) :
70 ret_dir
= gameboard
.TurnRight( direction
)
71 self
.counter
=self
.counter
-1
73 elif ( self
.counter
> 2 and density_right
== 0 ) :
74 ret_dir
= gameboard
.TurnRight( direction
)
76 # if we're stuck in a box of our own making, best to try and stay alive as long as possible..
77 elif ( self
.counter
> 4 or self
.counter
< -4 ) and ( self
.trap_gap
> 2 ) :
78 self
.trap_gap
=self
.trap_gap
-1