1 from troncode_values
import *
4 class FollowerPlayer( object ):
8 # LeftOrRight{-1,0,1} X UpOrDown{-1,0,1} -> Dir{ 0, 1, 2, 3 }
9 whereTable
= [ [ 0, 3, 0 ],
14 # CurrentDir{0,1,2,3} X NextDir{0,1,2,3} -> Dir( -1: Left, None: Left/Right, 1: Right )
15 dirTable
= [ [ 0, 1, None, -1 ],
23 def GetColour( self
):
24 return ( 255, 128, 0 )
28 GetName
= staticmethod( GetName
)
30 def GetDir( self
, position
, direction
, gameboard
):
31 """Stick as close as possible to any wall you find."""
33 pos
= gameboard
.GetPlayerPositions( )
34 #print "my-position: ", position
35 #print "my-direction: ", direction
40 #print "your-position: ", p[0]
41 #print "your-direction: ", p[1]
42 if p
[0][0] < position
[0]:
44 elif p
[0][0] == position
[0]:
49 if p
[0][1] < position
[1]:
51 elif p
[0][1] == position
[1]:
56 #print "LeftOrRight: ", leftOrRight
57 #print "UpOrDown: ", upOrDown
59 where
= FollowerPlayer
.whereTable
[ leftOrRight
+ 1 ][upOrDown
+ 1 ]
60 #print "---> where: ", where
66 dir = FollowerPlayer
.dirTable
[ direction
][ where
]
67 #print "---> dir: ", dir
68 if dir==-1 or dir is None:
78 if gameboard
.GetRelativePixel( position
, direction
, 0, -1 ) == 0:
79 ret_dir
= gameboard
.TurnLeft( ret_dir
)
81 # Don't enter tunnels of width 1
82 if ( gameboard
.GetRelativePixel( position
, ret_dir
, 1, 1 ) > 0 and
83 gameboard
.GetRelativePixel( position
, ret_dir
, 1, -1 ) > 0 ):
84 ret_dir
= gameboard
.TurnRight( ret_dir
)
86 # Avoid immediate death by turning right
88 if gameboard
.GetRelativePixel( position
, ret_dir
, 1, 0 ) == 0:
90 ret_dir
= gameboard
.TurnRight( ret_dir
)