Beispiel #1
0
 def process_ai_move(self, game, ais):
     ref = Referee(game)
     cur_plyr = game.get_cur_plyr()
     cur_ai = ais[cur_plyr.name]
     json = ref.get_current_state_as_json_for_player(cur_plyr.position)
     parsed_json = from_json(json)
     move = cur_ai.decide_what_to_do_json(parsed_json)
     ref.perform_move(move)
     logging.info("After processing ai move, stage is %s ", game.stage)
Beispiel #2
0
 def process_ai_move(self, game, ais):
     ref = Referee(game)
     cur_plyr = game.get_cur_plyr()
     cur_ai = ais[cur_plyr.name]
     json = ref.get_current_state_as_json_for_player(cur_plyr.position)
     parsed_json = from_json(json)
     move = cur_ai.decide_what_to_do_json(parsed_json)
     ref.perform_move(move)
     logging.info("After processing ai move, stage is %s ", game.stage)
Beispiel #3
0
    def do_ai_test_with_json(self, seed, num_players):
        names = ['PeterAI', 'MananAI', 'AndyAI', 'MarkAI', 'KevinAI', 'RyanAI', 'TabithaAI']
        ais = {}
        players = []
        for n in names[0:num_players]:
            ais[n] = SimpleAIPlayer(n)
            players.append(Player(n))

        game = GameState(seed, players[0], num_players, deck_template='decks/deck_test_60.csv')
        for p in players[1:num_players]:
            game.add_player(p)
        game.start_game()

        ref = Referee(game)

        json = ref.get_current_state_as_json_for_player(game.cur_player_index)
        parsed_json = from_json(json)
        json_game = parsed_json['game']

        game = None #force ourselves to use json from now on, and fail fast if
        #accidentally use game

        num_steps = 100 * len(players)

        logging.debug(json)

        for i in range(num_steps):
            logging.debug("On step %s of simulation" % i)
            cur_plyr = json_game['players'][json_game['cur_player_index']]
            cur_ai = ais[cur_plyr['name']]
            move = cur_ai.decide_what_to_do_json(parsed_json)
            json = ref.perform_move(move)
            parsed_json = from_json(json)
            json_game = parsed_json['game']
            stage = json_game['stage']
            if stage not in [Stage.GAME_OVER, Stage.END_GAME, Stage.PLAYING]:
                self.assertTrue(False, "stage is not valid: %s" % stage)
            logging.debug("stage is %s" % stage)
            if stage == Stage.GAME_OVER:
                logging.warning("**********************************************")
                logging.warning("******* Success, game over and %s won after %s rounds  ******" % (
                json_game['winner'], json_game['round_num']))
                json_players = json_game['players']

                buffer = ""
                for p in json_players:
                    buffer += "Player %s had %s pts, " % (p['name'], p['points'])
                logging.warning(buffer)
                return json_game['round_num']
        logging.error("Didn't finish game in %s steps, ending test" % num_steps)
        self.assertTrue(False, "didn't finish game in right amount of steps")
Beispiel #4
0
    def do_ai_test_with_json(self, seed, num_players):
        names = [
            'PeterAI', 'MananAI', 'AndyAI', 'MarkAI', 'KevinAI', 'RyanAI',
            'TabithaAI'
        ]
        ais = {}
        players = []
        for n in names[0:num_players]:
            ais[n] = SimpleAIPlayer(n)
            players.append(Player(n))

        game = GameState(seed,
                         players[0],
                         num_players,
                         deck_template='decks/deck_test_60.csv')
        for p in players[1:num_players]:
            game.add_player(p)
        game.start_game()

        ref = Referee(game)

        json = ref.get_current_state_as_json_for_player(game.cur_player_index)
        parsed_json = from_json(json)
        json_game = parsed_json['game']

        game = None  #force ourselves to use json from now on, and fail fast if
        #accidentally use game

        num_steps = 100 * len(players)

        logging.debug(json)

        for i in range(num_steps):
            logging.debug("On step %s of simulation" % i)
            cur_plyr = json_game['players'][json_game['cur_player_index']]
            cur_ai = ais[cur_plyr['name']]
            move = cur_ai.decide_what_to_do_json(parsed_json)
            json = ref.perform_move(move)
            parsed_json = from_json(json)
            json_game = parsed_json['game']
            stage = json_game['stage']
            if stage not in [Stage.GAME_OVER, Stage.END_GAME, Stage.PLAYING]:
                self.assertTrue(False, "stage is not valid: %s" % stage)
            logging.debug("stage is %s" % stage)
            if stage == Stage.GAME_OVER:
                logging.warning(
                    "**********************************************")
                logging.warning(
                    "******* Success, game over and %s won after %s rounds  ******"
                    % (json_game['winner'], json_game['round_num']))
                json_players = json_game['players']

                buffer = ""
                for p in json_players:
                    buffer += "Player %s had %s pts, " % (p['name'],
                                                          p['points'])
                logging.warning(buffer)
                return json_game['round_num']
        logging.error("Didn't finish game in %s steps, ending test" %
                      num_steps)
        self.assertTrue(False, "didn't finish game in right amount of steps")