Ejemplo n.º 1
0
def test_method():
    i = game_selection()
    if i != "base":
        test_two = ExBattlefield()
        test_two.run_game()
    else:
        forest_planet = Battlefield()
        forest_planet.run_game()
Ejemplo n.º 2
0
 def get_dummy_state_and_legal_actions_given_history(self, h):
     dummy_state = Battlefield()
     dummy_state.initialize_empty_grid()
     #Special case - root
     if h == -1:
         return dummy_state, dummy_state.valid_actions()
     else:
         for entry in h.history_list:
             dummy_state.apply_action(entry.action)
         return dummy_state, dummy_state.valid_actions()
Ejemplo n.º 3
0
def main():
    config = load_json(os.path.join('Configs', 'config.json'))
    random.seed(config['seed'])

    armies = []
    for data in config['armies']:
        armies.append(UNITS['Army']().create(data=data))

    if len(armies) >= MIN_ARMY_COUNT:
        Battlefield(armies).start_battle()
        dump_json(logger.report, os.path.join('Configs', 'report.json'))
Ejemplo n.º 4
0
def main():

    Conf.load('config.json')

    R.seed(Conf.seed)

    armies = list()

    for army_name in Conf.armies:
        armies.append(
            Army(army_name, get_squads(Conf.armies[army_name]),
                 Conf.armies[army_name]['strategy']))

    b = Battlefield(armies)

    b.start_battle()

    console_loger = Logger(replay)
    console_loger.write_all()

    with open('result.json', 'w') as output_file:
        loger = LoggerJSON(replay, output_file)
        loger.write_all()
Ejemplo n.º 5
0
def main():

    try:
        log_type = int(
            input(f"1 - Print the results to the console.\n"
                  f"2 - Print the results to the file.\n"))

        if log_type == 1:
            battle = Battlefield(log_type)

        elif log_type == 2:
            logfile = input("File for print: ")
            battle = Battlefield(log_type, logfile)

        else:
            raise ValueError("Incorrect input")

        battle.start()

    except ValueError:
        print("Incorrect input")
Ejemplo n.º 6
0
def main():
    battlefield = Battlefield()
    instructions = battlefield.load_file_instructions()
    battlefield.execute_instructions(instructions)
    battlefield.save_output()
Ejemplo n.º 7
0
import robot
from weapon import Weapon
from robot import Robot
from dinosaur import Dinosaur
from fleet import Fleet
from herd import Herd
from battlefield import Battlefield

if __name__ == '__main__':

    battlefield = Battlefield()
    battlefield.run_game()
Ejemplo n.º 8
0
from robots import Robot
from dinosaurs import Dinosaur
from fleet import Fleet
from herd import Herd
from battlefield import Battlefield
from weapons import Weapons
import ctypes
import random

if __name__ == '__main__':

    #Battlefield
    battlefield = Battlefield()

    #Weapons
    weapons = Weapons()

    # Robots
    robot_wally = Robot("Wall-E")
    robot_wally.power_level = 100
    robot_wally.attack_power = 60
    # weapons.choose_weapon(robot_wally)

    robot_megaman = Robot("Megaman")
    robot_megaman.power_level = 110
    robot_megaman.attack_power = 100
    # weapons.choose_weapon(robot_megaman)

    robot_marvin = Robot("Marvin")
    robot_marvin.power_level = 120
    robot_marvin.attack_power = 70
Ejemplo n.º 9
0
from battlefield import Battlefield
from robot import Robot
from fleet import Fleet
from dinosaur import Dinosaur

if __name__ == '__main__':
    user_choice = input('\nWelcome to the Robots vs Dinosaurs! '
                        '\n\nDo you want to auto-generate a game, '
                        'or do you want to play as Team Robot?'
                        ' (enter "auto" or "robot") ')

    while user_choice == 'auto' or user_choice == 'robot' or user_choice != 'no':
        if user_choice == 'auto':
            Battlefield().run_game()
            user_choice = input('Play again? Enter "auto", "robot", or "no" ')
        elif user_choice == 'robot':
            Battlefield().run_game_team_robots()
            user_choice = input('Play again? Enter "auto", "robot", or "no" ')
        elif user_choice != 'no':
            user_choice = input('Oops! Enter a valid input.')

    if user_choice == 'no':
        print('Thanks for playing!')
