def play_turn(self, wm, turn): """ This method is called once for every turn. This specific example solution returns a random action. Parameters: wm - an instance of the WorldModel class that contains an attribute called sensors of class Sensors. Sensors contains the boolean attributes: breeze, stench, glitter, bump and scream. turn - an integer, the index of the turn. If you receive twice the same number, don't worry, just ignore it. Returns: A Command instance - a Command contains an attribute called action of type int. action must be one of the Action attributes: FORWARD, TURNRIGHT, TURNLEFT, STAY, SHOOT, GRAB and CLIMB. """ command = Command() move = randint(0, 2) print str(turn) + ":", if move == 0: print "FORWARD" command.action = Action.FORWARD elif move == 1: print "TURNRIGHT" command.action = Action.TURNRIGHT else: print "TURNLEFT" command.action = Action.TURNLEFT return command
def play_turn(self, wm, moveList, turn): """ This method is called once for every turn. This specific example solution stores a matrix with the snakes bodies (as 0 or 1, with -1 as empty cell) and returns a random valid direction. Parameters: wm - an instance of the WorldModel class that contains a field called players which is a list of Players. A Player has a field named body which is a list of Coordinates, and which represent the coordinates of the body parts of the snake, in order. A Coordinate has two fields, x and y, of type int. turn - an integer, the index of the turn. If you receive twice the same number, don't worry, just ignore it. Returns: A Command instance - a Command contains a field called direction of type int, which can be one of the Direction values: RIGHT, UP, LEFT, DOWN. """ command = Command() command.direction = Direction.UP if moveList: command = choice(moveList) print str(turn) + ": " + str(command.direction) return command
def play_turn(self, wm, turn): """ This method is called once for every turn. This specific example solution stores a matrix with the snakes bodies (as 0 or 1, with -1 as empty cell) and returns a random valid direction. Parameters: wm - an instance of the WorldModel class that contains a field called players which is a list of Players. A Player has a field named body which is a list of Coordinates, and which represent the coordinates of the body parts of the snake, in order. A Coordinate has two fields, x and y, of type int. turn - an integer, the index of the turn. If you receive twice the same number, don't worry, just ignore it. Returns: A Command instance - a Command contains a field called direction of type int, which can be one of the Direction values: RIGHT, UP, LEFT, DOWN. """ print len(self.table) # Place new heads self.table[wm.players[0].body[-1].x][wm.players[0].body[-1].y] = 0 self.table[wm.players[1].body[-1].x][wm.players[1].body[-1].y] = 1 # Print the board print "Turn", turn for i in range(self.width): for j in range(self.height): if self.table[i][j] == self.me: print 'M', elif self.table[i][j] == 1 - self.me: print 'O', else: print '.', print print command = Command() command.direction = Direction.DOWN # Randomly choose a direction indexes = range(4) shuffle(indexes) for i in indexes: newx = wm.players[self.me].body[-1].x + dx[i] newy = wm.players[self.me].body[-1].y + dy[i] if self.isValid(newx, newy) and self.table[newx][newy] == -1: command.direction = dirs[i] break return command
def play_turn(self, wm, moveList, turn): """ This method is called once for every turn. This specific example solution tries to move the checkers at the highest points. However, it is not complete, so it sometimes sends invalid commands. Parameters: wm - an instance of the WorldModel class that contains the following fields: bar - type Point. The number of checkers for each player in the bar. board - list of Point. Always contains 24 elements. borne_off - type Point. The number of checkers that each player has borne off. dice - list of int. Always contains 2 elements. A Point is an alias for a list of int, with 2 elements, that represent the number of red and white checkers in that point, in that order. Hint: rembember that RED=0 and WHITE=1. Remember that a "point" is that triangle on the board where the checkers can be. turn - the index of the turn. If you receive twice the same number, don't worry, just ignore it. Returns: A Command instance - a Command contains a field called moves, which is a list of Move. A Move contains two fields of type int, src and dst. src and dst must be in the interval [0, 24). Additionally, src can be FROM_BAR and dst can be BEAR_OFF. """ command = Command() if moveList: command = choice(moveList) print str(turn) + ": " + str(command.moves) return command
def play_turn(self, wm, moveList, turn): """ This method is called once for every turn. This specific example solution returns a random action. Parameters: wm - an instance of the WorldModel class that contains an attribute called sensors of class Sensors. Sensors contains the boolean attributes: breeze, stench, glitter, bump and scream. turn - an integer, the index of the turn. If you receive twice the same number, don't worry, just ignore it. Returns: A Command instance - a Command contains an attribute called action of type int. action must be one of the Action attributes: FORWARD, TURNRIGHT, TURNLEFT, STAY, SHOOT, GRAB and CLIMB. """ command = Command() if moveList: command = random.choice(moveList) print str(turn) + ": " + str(command.action) return command
def play_turn(self, wm, moveList, turn): """ This method is called once for every turn. This specific example solution returns a random valid position. Parameters: wm - an instance of the WorldModel class that contains a field called table which is a list of lists of ints, which can have on of the Marker values. turn - an integer, the index of the turn. If you receive twice the same number, don't worry, just ignore it. Returns: A Command instance - a Command contains a field called coordinate of class coordinate. A Coordinate contains two fields of type int, x and y. """ command = Command(Coordinate()) if moveList: command = choice(moveList) print "%d: %s" % (turn, repr(command.coordinate)) return command