From cc9e85f2359131c44fead3f77ee6ae4350080183 Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Fri, 4 Jul 2008 21:01:10 +0100 Subject: [PATCH] Added a new, slightly good player, WallFollower. --- players/WallFollowerPlayer.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 players/WallFollowerPlayer.py diff --git a/players/WallFollowerPlayer.py b/players/WallFollowerPlayer.py new file mode 100644 index 0000000..e0a0026 --- /dev/null +++ b/players/WallFollowerPlayer.py @@ -0,0 +1,36 @@ +from troncode_values import * + +class WallFollowerPlayer( object ): + """Sticks as close to the wall as possible.""" + + def __init__( self ): + pass + + def GetColour( self ): + return ( 255, 200, 128 ) + + def GetName(): + return "WallFollower" + GetName = staticmethod( GetName ) + + def GetDir( self, position, direction, gameboard ): + """Stick as close as possible to any wall you find.""" + + ret_dir = direction + + # Turn left if we can + if gameboard.GetRelativePixel( position, direction, 0, -1 ) == 0: + ret_dir = gameboard.TurnLeft( ret_dir ) + + # Don't enter tunnels of width 1 + if ( gameboard.GetRelativePixel( position, ret_dir, 1, 1 ) > 0 and + gameboard.GetRelativePixel( position, ret_dir, 1, -1 ) > 0 ): + ret_dir = gameboard.TurnRight( ret_dir ) + + # Avoid immediate death by turning right + for i in range( 4 ): + if gameboard.GetRelativePixel( position, ret_dir, 1, 0 ) == 0: + break + ret_dir = gameboard.TurnRight( ret_dir ) + + return ret_dir -- 2.11.4.GIT