예제 #1
0
    def __init__(self,
                 subphase,
                 num_samples,
                 batch_size=32,
                 deterministic=False):
        """Dataset for random actions.

        Arguments:
            subphase      (str): Attack subphase to collect. TODO FIXME Cover more than just attacks
            num_samples   (int): Approximate number of samples to gather.
            deterministic(bool): Make each iteration produce the same results.
        """
        super(RandomActionDataset).__init__()
        self.subphase = subphase
        self.num_samples = num_samples
        self.batch_size = batch_size
        self.deterministic = deterministic

        # Variables for data generation
        self.randagent = RandomAgent()
        keys, ship_templates = parseShips('data/test_ships.csv')

        training_ships = [
            "All Defense Tokens", "All Defense Tokens",
            "Imperial II-class Star Destroyer", "MC80 Command Cruiser",
            "Assault Frigate Mark II A", "No Shield Ship", "One Shield Ship",
            "Mega Die Ship"
        ]
        self.defenders = []
        self.attackers = []
        for name in training_ships:
            self.attackers.append(
                Ship(name=name,
                     template=ship_templates[name],
                     upgrades=[],
                     player_number=1,
                     device='cpu'))
        for name in training_ships:
            self.defenders.append(
                Ship(name=name,
                     template=ship_templates[name],
                     upgrades=[],
                     player_number=2,
                     device='cpu'))
예제 #2
0
import random
import torch

import utility
from armada_encodings import (Encodings)
from game_constants import (ArmadaPhases, ArmadaTypes)
from learning_agent import (LearningAgent)
from learning_components import (collect_attack_batches, get_n_examples)
from model import (SeparatePhaseModel)
from random_action_dataset import (RandomActionDataset)
from random_agent import (RandomAgent)
from ship import (Ship)
from world_state import (AttackState, WorldState)

# Initialize ships from the test ship list
keys, ship_templates = utility.parseShips('data/test_ships.csv')

# Test the defense tokens by comparing the results of the test ships with and without those tokens


def update_lifetime_network(lifenet, batch, labels, optimizer, eval_only=False):
    """Do a forward and backward pass through the given lifetime network.

    Args:
        lifenet (torch.nn.Module): Trainable torch model
        batch (torch.tensor)     : Training batch
        labels (torch.tensor)    : Training labels
        optimizer (torch.nn.Optimizer) : Optimizer for lifenet parameters.
        eval_only (bool)         : Only evaluate, don't update parameters.
    Returns:
        batch error              : Average absolute error for this batch
import math
import PyGnuplot as gp

from game_constants import ArmadaDimensions
from utility import get_corners, parseShips, ruler_distance
from ship import Ship

keys, ship_templates = parseShips('data/test_ships.csv')
# Make two ships
alice = Ship(name="Alice",
             template=ship_templates["Attacker"],
             upgrades=[],
             player_number=1)
bob = Ship(name="Bob",
           template=ship_templates["Attacker"],
           upgrades=[],
           player_number=2)

# Put them somewhere
alice.set(name="location", value=[1.5, 1.5])
alice.set(name="heading", value=math.pi / 2.)
print(f"Alice location is {alice.get_range('location')}")
bob.set(name="location", value=[1.5, 0.8])
bob.set(name="heading", value=math.pi / 4.)
print(f"Bob location is {bob.get_range('location')}")

# Get the distance
distance, path = ruler_distance(alice, bob)

# Print out the ship edges and the shortest path
print(f"Distance is {distance}")
예제 #4
0
                    required=True,
                    help='Name of a ship or "all"')
parser.add_argument('--ship2',
                    type=str,
                    required=True,
                    help='Name of a ship or "all"')
parser.add_argument('--ranges',
                    type=str,
                    nargs='+',
                    required=True,
                    help='Ranges (short, medium, long)')
# TODO Allow specification of hull zones

args = parser.parse_args()

keys, ship_templates = utility.parseShips('data/armada-ship-stats.csv')
#print("keys are", keys)
#print("ships are ", ship_templates)

first_ship_names = []
if 'all' == args.ship1:
    first_ship_names = [name for name in ship_templates.keys()]
else:
    first_ship_names = [args.ship1]
    if args.ship1 not in ship_templates.keys():
        print("Unrecognized ship name {}".format(args.ship1))
        print("Recognized ship names are:\n")
        for name in ship_templates.keys():
            print("\t{}".format(name))
        exit(1)