// Path: src/org/iaie/btree/BehavioralTree.java
// public class BehavioralTree extends Task{
//     
//        
//     /**
//      *
//      * @param name
//      */
//     public BehavioralTree(String name) {
//         super(name, null);
//     }
//     
//     @Override
//     public void addChild(Task task) {
//         if (this.children.isEmpty()) this.children.add(task);
//     }
//     
//     @Override
//     public Task getChild (int i) {
//         if (i == 0) return this.children.get(0);
//         else return null;
//     }
// 
//     @Override
//     public State run() {
//         try {
//             return this.children.get(0).run();
//         }
//         catch (Exception e) {
//             return State.ERROR;
//         }
//     }
// }
// 
// Path: src/org/iaie/btree/task/composite/Selector.java
// public class Selector<GameHandler> extends Composite {
// 
//     public Selector(String name) {
//         super(name, null);
//     }
//     
//     public Selector(String name, Task ... tasks) {
//         super(name, null);
//         this.addChildren(tasks);
//     }    
// 
//     @Override
//     public State run() {        
//         
//         for (int i = 0; i < this.children.size(); i++) {        
//             if (this.children.get(i).run() == State.SUCCESS) return State.SUCCESS;
//         }
//         
//         return State.FAILURE;
//     }
// }
// 
// Path: src/org/iaie/btree/task/composite/Sequence.java
// public class Sequence extends Composite {
//     
//     public Sequence(String name) {
//         super(name, null);
//     }
//     
//     public Sequence(String name, Task ... tasks) {
//         super(name, null);
//         this.addChildren(tasks);
//     }
// 
//     @Override
//     public State run() {
//         
//         for (int i = 0; i < this.children.size(); i++) {        
//             State result = this.children.get(i).run();
//             if (result == State.FAILURE) return State.FAILURE;
//             if (result == State.ERROR) return State.ERROR;
//         }
//         return State.SUCCESS;
//     }
// }
// 
// Path: src/org/iaie/btree/util/GameHandler.java
// public abstract class GameHandler {
//     protected Game connector; 
//     protected Player self;
//     
//     public GameHandler(Game bwapi, Player self) {
//         this.connector = bwapi;
//         this.self = self;
//     }
// }


import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.function.Predicate;
import org.iaie.btree.BehavioralTree;
import org.iaie.btree.task.composite.Selector;
import org.iaie.btree.task.composite.Sequence;
import org.iaie.btree.util.GameHandler;
import bwapi.BWEventListener;
import bwapi.Game;
import bwapi.Mirror;
import bwapi.Player;
import bwapi.Position;
import bwapi.Race;
import bwapi.Unit;
import bwapi.UnitType;
import bwapi.UpgradeType;
import bwta.BWTA;

		Sequence TrainMedic = new Sequence("Train medic");
		TrainMedic.addChild(new CheckResources("Check resources medic", gh, UnitType.Terran_Medic));
		TrainMedic.addChild(new ChooseBuilding("Check training medic", gh, UnitType.Terran_Medic));
		TrainMedic.addChild(new TrainUnit("Train medic", gh, UnitType.Terran_Medic, UnitType.Terran_Barracks));
		//Train firebats
		Sequence TrainFirebat = new Sequence("Train Firebat");
		TrainFirebat.addChild(new CheckResources("Check resources firebat", gh, UnitType.Terran_Firebat));
		TrainFirebat.addChild(new ChooseBuilding("Check training firebat", gh, UnitType.Terran_Firebat));
		TrainFirebat.addChild(new TrainUnit("Train Firebat", gh, UnitType.Terran_Firebat, UnitType.Terran_Barracks));
		//Train siege tanks
		Sequence TrainSiegeTank = new Sequence("Train Siege Tank");
		TrainSiegeTank.addChild(new CheckResources("Check resources siege tank", gh, UnitType.Terran_Siege_Tank_Tank_Mode));
		TrainSiegeTank.addChild(new ChooseBuilding("Check training siege tank", gh, UnitType.Terran_Siege_Tank_Tank_Mode));
		TrainSiegeTank.addChild(new TrainUnit("Train siege tank", gh, UnitType.Terran_Siege_Tank_Tank_Mode, UnitType.Terran_Factory));
		//Train vultures
		Sequence TrainVulture = new Sequence("Train Vulture");
		TrainVulture.addChild(new CheckResources("Check resources vulture", gh, UnitType.Terran_Vulture));
		TrainVulture.addChild(new ChooseBuilding("Check training vulture", gh, UnitType.Terran_Vulture));
		TrainVulture.addChild(new TrainUnit("Train vulture", gh, UnitType.Terran_Vulture, UnitType.Terran_Factory));
		//Train goliats
		Sequence TrainGoliat = new Sequence("Train Goliat");
		TrainGoliat.addChild(new CheckResources("Check resources goliat", gh, UnitType.Terran_Goliath));
		TrainGoliat.addChild(new ChooseBuilding("Check training goliat", gh, UnitType.Terran_Goliath));
		TrainGoliat.addChild(new TrainUnit("Train goliat", gh, UnitType.Terran_Goliath, UnitType.Terran_Factory));
		//Train science vessels
		Sequence TrainVessel = new Sequence("Train science vessel");
		TrainVessel.addChild(new CheckResources("Check resources science vessel", gh, UnitType.Terran_Science_Vessel));
		TrainVessel.addChild(new ChooseBuilding("Check training science vessels", gh, UnitType.Terran_Science_Vessel));
		TrainVessel.addChild(new TrainUnit("Train Science vessel", gh, UnitType.Terran_Science_Vessel, UnitType.Terran_Starport));


