1 from troncode_values
import *
3 TRAP_SEQUENCE_R
= "R RLL LLR R"
4 TRAP_SEQUENCE_L
= "L LRR RRL L "
8 class PeteZeroZeroOnePlayer ( object ):
12 self
.previousDirection
= -1
15 self
.counter
= TRAP_GAP
16 self
.real_dir
= DIR_UP
17 self
.trap_gap
= TRAP_GAP
21 def GetColour( self
):
22 return ( 255, 255, 254 )
25 return "Pete Zero Zero One"
26 GetName
= staticmethod( GetName
)
28 def GetDir( self
, position
, direction
, gameboard
):
30 if self
.previousDirection
== -1:
31 self
.previousDirection
= direction
33 returnDirection
= direction
36 #calculate the size of the board
37 if self
.gameBoardY
== -1:
38 self
.gameBoardX
= position
[0]
39 self
.gameBoardY
= position
[1]
40 tempPosition
= self
.gameBoardX
, self
.gameBoardY
44 if gameboard
.GetRelativePixel( tempPosition
, DIR_RIGHT
, 0, 3) == 0:
45 self
.gameBoardY
= self
.gameBoardY
+ 3;
46 tempPosition
= self
.gameBoardX
,self
.gameBoardY
52 if gameboard
.GetRelativePixel( tempPosition
, DIR_RIGHT
, 3, 0) == 0:
53 self
.gameBoardX
= self
.gameBoardX
+ 3;
54 tempPosition
= self
.gameBoardX
,self
.gameBoardY
59 if position
[0] > ( self
.gameBoardX
/ 2 ):
60 returnDirection
= DIR_LEFT
61 elif position
[0] < ( self
.gameBoardX
/ 2 ):
62 returnDirection
= DIR_RIGHT
64 if position
[1] > ( self
.gameBoardY
/ 2 ):
65 returnDirection
= DIR_DOWN
66 elif position
[1] < ( self
.gameBoardY
/ 2 ):
67 returnDirection
= DIR_UP
70 #Shamelessly pillaged from the code of others
71 # Avoid our own traps by not entering tunnels of width 1
72 if ( gameboard
.GetRelativePixel( position
, returnDirection
, 1, 1 ) > 0 and
73 gameboard
.GetRelativePixel( position
, returnDirection
, 1, -1 ) > 0 ):
74 returnDirection
= gameboard
.TurnRight( returnDirection
)
75 self
.counter
= self
.trap_gap
76 # Avoid immediate death by turning back the way we were going
77 if gameboard
.GetRelativePixel( position
, returnDirection
, 1, 0 ) > 0:
78 returnDirection
= self
.real_dir
79 self
.counter
= self
.trap_gap
80 # Avoid immediate death by turning right
82 if gameboard
.GetRelativePixel( position
, returnDirection
, 1, 0 ) == 0:
84 returnDirection
= gameboard
.TurnRight( returnDirection
)
85 self
.counter
= self
.trap_gap
90 self
.previousDirection
= returnDirection
92 return returnDirection