def __init__(self, nao_motion, nao_video, nao_tts, wait_disc_func, ppA=0.05, cA=0.005, rA=0.8, min_detections=3, dist=-1, sloped=True, nao_strategy=Basic, other_strategy=NAOVision): """ :param nao_motion: an instance of the motion controller of NAO :type nao_motion: nao.controller.motion.MotionController :param nao_video: an instance of the video controller of NAO :type nao_video: nao.controller.video.VideoController :param nao_tts: an instance of the TTS proxy of NAO :type nao_tts: naoqi.ALProxy :param ppA: the perfect position accuracy in meters. While the robot is not located to the perfect position, with a sharper accuracy than ppA, the robot continues to move :param cA: the coordinates accuracy in meters. While the robot's hand has not reached this accuracy, the robot will continue to move to get its hand to a better place. :param rA: the rotation accuracy in radians. While the robot's hand is not inclined with this accuracy compared to the perfect position, the robot will continue to move. :param min_detections: the minimum number of success before a detection is considered as successful :param dist: the distance in meters between NAO and the game board, -1 = unknown :param sloped: True if the game board is sloped from NAO :param nao_strategy: the class that defines NAO's strategy :param other_strategy: the class that defines the other player's strategy """ self.rA = rA self.cA = cA self.ppA = ppA self.estimated_distance = dist self.min_detections = min_detections self.sloped = sloped self.wait_disc_func = wait_disc_func # Setting NAO's controllers self.tts = nao_tts self.nao_motion = nao_motion self.nao_video = nao_video self.camera_subscribed = [False, False] self.current_yaw = self.nao_motion.DEFAULT_HEAD_YAW self.current_pitch = self.nao_motion.DEFAULT_HEAD_PITCH self.yaw_sign = 1 self.pitch_sign = -1 # Connect 4 detectors and models self.c4_model = DefaultModel() self.c4_tracker = Connect4Tracker(self.c4_model) self.c4_handler = Connect4Handler(self.getNaoImage) self.c4_coords = [0, 0, 0, 0, 0, 0] # Creating the strategies that will play the game self.strategy = nao_strategy() if other_strategy is NAOVision: self.other_strategy = NAOVision(self.c4_model.image_of_reference.pixel_mapping, self.c4_handler.front_hole_detector.getPerspective) else: self.other_strategy = other_strategy() # Creating the game and registering the players self.game = Game() self.NAO_player = self.game.registerPlayer(self.strategy) self.human_player = self.game.registerPlayer(self.other_strategy) print "Lancement du jeu, la couleur de NAO est le {0}".format(disc.color_string(self.NAO_player.color)) next_player = "NAO" if not self.game.checkPlayerTurn(self.NAO_player): next_player = "Joueur humain" print "Le premier joueur est : {0}".format(next_player)
def game(args): strategies = {'basic': Basic, 'human': Human} player1 = strategies.get(args['--player1'], None) player2 = strategies.get(args['--player2'], None) if player1 is None: exit("{0} is not a valid strategy. The valid strategies are: basic, human".format(args['--player1'])) if player2 is None: exit("{0} is not a valid strategy. The valid strategies are: basic, human".format(args['--player2'])) print "A new game is created." print print "-1 = Empty, 0 = Red, 1 = Green" print new_game = Game() basic.ALPHA_BETA_MAX_DEPTH = int(args['--max-depth']) new_game.registerPlayer(player1()) color_int = new_game.players[0].color print "Player 1: {0} with color {1} ({2})".format(player1.__name__, disc.color_string(color_int), color_int) new_game.registerPlayer(player2()) color_int = new_game.players[1].color print "Player 2: {0} with color {1} ({2})".format(player2.__name__, disc.color_string(color_int), color_int) print print new_game.playLoop()