// Path: src/org/iaie/btree/BehavioralTree.java
// public class BehavioralTree extends Task{
//     
//        
//     /**
//      *
//      * @param name
//      */
//     public BehavioralTree(String name) {
//         super(name, null);
//     }
//     
//     @Override
//     public void addChild(Task task) {
//         if (this.children.isEmpty()) this.children.add(task);
//     }
//     
//     @Override
//     public Task getChild (int i) {
//         if (i == 0) return this.children.get(0);
//         else return null;
//     }
// 
//     @Override
//     public State run() {
//         try {
//             return this.children.get(0).run();
//         }
//         catch (Exception e) {
//             return State.ERROR;
//         }
//     }
// }
// 
// Path: src/org/iaie/btree/task/composite/Selector.java
// public class Selector<GameHandler> extends Composite {
// 
//     public Selector(String name) {
//         super(name, null);
//     }
//     
//     public Selector(String name, Task ... tasks) {
//         super(name, null);
//         this.addChildren(tasks);
//     }    
// 
//     @Override
//     public State run() {        
//         
//         for (int i = 0; i < this.children.size(); i++) {        
//             if (this.children.get(i).run() == State.SUCCESS) return State.SUCCESS;
//         }
//         
//         return State.FAILURE;
//     }
// }
// 
// Path: src/org/iaie/btree/task/composite/Sequence.java
// public class Sequence extends Composite {
//     
//     public Sequence(String name) {
//         super(name, null);
//     }
//     
//     public Sequence(String name, Task ... tasks) {
//         super(name, null);
//         this.addChildren(tasks);
//     }
// 
//     @Override
//     public State run() {
//         
//         for (int i = 0; i < this.children.size(); i++) {        
//             State result = this.children.get(i).run();
//             if (result == State.FAILURE) return State.FAILURE;
//             if (result == State.ERROR) return State.ERROR;
//         }
//         return State.SUCCESS;
//     }
// }
// 
// Path: src/org/iaie/btree/util/GameHandler.java
// public abstract class GameHandler {
//     protected Game connector; 
//     protected Player self;
//     
//     public GameHandler(Game bwapi, Player self) {
//         this.connector = bwapi;
//         this.self = self;
//     }
// }


// Path: src/bot/Goliat.java
import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.function.Predicate;
import org.iaie.btree.BehavioralTree;
import org.iaie.btree.task.composite.Selector;
import org.iaie.btree.task.composite.Sequence;
import org.iaie.btree.util.GameHandler;
import bwapi.BWEventListener;
import bwapi.Game;
import bwapi.Mirror;
import bwapi.Player;
import bwapi.Position;
import bwapi.Race;
import bwapi.Unit;
import bwapi.UnitType;
import bwapi.UpgradeType;
import bwta.BWTA;

		Sequence TrainMedic = new Sequence("Train medic");
		TrainMedic.addChild(new CheckResources("Check resources medic", gh, UnitType.Terran_Medic));
		TrainMedic.addChild(new ChooseBuilding("Check training medic", gh, UnitType.Terran_Medic));
		TrainMedic.addChild(new TrainUnit("Train medic", gh, UnitType.Terran_Medic, UnitType.Terran_Barracks));
		//Train firebats
		Sequence TrainFirebat = new Sequence("Train Firebat");
		TrainFirebat.addChild(new CheckResources("Check resources firebat", gh, UnitType.Terran_Firebat));
		TrainFirebat.addChild(new ChooseBuilding("Check training firebat", gh, UnitType.Terran_Firebat));
		TrainFirebat.addChild(new TrainUnit("Train Firebat", gh, UnitType.Terran_Firebat, UnitType.Terran_Barracks));
		//Train siege tanks
		Sequence TrainSiegeTank = new Sequence("Train Siege Tank");
		TrainSiegeTank.addChild(new CheckResources("Check resources siege tank", gh, UnitType.Terran_Siege_Tank_Tank_Mode));
		TrainSiegeTank.addChild(new ChooseBuilding("Check training siege tank", gh, UnitType.Terran_Siege_Tank_Tank_Mode));
		TrainSiegeTank.addChild(new TrainUnit("Train siege tank", gh, UnitType.Terran_Siege_Tank_Tank_Mode, UnitType.Terran_Factory));
		//Train vultures
		Sequence TrainVulture = new Sequence("Train Vulture");
		TrainVulture.addChild(new CheckResources("Check resources vulture", gh, UnitType.Terran_Vulture));
		TrainVulture.addChild(new ChooseBuilding("Check training vulture", gh, UnitType.Terran_Vulture));
		TrainVulture.addChild(new TrainUnit("Train vulture", gh, UnitType.Terran_Vulture, UnitType.Terran_Factory));
		//Train goliats
		Sequence TrainGoliat = new Sequence("Train Goliat");
		TrainGoliat.addChild(new CheckResources("Check resources goliat", gh, UnitType.Terran_Goliath));
		TrainGoliat.addChild(new ChooseBuilding("Check training goliat", gh, UnitType.Terran_Goliath));
		TrainGoliat.addChild(new TrainUnit("Train goliat", gh, UnitType.Terran_Goliath, UnitType.Terran_Factory));
		//Train science vessels
		Sequence TrainVessel = new Sequence("Train science vessel");
		TrainVessel.addChild(new CheckResources("Check resources science vessel", gh, UnitType.Terran_Science_Vessel));
		TrainVessel.addChild(new ChooseBuilding("Check training science vessels", gh, UnitType.Terran_Science_Vessel));
		TrainVessel.addChild(new TrainUnit("Train Science vessel", gh, UnitType.Terran_Science_Vessel, UnitType.Terran_Starport));


		Selector<Sequence> selectorTrain = new Selector<>("Selector train", TrainVessel, TrainGoliat, TrainSiegeTank, 
