예제 #1
0
파일: tests.py 프로젝트: peterrecore/plyus
    def do_ai_test(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)
        num_steps = 100 * len(players)

        for i in range(num_steps):
            logging.debug("On step %s of simulation" % i)
            cur_plyr = game.players[game.cur_player_index]
            logging.debug("Cur plyr index is %s" % game.cur_player_index)
            logging.debug("Cur plyr is %s" % cur_plyr)
            cur_ai = ais[cur_plyr.name]
            move = cur_ai.decide_what_to_do_native(game)
            ref.perform_move(move)
            #            logging.warning("Stage is %s" % game.stage)
            if game.stage == Stage.GAME_OVER:
                logging.warning("**********************************************")
                logging.warning("******* Success, game over and %s won   ******" % game.winner)
                for p in game.players:
                    logging.warning("Player %s had %s pts" % (p.name, p.points))
                return 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")
예제 #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)
예제 #3
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)
예제 #4
0
파일: tests.py 프로젝트: peterrecore/plyus
    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")
예제 #5
0
    def do_test_using_json_from_file(self, file, move_set):
        players = [fake_player("peter"), fake_player("manan")]

        test_deck = Building.create_deck_from_csv('decks/deck_test_30.csv')
        game = GameState()
        game.initialize_game(42, players, deck=test_deck)

        ref = Referee(r, game)

        with open(file) as f:
            move_sets = json.loads(f.read())

        moves = move_sets[move_set]
        for move in moves:
            ref.perform_move(move)
예제 #6
0
파일: tests.py 프로젝트: peterrecore/plyus
    def do_test_using_json_from_file(self, file, move_set):
        players = [fake_player("peter"), fake_player("manan")]

        test_deck = Building.create_deck_from_csv('decks/deck_test_30.csv')
        game = GameState()
        game.initialize_game(42, players, deck=test_deck)

        ref = Referee(r, game)

        with open(file) as f:
            move_sets = json.loads(f.read())

        moves = move_sets[move_set]
        for move in moves:
            ref.perform_move(move)
예제 #7
0
파일: tests.py 프로젝트: peterrecore/plyus
    def test_wrong_turn(self):
        with self.assertRaises(NotYourTurnError):
            players = [fake_player("Peter"), fake_player("Manan")]
            game = GameState(42, players[0], 2, deck_template='decks/default.csv')
            game.add_player(players[1])
            game.start_game()

            ref = Referee(game)

            with open("tests/moves.json") as f:
                move_sets = json.loads(f.read())

            moves = move_sets["wrong_turn"]
            for move in moves:
                ref.perform_move(move)
예제 #8
0
    def test_wrong_turn(self):
        with self.assertRaises(NotYourTurnError):
            players = [fake_player("Peter"), fake_player("Manan")]
            game = GameState(42,
                             players[0],
                             2,
                             deck_template='decks/default.csv')
            game.add_player(players[1])
            game.start_game()

            ref = Referee(game)

            with open("tests/moves.json") as f:
                move_sets = json.loads(f.read())

            moves = move_sets["wrong_turn"]
            for move in moves:
                ref.perform_move(move)
예제 #9
0
    def do_ai_test(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)
        num_steps = 100 * len(players)

        for i in range(num_steps):
            logging.debug("On step %s of simulation" % i)
            cur_plyr = game.players[game.cur_player_index]
            logging.debug("Cur plyr index is %s" % game.cur_player_index)
            logging.debug("Cur plyr is %s" % cur_plyr)
            cur_ai = ais[cur_plyr.name]
            move = cur_ai.decide_what_to_do_native(game)
            ref.perform_move(move)
            #            logging.warning("Stage is %s" % game.stage)
            if game.stage == Stage.GAME_OVER:
                logging.warning(
                    "**********************************************")
                logging.warning(
                    "******* Success, game over and %s won   ******" %
                    game.winner)
                for p in game.players:
                    logging.warning("Player %s had %s pts" %
                                    (p.name, p.points))
                return 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")
예제 #10
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")