50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
from diplomacy import Game
|
|
import random
|
|
|
|
def random_bot_move(game, power_name):
|
|
# Get all possible orders for the power
|
|
possible_orders = game.get_all_possible_orders()
|
|
|
|
# Check if we have units
|
|
if not game.get_units(power_name):
|
|
print(f"Debug: No units found for {power_name}")
|
|
return []
|
|
|
|
# possible_orders[power_name] is a dict: { 'A PAR': ['A PAR H', 'A PAR - BUR', ...], ... }
|
|
# Or in newer versions, check the structure.
|
|
# Based on previous output: {'A PAR': [...], 'F BRE': [...]}
|
|
|
|
# Wait, my previous test showed get_all_possible_orders() returns { 'LOC': [orders...] }
|
|
# So we need to find which locations belong to the power.
|
|
|
|
power_units = game.get_units(power_name) # ['A PAR', 'F BRE']
|
|
print(f"Debug: Units for {power_name}: {power_units}")
|
|
print(f"Debug: Possible orders keys sample: {list(possible_orders.keys())[:5]}")
|
|
|
|
orders_to_submit = []
|
|
|
|
for unit in power_units:
|
|
# unit string is "A PAR"
|
|
loc = unit.split(' ')[1]
|
|
print(f"Debug: Checking loc {loc}...")
|
|
|
|
if loc in possible_orders:
|
|
unit_orders = possible_orders[loc]
|
|
print(f"Debug: found {len(unit_orders)} orders for {loc}")
|
|
if unit_orders:
|
|
selected = random.choice(unit_orders)
|
|
orders_to_submit.append(selected)
|
|
else:
|
|
print(f"Debug: Loc {loc} NOT in possible_orders")
|
|
|
|
return orders_to_submit
|
|
|
|
if __name__ == "__main__":
|
|
game = Game()
|
|
power = "FRANCE"
|
|
print(f"Generating random orders for {power}...")
|
|
orders = random_bot_move(game, power)
|
|
print("Selected Orders:")
|
|
for o in orders:
|
|
print(f"- {o}")
|