def test_named_coast(self):
     data = {
         'orders': [],
         'pieces': [],
         'named_coasts': [{
             '_id': 1,
             'name': 'Spain South Coast',
             'territory_id': 1,
             'neighbour_ids': [2],
         }],
         'territories': [{
             '_id': 1,
             'type': 'coastal',
             'name': 'Spain',
             'nationality': None,
             'controlled_by': None,
             'supply_center': True,
             'neighbour_ids': [2, 3, 4, 5],
             'shared_coast_ids': [2, 3],
         }]
     }
     state = data_to_state(data)
     self.assertEqual(type(state.named_coasts[0].parent), CoastalTerritory)
     self.assertEqual(state.named_coasts[0].name, 'Spain South Coast')
     self.assertEqual(state.named_coasts[0].id, 1)
 def test_hold(self):
     data = {
         'orders': [{
             '_id': 1,
             'type': 'hold',
             'nation': 1,
             'source_id': 1,
             'piece_type': None,
         }],
         'pieces': [],
         'named_coasts': [],
         'territories': [
             {
                 '_id': 1,
                 'type': 'coastal',
                 'name': 'Spain',
                 'nationality': None,
                 'controlled_by': None,
                 'supply_center': True,
                 'neighbour_ids': [2, 3, 4, 5],
                 'shared_coast_ids': [2, 3],
             },
         ]
     }
     state = data_to_state(data)
     self.assertEqual(type(state.orders[0].source), CoastalTerritory)
     self.assertEqual(type(state.orders[0]), order.Hold)
     self.assertEqual(state.orders[0].nation, 1)
 def test_piece(self):
     data = {
         'orders': [],
         'pieces': [{
             '_id': 0,
             'type': 'army',
             'nation': 1,
             'territory_id': 1,
         }],
         'named_coasts': [],
         'territories': [{
             '_id': 1,
             'type': 'coastal',
             'name': 'Spain',
             'nationality': None,
             'controlled_by': None,
             'supply_center': True,
             'neighbour_ids': [2, 3, 4, 5],
             'shared_coast_ids': [2, 3],
         }]
     }
     state = data_to_state(data)
     self.assertEqual(type(state.pieces[0].territory), CoastalTerritory)
     self.assertEqual(state.pieces[0].__class__.__name__, 'Army')
     self.assertEqual(state.pieces[0].nation, 1)
Esempio n. 4
0
 def test_data_to_state_gets_contested_sea(self):
     data = {
         'territories': [{
             '_id': 1,
             'type': 'sea',
             'name': 'English Channel',
             'neighbour_ids': [],
             'shared_coast_ids': [],
             'contested': True,
         }],
         'named_coasts': [],
         'pieces': [],
         'orders': [],
     }
     state = data_to_state(data)
     self.assertEqual(state.territories[0].contested, True)
 def test_sea_territory(self):
     data = {
         'orders': [],
         'pieces': [],
         'named_coasts': [],
         'territories': [{
             '_id': 1,
             'type': 'sea',
             'name': 'Adriatic Sea',
             'neighbour_ids': [2, 3, 4, 5],
             'shared_coast_ids': None,
         }]
     }
     state = data_to_state(data)
     self.assertEqual(type(state.territories[0]), SeaTerritory)
     self.assertEqual(state.territories[0].name, 'Adriatic Sea')
     self.assertEqual(state.territories[0].id, 1)
Esempio n. 6
0
 def test_data_to_state_gets_contested_coastal(self):
     data = {
         'territories': [{
             '_id': 1,
             'type': 'coastal',
             'name': 'Paris',
             'nationality': 1,
             'neighbour_ids': [],
             'shared_coast_ids': [],
             'contested': True,
         }],
         'named_coasts': [],
         'pieces': [],
         'orders': [],
     }
     state = data_to_state(data)
     self.assertEqual(state.territories[0].contested, True)
 def test_convoy(self):
     data = {
         'orders': [{
             '_id': 1,
             'type': 'convoy',
             'nation': 1,
             'source_id': 1,
             'target_id': 2,
             'aux_id': 2,
             'piece_type': None,
         }],
         'pieces': [],
         'named_coasts': [],
         'territories': [{
             '_id': 1,
             'type': 'coastal',
             'name': 'Spain',
             'nationality': None,
             'controlled_by': None,
             'supply_center': True,
             'neighbour_ids': [2, 3, 4, 5],
             'shared_coast_ids': [2, 3],
         }, {
             '_id': 2,
             'type': 'coastal',
             'name': 'Portugal',
             'nationality': None,
             'controlled_by': None,
             'supply_center': True,
             'neighbour_ids': [1, 3, 4, 5],
             'shared_coast_ids': [1, 3],
         }]
     }
     state = data_to_state(data)
     self.assertEqual(type(state.orders[0].source), CoastalTerritory)
     self.assertEqual(type(state.orders[0].target), CoastalTerritory)
     self.assertEqual(type(state.orders[0].aux), CoastalTerritory)
     self.assertEqual(type(state.orders[0]), order.Convoy)
     self.assertEqual(state.orders[0].nation, 1)
 def test_inland_territory(self):
     data = {
         'orders': [],
         'pieces': [],
         'named_coasts': [],
         'territories': [{
             '_id': 1,
             'type': 'inland',
             'name': 'Paris',
             'nationality': 1,
             'controlled_by': 1,
             'supply_center': True,
             'neighbour_ids': [2, 3, 4, 5],
             'shared_coast_ids': None,
         }]
     }
     state = data_to_state(data)
     self.assertEqual(type(state.territories[0]), InlandTerritory)
     self.assertEqual(state.territories[0].name, 'Paris')
     self.assertEqual(state.territories[0].nationality, 1)
     self.assertEqual(state.territories[0].controlled_by, 1)
     self.assertEqual(state.territories[0].supply_center, True)
     self.assertEqual(state.territories[0].id, 1)
Esempio n. 9
0
def process_game_state(data):
    state = data_to_state(data)
    state.post_register_updates()
    process(state)
    return state_to_data(state)