Ejemplo n.º 10
0
def battle_action():
    # NOTE: THIS REALLY SHOULD BE DONE USING A DATABASE OR AN ARRAY/LIST
    #       RATHER THAN SEPARATE INSTANCES OF  ROBOTS AND DINOSAURS.
    #       AN ARRAY/LIST WOULD BE MUCH MORE EFFICIENT
    # Assemble the robots
    print('\n================================')
    robot1 = Robot('Able', 50, 50, 'Phaser').robot_attr_list()
    robot2 = Robot('Baker', 50, 50, 'Phaser').robot_attr_list()
    robot3 = Robot('Sarge', 125, 100, '').robot_attr_list()

    robot_fleet = Fleet('Armageddon')
    robot_fleet.assign_member(robot3.name, robot3.attack_power, robot3.health)
    robot_fleet.assign_member(robot1.name, robot1.attack_power, robot1.health)
    robot_fleet.assign_member(robot2.name, robot2.attack_power, robot2.health)
    robot_fleet.fleet_status()

    # Assemble the dinosaurs
    print('\n================================')
    dinosaur1 = Dinosaur('Triceratops', 75, 30, 'Bash').dino_attr_list()
    dinosaur2 = Dinosaur('Velociraptor', 50, 100, 'Tail whip').dino_attr_list()
    dinosaur3 = Dinosaur('T-Rex', 100, 70, '').dino_attr_list()

    dinosaur_herd = Herd('R-r-raw-R!')
    dinosaur_herd.add_member(dinosaur3.dino_type, dinosaur3.attack_power, dinosaur3.health)
    dinosaur_herd.add_member(dinosaur1.dino_type, dinosaur1.attack_power, dinosaur1.health)
    dinosaur_herd.add_member(dinosaur2.dino_type, dinosaur2.attack_power, dinosaur2.health)
    dinosaur_herd.herd_status()

    # Create the battle field
    water_loo = Battlefield('Water Loo')
    water_loo.side1_name = robot_fleet.name
    water_loo.side2_name = dinosaur_herd.name
    water_loo.side1_points = robot_fleet.defense_points
    water_loo.side2_points = dinosaur_herd.defense_points

    # Now fight
    battle_ended = False
    counter = 0
    engagements = len(robot_fleet.members)
    water_loo.battle_status()
    print('\n\n ***** Battle commencing *****')
    detail_print = input('Do you wish to see the details? (y/n): ')
    while not battle_ended:
        side1_damage = 0
        side2_damage = 0
        damage1 = 0
        # battle strikes happen here...
        # Individual engagements (eg. 1 vs 1, 2 vs 2, 3 vs 3)
        if (robot1.health > 0 and robot1.power_level > 0) and (dinosaur1.health > 0 and dinosaur1.energy > 0):
            robot_attack_damage = make_an_attack(robot1.attack_power)
            dino_attack_damage = make_an_attack(dinosaur1.attack_power)
            dinosaur1.update_health(robot_attack_damage).update_energy(10)
            robot1.update_health(dino_attack_damage).update_power_level(10)
            if detail_print == 'y':
                print(f'Robot {robot1.name} hits {dinosaur1.dino_type} for {robot_attack_damage} damage '
                      f'and it has {dinosaur1.health} health '
                      f'and {dinosaur1.energy} energy left.')
                print(f'The {dinosaur1.dino_type} hits {robot1.name} for {dino_attack_damage} damage '
                      f'and it has {robot1.health} health '
                      f'and {robot1.power_level} power left.\n')
            side1_damage += dino_attack_damage
            side2_damage += robot_attack_damage
        else:
            # One member has been defeated, the other may or may not be left standing.
            engagements -= 1

        if (robot2.health > 0 and robot2.power_level > 0) and (dinosaur2.health > 0 and dinosaur2.energy > 0):
            robot_attack_damage = make_an_attack(robot2.attack_power)
            dino_attack_damage = make_an_attack(dinosaur2.attack_power)
            dinosaur2.update_health(robot_attack_damage).update_energy(10)
            robot2.update_health(dino_attack_damage).update_power_level(10)
            if detail_print == 'y':
                print(f'Robot {robot2.name} hits {dinosaur2.dino_type} for {robot_attack_damage} damage '
                      f'and it has {dinosaur2.health} health '
                      f'and {dinosaur2.energy} energy left.')
                print(f'The {dinosaur2.dino_type} hits {robot2.name} for {dino_attack_damage} damage '
                      f'and it has {robot2.health} health '
                      f'and {robot2.power_level} power left.\n')
            side1_damage += dino_attack_damage
            side2_damage += robot_attack_damage
        else:
            # One member has been defeated, the other may or may not be left standing.
            engagements -= 1

        if (robot3.health > 0 and robot3.power_level > 0) and (dinosaur3.health > 0 and dinosaur3.energy > 0):
            robot_attack_damage = make_an_attack(robot3.attack_power)
            dino_attack_damage = make_an_attack(dinosaur3.attack_power)
            dinosaur3.update_health(robot_attack_damage).update_energy(10)
            robot3.update_health(dino_attack_damage).update_power_level(10)
            if detail_print == 'y':
                print(f'Robot {robot3.name} hit the {dinosaur3.dino_type} for {robot_attack_damage} damage '
                      f'and it has {dinosaur3.health} health '
                      f'and {dinosaur3.energy} energy left.')
                print(f'The {dinosaur3.dino_type} hit robot {robot3.name} for {dino_attack_damage} damage '
                      f'and it has {robot3.health} health '
                      f'and {robot3.power_level} power left.\n')
            side1_damage += dino_attack_damage
            side2_damage += robot_attack_damage
        else:
            # One member has been defeated, the other may or may not be left standing.
            engagements -= 1

        water_loo.update_battle_status(side1_damage, side2_damage)
        if detail_print == 'y':
            water_loo.battle_status()
        counter += 1
        # Check to see if either side has been wiped out or at a tactical advantage
        battle_ended = water_loo.battle_results(counter, engagements, detail_print)
        # Tactical advantage equals all engagements are complete (0).
        if engagements == 0:
            battle_ended = True
        elif counter > 15:
            # The soldiers are too wimpy and their hearts are in not in the fight!
            print('Battle has stalemated. Troops are going home.')
            battle_ended = True
