Print a success message when Selfish Git's tests pass.
[troncode.git] / players / PeteZeroZeroOnePlayer.py
blobf5dfde62fb5361c590b92305243a512bae30795e
1 from troncode_values import *
2 import time
3 TRAP_SEQUENCE_R = "R RLL LLR R"
4 TRAP_SEQUENCE_L = "L LRR RRL L "
6 TRAP_GAP = 20
7 TRAP_MULT = 1.6
8 class PeteZeroZeroOnePlayer ( object ):
10 def __init__( self ):
11 self.players = ()
12 self.previousDirection = -1
13 self.gameBoardX = -1
14 self.gameBoardY = -1
15 self.counter = TRAP_GAP
16 self.real_dir = DIR_UP
17 self.trap_gap = TRAP_GAP
19 pass
21 def GetColour( self ):
22 return ( 255, 255, 254 )
24 def GetName():
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
42 x = True
43 while x == True:
44 if gameboard.GetRelativePixel( tempPosition, DIR_RIGHT, 0, 3) == 0:
45 self.gameBoardY = self.gameBoardY + 3;
46 tempPosition = self.gameBoardX,self.gameBoardY
47 else:
48 x = False
50 x = True
51 while x == True:
52 if gameboard.GetRelativePixel( tempPosition, DIR_RIGHT, 3, 0) == 0:
53 self.gameBoardX = self.gameBoardX + 3;
54 tempPosition = self.gameBoardX,self.gameBoardY
55 else:
56 x = False
59 if position[0] > ( self.gameBoardX / 2 ):
60 returnDirection = DIR_LEFT
61 elif position[0] < ( self.gameBoardX / 2 ):
62 returnDirection = DIR_RIGHT
63 else:
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
81 for i in range( 4 ):
82 if gameboard.GetRelativePixel( position, returnDirection, 1, 0 ) == 0:
83 break
84 returnDirection = gameboard.TurnRight( returnDirection )
85 self.counter = self.trap_gap
90 self.previousDirection = returnDirection
91 """time.sleep(0.1)"""
92 return returnDirection