def test_IfBoardIsFlippedTwoTimes_ThenItShouldBeTheSame(self): gamestate = Gamestate.from_document(self.get_test_gamestate_document()) gamestate_copy = Gamestate.from_document(self.get_test_gamestate_document()) gamestate_copy.created_at = gamestate.created_at gamestate_copy.flip_all_units() gamestate_copy.flip_all_units() self.assert_equal_documents(gamestate.to_document(), gamestate_copy.to_document()) self.assertEqual(gamestate, gamestate_copy)
def test_ActionDocument_WhenSavingAndLoading_ThenItShouldBeTheSame(self): gamestate = Gamestate.from_document(self.get_test_gamestate_document()) actions = action_getter.get_actions(gamestate) for action in actions: action_document = action.to_document() same_action = Action.from_document(gamestate.all_units(), action_document) same_action.created_at = action.created_at same_action_document = same_action.to_document() self.assertEquals(action, same_action) self.assertEquals(action_document, same_action_document)
import profile import gamestate import json from gamestate import Gamestate from player import Player from game import Game from common import Intelligence from glob import glob games = [] for path in glob("./keep_replays/*.json"): document = json.loads(open(path).read()) gamestate = Gamestate.from_document(document["gamestate"]) gamestate.actions_remaining = 2 gamestate.set_available_actions() players = [ Player("Green", Intelligence.AI), Player("Red", Intelligence.AI) ] games.append(Game(players, gamestate)) def a(): for game in games: game.current_player().ai.select_action(game) profile.run('a()')
def test_GamestateDocument_WhenSavingAndLoading_ThenItShouldBeTheSame(self): document = self.get_test_gamestate_document() gamestate = Gamestate.from_document(document) same_document = gamestate.to_document() self.assert_equal_documents(document, same_document)