Ejemplo n.º 11
0
from robot import Robot
from herd import Herd
from dinosaur import Dinosaur
from weapon import Weapon
from fleet import Fleet
from battlefield import Battlefield

if __name__ == '__main__':
    battlefield = Battlefield()
    battlefield.display_welcome()
    user_start = input("\nStart game? (yes/no) >")
    if user_start.lower() == 'yes':
        battlefield.run_game()

    else:
        print("Exiting 3..2..1..")
Ejemplo n.º 12
0
from battlefield import Battlefield

if __name__ == '__main__':
    Battlefield()
Ejemplo n.º 13
0
 def __init__(self):
     self.start_state = Battlefield()
Ejemplo n.º 14
0
from battlefield import Battlefield

if __name__ == '__main__':

    first_battle = Battlefield()

    first_battle.run_game()
Ejemplo n.º 15
0
from battlefield import Battlefield

if __name__ == '__main__':
    battle = Battlefield()

Ejemplo n.º 16
0
 def __init__(self):
     game = Battlefield()
     game.display_welcome()
Ejemplo n.º 17
0
from battlefield import Battlefield

if __name__ == '__main__':
    test_battlefield = Battlefield()
    test_battlefield.run_game()
Ejemplo n.º 18
0
from battlefield import Battlefield

mountains = Battlefield()

mountains.run_game()

Ejemplo n.º 19
0
def sample_random_particles(n_particles):
    particles = []
    for _ in range(n_particles):
        battlefield = Battlefield()
        particles.append(battlefield)
    return particles
Ejemplo n.º 20
0
from battlefield import Battlefield

if __name__ == '__main__':
    battle_1 = Battlefield()
    battle_1.run_game()