1 from troncode_values
import *
8 class FanRandomPlayer( object ):
14 def GetColour( self
):
15 return ( 255, 255, 0 )
18 return "Fan Zhang's Random Player!"
19 GetName
= staticmethod( GetName
)
21 def ProbeEnemies(self
, position
, gameboard
):
22 enemies
= gameboard
.GetPlayerPositions(position
)
23 (my_x
, my_y
) = position
24 for (epos
, edir
) in enemies
:
26 dis
= math
.sqrt((my_x
-x
)*(my_x
-x
) + (my_y
-y
)*(my_y
-y
))
28 return (DANGER
, epos
, edir
)
29 return (SAFE
, None, None)
31 def GetDir( self
, position
, direction
, gameboard
):
39 if self
.step
==0 and x
< y
and x
< ay
and x
< ax
:
41 elif self
.step
==0 and y
< x
and y
< ax
and y
< ay
:
43 elif self
.step
==0 and ax
< ay
and ax
< y
and ax
< x
:
45 elif self
.step
==0 and ay
< ax
and ay
< x
and ay
< y
:
49 if (x
== 0 or x
== 199) and y
> ay
:
51 elif (x
== 0 or x
== 199) and y
<= ay
:
53 elif (y
== 0 or y
== 199) and x
> ax
:
55 elif (y
== 0 or y
== 199) and x
<= ax
:
58 #normal direction for marching
60 ret_dir
= gameboard
.TurnLeft( ret_dir
)
63 ret_dir
= gameboard
.TurnLeft( ret_dir
)
66 player
= self
.ProbeEnemies(position
, gameboard
)
68 if player
[0] == DANGER
:
69 ret_dir
= gameboard
.TurnLeft( ret_dir
)
71 # Don't enter tunnels of width 1
72 if ( gameboard
.GetRelativePixel( position
, ret_dir
, 1, 1 ) > 0 and
73 gameboard
.GetRelativePixel( position
, ret_dir
, 1, -1 ) > 0 ):
74 ret_dir
= gameboard
.TurnRight( ret_dir
)
76 # Avoid immediate death by turning right
78 if gameboard
.GetRelativePixel( position
, ret_dir
, 1, 0 ) == 0:
80 ret_dir
= gameboard
.TurnRight( ret_dir
)
82 self
.step
= self
.step
+1