1 from troncode_values
import *
7 COLLAPSE_SEQUENCE
= "LL-RZ3"
8 SEQUENCE_STEP_AWAY
= "LR-Z3"
9 SEQUENCE_STEP_IN
= "RL-Z3"
11 class TunnelMakerPlayer( object ):
12 """An example player to get you started on writing your own. This player
13 creates tunnels to trap opponents."""
16 """Do any required setup here."""
17 self
.state
= MODE_START
19 def GetColour( self
):
20 """Return the colour this light cycle should be displayed on screen."""
21 return ( 218, 165, 32 )
24 """Return the name of this player as it should be displayed."""
25 return "Edmund's Tunnel Maker"
26 GetName
= staticmethod( GetName
)
29 def DebugPrint( self
, what
) :
34 def IssueMove( self
, gameboard
, position
, new_direction
) :
35 """Move in the direction indicated, if not blocked"""
38 if gameboard
.GetRelativePixel( position
, new_direction
, 1, 0 ) == 0:
41 new_direction
= gameboard
.TurnLeft( new_direction
)
43 self
.DebugPrint("Trying " + str(new_direction
) + "...")
46 def CountOccupied(self
, gameboard
, position
, direction
, forward_range
, right_range
) :
47 """How many of this block are occupied?"""
50 for df
in forward_range
:
51 for ds
in right_range
:
52 if gameboard
.GetRelativePixel( position
, direction
, df
, ds
) > 0:
58 def GetDir( self
, position
, direction
, gameboard
):
59 """Repeatedly create a tunnel to lure an opposing player into, then close it
60 so they can't get out"""
62 if (self
.state
== MODE_START
or self
.state
== MODE_NORMAL
) :
64 if (gameboard
.GetRelativePixel( position
, direction
, 1, 0 ) > 0 and
65 gameboard
.GetRelativePixel( position
, direction
, 1, -1 ) == 0) :
66 self
.state
= MODE_SEQUENCE
67 self
.sequence
= SEQUENCE_STEP_AWAY
68 self
.DebugPrint("skim")
69 return self
.GetDir ( position
, direction
, gameboard
)
71 # Found "the side", so collapse the tunnel
72 if (gameboard
.GetRelativePixel( position
, direction
, 1, 0 ) > 0 or
73 gameboard
.GetRelativePixel( position
, direction
, 1, -1 ) > 0) :
74 self
.state
= MODE_SEQUENCE
75 self
.sequence
= COLLAPSE_SEQUENCE
;
76 self
.DebugPrint("jaws")
77 self
.PrintRadar(gameboard
, position
, direction
)
78 return self
.GetDir ( position
, direction
, gameboard
)
80 # Too close -> step out
81 if (gameboard
.GetRelativePixel( position
, direction
, 0, 1 ) > 0 or
82 gameboard
.GetRelativePixel( position
, direction
, 0, 2 ) > 0) :
83 self
.state
= MODE_SEQUENCE
84 self
.sequence
= SEQUENCE_STEP_AWAY
85 self
.DebugPrint("step out")
86 return self
.GetDir ( position
, direction
, gameboard
)
88 # Turn right if there's space
89 elif (self
.state
== MODE_NORMAL
and
90 self
.CountOccupied( gameboard
, position
, direction
,
91 range(-2, 1), range(1, 4)) == 0) :
92 self
.DebugPrint("right")
93 return gameboard
.TurnRight( direction
)
96 return self
.IssueMove(gameboard
, position
, direction
)
99 if (self
.state
== MODE_SEQUENCE
) :
100 action
= self
.sequence
[0]
101 self
.sequence
= self
.sequence
[1:]
102 self
.DebugPrint("S[" + action
+ "]")
104 self
.state
= int(self
.sequence
[0])
105 self
.DebugPrint("Z = " + str(self
.state
))
106 return self
.GetDir ( position
, direction
, gameboard
)
107 elif (action
== "R") :
108 return gameboard
.TurnRight( direction
)
109 elif (action
== "L") :
110 return gameboard
.TurnLeft( direction
)
111 elif (action
== "-") :
112 return self
.IssueMove(gameboard
, position
, direction
);
116 print "no direction!!!\a"
119 def PrintRadar( self
, gameboard
, position
, direction
) :
120 """Debug dump of what we can see"""
122 # print "" + str(gameboard.GetRelativePixel(position, direction, 2, -1)) + "-" + \
123 # str(gameboard.GetRelativePixel(position, direction, 2, 0)) + "-" + \
124 # str(gameboard.GetRelativePixel(position, direction, 2, 1))
126 # print str(gameboard.GetRelativePixel(position, direction, 1, -1)) + "-" + \
127 # str(gameboard.GetRelativePixel(position, direction, 1, 0)) + "-" + \
128 # str(gameboard.GetRelativePixel(position, direction, 1, 1))
129 # print str(gameboard.GetRelativePixel(position, direction, 0, -1)) + "-" + \
131 # str(gameboard.GetRelativePixel(position, direction, 0, 1))