示例#1
0
def encode_garrison_options(G):
	code = adict()

	for player, tilenames in G.temp.sat_units.items():
		options = placeable_units(G, player, G.players[player].stats.great_power, tilenames)
		if len(options):
			code[player] = options

	return code
示例#2
0
def encode_setup_actions(G):

    code = adict()

    for faction, nationality, tilenames in seq_iterate(G.temp.setup,
                                                       [None, 'cadres', None],
                                                       end=True):
        # if player is not None and faction != player:
        # 	continue

        options = placeable_units(G, faction, nationality, tilenames)

        if len(options) == 0:
            continue

        if faction not in code:
            code[faction] = xset()

        code[faction].add((nationality, options))

    if len(code) == 0:
        raise PhaseComplete

    return code
示例#3
0
def encode_production_actions(G):

    code = adict()

    active_player = G.game.turn_order[G.temp.active_idx]
    faction = G.players[active_player]

    options = xset()

    # pass
    options.add(('pass', ))

    # cards
    options.add(('action_card', ))
    options.add(('investment_card', ))

    ex_territory = faction.territory.copy()

    # new cadres
    for nationality, tiles in faction.homeland.items():
        groups = placeable_units(G, active_player, nationality, tiles)
        if len(groups):
            options.add((nationality, groups))

        ex_territory -= tiles

    # new fortresses
    fort_opts = adict()
    for tilename in ex_territory:
        tile = G.tiles[tilename]
        if not contains_fortress(G, tile):
            nationality = faction.stats.great_power
            for nat, lands in faction.members.items():
                if tile.alligence in lands:
                    nationality = nat
                    break
            if G.units.reserves[nationality].Fortress > 0:
                if nationality not in fort_opts:
                    fort_opts[nationality] = xset()
                fort_opts[nationality].add(tilename)
    if len(fort_opts):
        for nationality, tiles in fort_opts.items():
            options.add((nationality, tiles, 'Fortress'))

    # improve units
    improvable = xset()

    for uid, unit in faction.units.items():

        # can't upgrade a cv of 4
        if unit.cv == 4:
            continue

        tile = G.tiles[unit.tile]

        # unit must be supplied and not engaged
        if 'disputed' in tile or 'unsupplied' in tile:
            continue

        # tile must be land or coast
        if tile.type in {'Sea', 'Ocean'}:
            continue

        improvable.add(unit._id)
    improvable -= G.temp.prod[active_player].upgraded_units
    if len(improvable):
        options.add((improvable, ))

    code[active_player] = options

    return code