void Awake()
 {
     _player = GetComponent<Player> ();
     _aiPlayer = GetComponent<AIPlayer> ();
     _aiMovement = GetComponent<AIMovement> ();
     _movement = GetComponent<PlatformerMovement> ();
 }
	/// <summary>
	/// Starts a new game.
	/// </summary>
	/// <remarks>
	/// Creates an AI player based upon the _aiSetting.
	/// </remarks>
	public static void StartGame()
	{
		if (_theGame != null)
			EndGame();

		//Create the game
		_theGame = new BattleShipsGame();

		//create the players
		switch (_aiSetting) {
			case AIOption.Medium:
				_ai = new AIMediumPlayer(_theGame);
				break;
			case AIOption.Hard:
				_ai = new AIHardPlayer(_theGame);
				break;
			default:
				_ai = new AIHardPlayer(_theGame);
				break;
		}

		_human = new Player(_theGame);

		//AddHandler _human.PlayerGrid.Changed, AddressOf GridChanged
		_ai.PlayerGrid.Changed += GridChanged;
		_theGame.AttackCompleted += AttackCompleted;

		AddNewState(GameState.Deploying);
	}
 void Awake()
 {
     moveTarget = new Vector2(transform.position.x,transform.position.y);
     _aiPlayer = GetComponent<AIPlayer> ();
     _platformMovement = gameObject.GetComponent<PlatformerMovement> ();
     _prePos = transform.position;
 }
Example #4
0
 public Game()
 {
     this.AI = new AIPlayer();
     this.Human = new HumanPlayer();
     EventManager.OnGameOver += this.GameOver;
     EventManager.OnGamePause += this.Pause;
     EventManager.OnGameResume += this.Resume;
 }
Example #5
0
    public void Start()
    {
        _score = 0;
        _aiPlayer = new AIPlayer();
        GameObject spawnerGameObj = GameObject.FindGameObjectWithTag("Spawner");
        Vector3[] aiSpawnLocs = new Vector3[AIDefenderSpawns.Length]; 
        for (int i = 0; i < AIDefenderSpawns.Length; ++i)
        {
            aiSpawnLocs[i] = AIDefenderSpawns[i].transform.position;
        }
        _aiPlayer.Init(LevelDifficulty, aiSpawnLocs, spawnerGameObj.GetComponent<AddObject>());

        if (_persistantInfo.ContainsKey(SCORE_KEY))
            _score = (Int32)_persistantInfo[SCORE_KEY];
    }
Example #6
0
    protected void Start()
    {
        player = gameObject.GetComponent<Player> ();
        aiPlayer = gameObject.GetComponent<AIPlayer> ();

        foreach(AIPlayer a in gameObject.GetComponents<AIPlayer> ()) {
            if (a.isActiveAndEnabled) {
                aiPlayer = a;
                break;
            }
        }

        if (player != null)
            team = player.team;
    }
Example #7
0
	public void CreatePlayers() {
		boardInput = GetComponent<ChessInput> ();

		HumanPlayer whiteHuman = null;
		HumanPlayer blackHuman = null;	
		AIPlayer whiteAI = null;
		AIPlayer blackAI = null;

		if (blackPlayerType == PlayerType.Human) {
			ChessUI.instance.SetBoardOrientation(false);
			blackHuman = new HumanPlayer ();
			boardInput.AddPlayer (blackHuman);
		} else {
			blackAI = new AIPlayer ();
		}

		if (whitePlayerType == PlayerType.Human) {
			ChessUI.instance.SetBoardOrientation(true);
			whiteHuman = new HumanPlayer ();
			boardInput.AddPlayer (whiteHuman);
			FindObjectOfType<NotationInput>().SetPlayer(whiteHuman);
		} else {
			whiteAI = new AIPlayer ();
		}

		whitePlayer = (Player)whiteHuman ?? (Player)whiteAI;
		blackPlayer = (Player)blackHuman ?? (Player)blackAI;

		whitePlayer.OnMove += OnMove;
		blackPlayer.OnMove += OnMove;

		whitePlayer.Init (true);
		blackPlayer.Init (false);

		whiteToPlay = Board.IsWhiteToPlay ();
		RequestMove ();
	}
Example #8
0
 public ExecuteFire(DecidedMessage _msg, AIPlayer _player)
     : base(_msg, _player)
 {
 }
Example #9
0
 public virtual void onReachDestination(AIPlayer obj)
 {
 }
Example #10
0
 public ExecuteDragThink(DecidedMessage _msg, AIPlayer _player)
     : base(_msg, _player)
 {
     m_ThinkTime = 0.5f;
 }
        private void btnStart_Click(object sender, RoutedEventArgs e)
        {
            int interval = 0;

            if (this.cbTimerEnabled.IsChecked.HasValue && this.cbTimerEnabled.IsChecked.Value)
            {
                if (!int.TryParse(this.tbTimerInterval.Text, out interval))
                {
                    MessageBox.Show("De ingevulde timer interval is ongeldig");
                    return;
                }
                if (interval <= 2)
                {
                    MessageBox.Show("De interval van de timer moet minimaal 3 seconden zijn");
                    return;
                }
                //game.InitializeTimer(interval);
            }

            var settings = new Settings(interval);
            var game     = new Game(settings);

            string p1Name = this.tbP1Name.Text;
            string p2Name = this.tbP2Name.Text;

            if (p1Name.Length < 2)
            {
                MessageBox.Show("speler 1: kies een naam van minstens 2 tekens");
                return;
            }
            if (p2Name.Length < 2)
            {
                MessageBox.Show("speler 2: kies een naam van minstens 2 tekens");
                return;
            }
            IPlayer     p1, p2;
            PlayerColor p1Color, p2Color;

            if (new Random().Next(0, 2) == 0)
            {
                p1Color = PlayerColor.Light;
                p2Color = PlayerColor.Dark;
            }
            else
            {
                p1Color = PlayerColor.Dark;
                p2Color = PlayerColor.Light;
            }

            if (this.rbP1IsAi.IsChecked.HasValue && this.rbP1IsAi.IsChecked.Value)
            {
                var p1AiType = (AIType)this.cbP1AIType.SelectedValue;
                p1 = new AIPlayer(PlayerNumber.One, p1Name, p1Color, p1AiType);
            }
            else
            {
                p1 = new Player(PlayerNumber.One, p1Name, p1Color);
            }

            if (this.rbP2IsAi.IsChecked.HasValue && this.rbP2IsAi.IsChecked.Value)
            {
                var p2AiType = (AIType)this.cbP2AIType.SelectedValue;
                p2 = new AIPlayer(PlayerNumber.Two, p2Name, p2Color, p2AiType);
            }
            else
            {
                p2 = new Player(PlayerNumber.Two, p2Name, p2Color);
            }

            game.Player1 = p1;
            game.Player2 = p2;

            Start?.Invoke(this, new GameEventArgs(game));
        }
Example #12
0
	public List<List<Card>> AISponsorCards(int turnId){
		AIPlayer currAi = (AIPlayer)_players[turnId];
		List<List<Card>> questStages = currAi.sponsorQuest ((QuestCard)_storyCard, _players);
		return questStages;
	}
Example #13
0
    public static int TREE_INDEX = 0; //改名

    void Start()
    {
        m_Character = GetComponent <AIPlayer>();
    }
Example #14
0
 public ExecuteAimThink(DecidedMessage _msg, AIPlayer _player) : base(_msg, _player)
 {
     m_ThinkTime = 1;
 }
Example #15
0
        //move left/right towards the destination node.
        //if hard deceleration would result in overshooting the destination, decelerate.
        //This is to stop the AI from going too fast and driving off the edge of a platform
        private void stepWalking(float dt)
        {
            if (destinationNode == null)
            {
                return;
            }
            Physics.Vector2D displacement = mainGraph.topLevelNode.GetNodePosition(destinationNode) - AIPlayer.playerBody.Position;

            //Get the direction of the displacement (-1 = dest is to the left)
            float sign = displacement.X / Math.Abs(displacement.X);

            //Get the displacement if the AI were to hard brake
            float naturalDisplacement      = Physics.SuvatEquations.SFromUVA(AIPlayer.playerBody.LinearVelocity.X, 0.0f, AIPlayer.GetHorizontalAcceleration()) * -1;
            float currentDirectionOfMotion = 1;

            //force natural displacement to be positive
            if (AIPlayer.playerBody.LinearVelocity.X != 0)
            {
                currentDirectionOfMotion = AIPlayer.playerBody.LinearVelocity.X / Math.Abs(AIPlayer.playerBody.LinearVelocity.X);
            }
            naturalDisplacement *= currentDirectionOfMotion;

            //If the displacement with deceleration results in overshooting, slow down
            if (displacement.X * sign < naturalDisplacement * sign)
            {
                //decelerate
                if (sign > 0)
                {
                    actionPlan.Add(new act_dur((int)ACTIONS.MOVE_LEFT, 0.0f));
                }
                else
                {
                    actionPlan.Add(new act_dur((int)ACTIONS.MOVE_RIGHT, 0.0f));
                }
            }
            else
            {
                //if travelling the wrong way, or travelling below walkingSpeed, accelerate towards the destination
                if (currentDirectionOfMotion != sign || Math.Abs(AIPlayer.playerBody.LinearVelocity.X) < walkingSpeed)
                {
                    if (sign < 0)
                    {
                        actionPlan.Add(new act_dur((int)ACTIONS.MOVE_LEFT, 0.0f));
                    }
                    else
                    {
                        actionPlan.Add(new act_dur((int)ACTIONS.MOVE_RIGHT, 0.0f));
                    }
                }
                else
                {
                    actionPlan.Add(new act_dur((int)ACTIONS.DO_NOTHING, 0.0f));
                }
            }
        }
Example #16
0
    // Update is called once per frame
    void Update()
    {
        switch (SimulationPhase)
        {
        case SimulationPhase.MatchesReady:
            //Debug.Log("Starting matchround " + Population.Generation + "." + (MatchesPlayed + 1));
            SimulationUI.TitleText.text = "Match Round " + Population.Generation + "." + (MatchesPlayed + 1);
            foreach (Match m in Matches)
            {
                if (m.Visual)
                {
                    SimulationUI.gameObject.SetActive(false);
                    VisualMatch = m;
                    m.StartMatch(VisualPlayer, VisualMinion, VisualBoardHeight, MatchUI);
                }
                else
                {
                    m.StartMatch();
                }
            }
            SimulationPhase = SimulationPhase.MatchesRunning;
            break;

        case SimulationPhase.MatchesRunning:
            foreach (Match m in Matches)
            {
                m.Update();
            }
            if (Matches.TrueForAll(x => x.Phase == MatchPhase.GameEnded))
            {
                MatchesPlayed++;
                SimulationPhase = SimulationPhase.MatchesFinished;
                if (VisualMatch != null)
                {
                    VisualMatch = null;
                    SimulationUI.gameObject.SetActive(true);
                }
            }
            break;

        case SimulationPhase.MatchesFinished:

            // Update Stats
            UpdateStatistics();

            if (MatchesPlayed >= MatchesPerGeneration)
            {
                // Init Human vs AI game if gen is finished
                if (SimulationUI.PlayGame.isOn)
                {
                    SimulationUI.PlayGame.isOn = false;
                    Matches.Clear();

                    // Create match
                    Match   match       = new Match();
                    Player  player1     = new HumanPlayer(match);
                    Subject bestSubject = Population.Subjects.OrderByDescending(x => x.Wins).First();
                    Player  player2     = new AIPlayer(match, bestSubject);
                    match.InitGame(player1, player2, StartHealth, StartCardOptions, MinCardOptions, MaxCardOptions, MaxMinions, MaxMinionsPerType, FatigueDamageStartTurn, true, false);

                    // Start match
                    Matches.Add(match);
                    VisualMatch = match;
                    SimulationUI.gameObject.SetActive(false);
                    match.StartMatch(VisualPlayer, VisualMinion, VisualBoardHeight, MatchUI);
                    SimulationPhase = SimulationPhase.MatchesReady;
                }

                else
                {
                    SimulationPhase = SimulationPhase.GenerationFinished;
                }
            }
            else
            {
                GenerateMatches();
                SimulationPhase = SimulationPhase.MatchesReady;
            }
            break;

        case SimulationPhase.GenerationFinished:

            // Reset stats
            ResetStatistics();
            MatchesPlayed = 0;

            // Evolve and Update UI
            EvolutionInformation info = Population.EvolveGeneration();
            SimulationUI.EvoStats.UpdateStatistics(info);
            SimulationUI.SpeciesScoreboard.UpdateScoreboard(Population);

            // Generate first match round
            GenerateMatches();
            SimulationPhase = SimulationPhase.MatchesReady;
            break;
        }
    }
Example #17
0
 public override void onTargetExitLOS(AIPlayer obj)
 {
     setImageTrigger(0, false);
 }
Example #18
0
 void Awake()
 {
     Global.Instance.Init();
     player = PlayerData.Load("common/characters");
     enemyTypes = PlayerData.Load("common/enemy_types");
     ai = new AIPlayer(map);
 }
Example #19
0
 public override void onTargetEnterLOS(AIPlayer obj)
 {
     setImageTrigger(0, true);
 }
Example #20
0
 public virtual void onTargetExitLOS(AIPlayer obj)
 {
 }
Example #21
0
 public virtual void onTargetEnterLOS(AIPlayer obj)
 {
 }
Example #22
0
 public ExecuteThink(DecidedMessage _msg, AIPlayer _player, float _thinkTime)
     : base(_msg, _player)
 {
     m_ThinkTime = _thinkTime;
 }
Example #23
0
 // Methods to set the players
 public void SetHumanPlayer(HumanPlayer humanPlayer)
 {
     this.humanPlayer = humanPlayer;
     aIPlayer         = null;
     isActive         = true;
 }
Example #24
0
        /// <summary>
        /// Initializes the game
        /// </summary>
        /// <param name="server">Server object</param>
        /// <param name="writer">Writer object</param>
        /// <param name="game">Game object</param>
        public void StartMatch(NetManager server, NetDataWriter writer, Game game)
        {
            if (m_AddBots)
            {
                NetworkPlayer[] temp = new NetworkPlayer[m_MaxPlayers];
                for (int i = 0; i < m_MaxPlayers; i++)
                {
                    if (i < m_player.Length)
                    {
                        temp[i] = m_player[i];
                    }
                    else
                    {
                        temp[i] = new AIPlayer(i);
                    }
                }
                m_player = temp;
            }

            game.m_IsInProgress = true;
            writer.Put("START");
            writer.Put(m_player.Length);//Player amount

            //Starting postitions
            switch (m_player.Length)
            {
            case 1:
                m_player[0].m_Position = new Vector3(0, 0.5f, 0);
                break;

            case 2:
                m_player[0].m_Position = new Vector3(-4, 0.5f, 0);
                m_player[1].m_Position = new Vector3(4, 0.5f, 0);
                break;

            case 3:
                m_player[0].m_Position = new Vector3(-3.464f, 0.5f, -2f);
                m_player[1].m_Position = new Vector3(3.464f, 0.5f, -2f);
                m_player[2].m_Position = new Vector3(0, 0.5f, 4);
                break;

            default:
                writer.Reset();
                writer.Put("START");
                writer.Put(4);
                m_player[0].m_Position = new Vector3(-2.828f, 0.5f, -2.828f);
                m_player[1].m_Position = new Vector3(2.828f, 0.5f, -2.828f);
                m_player[2].m_Position = new Vector3(-2.828f, 0.5f, 2.828f);
                m_player[3].m_Position = new Vector3(2.828f, 0.5f, 2.828f);
                break;
            }
            server.SendToAll(writer, DeliveryMethod.ReliableOrdered);
            writer.Reset();

            //Set booleans false for continious play
            for (int i = 0; i < m_player.Length; i++)
            {
                m_player[i].m_Killed   = false;
                m_player[i].m_Velocity = new Vector3();
                if (m_player[i] is AIPlayer)
                {
                    m_player[i].m_Ready = true;
                }
                else
                {
                    m_player[i].m_Ready = false;
                }
            }
        }
Example #25
0
 public void SetAiPlayer(AIPlayer aiPlayer)
 {
     this.aIPlayer = aiPlayer;
     humanPlayer   = null;
     isActive      = true;
 }
Example #26
0
 public ExecuteThink(DecidedMessage _msg, AIPlayer _player, float _thinkTime) : base(_msg, _player)
 {
     m_ThinkTime = _thinkTime;
 }
    /// <summary>
    /// Generates a random team for the AI based on its specs
    /// </summary>
    /// <param name="ai"></param>
    void GenerateAI(AIPlayer ai)
    {
        int mapLevel = 0;

        if (_players.Length == 0)
        {
            mapLevel = 1;
        }
        else
        {
            foreach (var p in _players)
            {
                mapLevel += p.AverageLevel;
            }
            mapLevel = Mathf.Max(mapLevel / _players.Length, 1);
        }

        List <Squad> squads = new List <Squad>();

        System.Array   values = System.Enum.GetValues(typeof(TileStats.type));
        TileStats.type type;

        // Create the initial squad container
        GameObject squadContainer = new GameObject();

        squadContainer.name = "Squads";

        // Create x squads
        for (int i = 0; i < ai.SquadCount; i++)
        {
            GameObject squad = new GameObject();
            squads.Add(squad.AddComponent <Squad>());
            squad.transform.parent = squadContainer.transform;
            squad.name             = "Squad" + i;

            do
            {
                System.Random random = new System.Random();
                type = (TileStats.type)values.GetValue(Random.Range(0, values.Length));
            } while (type == TileStats.type.Obstacle);
            //type = TileStats.type.Grass;

            var chars = AvailableCharacters
                        .Where(ac => ac.Type == type)
                        .Select(ac => ac.Characters).First();

            // Add x units
            int selected = 0;
            for (int j = 0; j < ai.MaxUnitCountPerSquad; j++)
            {
                if (j == ai.MaxUnitCountPerSquad - 1 && Random.Range(0, 1f) < 0.5f)
                {
                    selected = 1;
                }
                var instance = (GameObject)Instantiate(chars[selected], Vector3.zero, Quaternion.identity);
                instance.transform.parent = squad.transform;
                instance.tag = "AI";

                instance.GetComponent <PokemonStats>().SetLevel(mapLevel + selected);
            }

            squads[i].PrepareSquad();
        }

        ai.SetSquads(squads);

        // Set ai as parent
        squadContainer.transform.parent = ai.transform;
    }
Example #28
0
 public ExecuteFire(DecidedMessage _msg, AIPlayer _player) : base(_msg, _player)
 {
 }
 // Use this for initialization
 void Awake()
 {
     _aiPlayer = GetComponent<AIPlayer> ();
 }
Example #30
0
	//AI Response to prompts
	public void AILogicResponse(int turnId,string type){
		//Current AI
		AIPlayer currAi = (AIPlayer)_players[turnId];
		/*
			AI Draws so he can either
				-Sponsor Quest
				-Join Tournament
				-Draw Event Card
		*/
		if(activeStoryCard == false){
			DrawCard();
			//need to sponsor
			if (_storyCard.GetType() == typeof(QuestCard)) {
				List<List<Card>> questStages = currAi.sponsorQuest ((QuestCard)_storyCard, _players);
				if (questStages == null) {
					Prompt.PromptManager.promptNo();
					Debug.Log("AI declined to sponsor quest");
				} else {
					Prompt.PromptManager.promptYes ();
					Debug.Log("AI sponsors quest");
				}
			}
			//Join Tournament
			else if (_storyCard.GetType() == typeof(TournamentCard)) {
				//Prompt.PromptManager.promptYes();

				bool answer = currAi.joinTournament((TournamentCard)_storyCard,_players);
				if(answer){
					Debug.Log("AI has Joined Tournement");
					Prompt.PromptManager.promptYes();
				}
				else{
					Debug.Log("AI has denied Tournament entry");
					Prompt.PromptManager.promptNo();
				}

			}
			// A event card has been drawn.
			else if (_storyCard.GetType() == typeof(EventCard)) {
				EndTurn();
			}
		}
		/*
			AI Didn't Draw the Card
				-Join Quest
				-Join Tournament
		*/
		else if(activeStoryCard == true) {
			if (_storyCard.GetType() == typeof(QuestCard)) {
				//Prompt.PromptManager.promptYes();
				if(type == "sponsor") {
					List<List<Card>> questStages = currAi.sponsorQuest ((QuestCard)_storyCard, _players);
					if (questStages == null) {
						Prompt.PromptManager.promptNo();
						Debug.Log("AI declined to sponsor quest");
					} else {
						Prompt.PromptManager.promptYes ();
					}
				}
				if(type == "quest"){
					bool answer = currAi.joinQuest((QuestCard)_storyCard,_players);
					if(answer) {
						Debug.Log("AI Joined Quest");
						Prompt.PromptManager.promptYes();
					} else {
						Debug.Log("AI Denied to Join Quest");
						Prompt.PromptManager.promptNo();
					}
				}
			}
			else if (_storyCard.GetType() == typeof(TournamentCard)) {
				//Prompt.PromptManager.promptYes();
				bool answer = currAi.joinTournament((TournamentCard)_storyCard,_players);
				if(answer) {
					Debug.Log("AI Joined Tournement");
					Prompt.PromptManager.promptYes();
				} else {
					Debug.Log("AI Denied to join tournament");
					Prompt.PromptManager.promptNo();
				}
			}
		}
	}
 public void DeadAI(AIPlayer player)
 {
     // Hard coded for single AI
     UIManager.Instance.GameEndOptions.ShowVictory();
     StartCoroutine(Victory());
 }
Example #32
0
 public void PlayerTurnFinished(AIPlayer player)
 {
     playersTakingturns.Remove(player);
 }
Example #33
0
 public virtual void onMoveStuck(AIPlayer obj)
 {
 }
Example #34
0
 public AIDecider(AIPlayer _player)
 {
     player = _player;
 }
Example #35
0
 public ExecuteAimThink(DecidedMessage _msg, AIPlayer _player)
     : base(_msg, _player)
 {
     m_ThinkTime = 1;
 }
Example #36
0
    public void Test_AI()
    {
        AIPlayer      ai      = new AIPlayer(0, 1);
        List <Player> players = new List <Player> ();


        FoeCard    thieves    = new FoeCard("Thieves", "Thieves", 5, 5, false, "card_image/foe/foeCard4");
        FoeCard    thieves2   = new FoeCard("Thieves", "Thieves", 5, 5, false, "card_image/foe/foeCard4");
        FoeCard    boar       = new FoeCard("Boar", "Boar", 5, 15, false, "card_image/foe/foeCard3");
        WeaponCard excalibur  = new WeaponCard("Excalibur", 30, "card_image/weapons/weaponCard3");
        WeaponCard excalibur2 = new WeaponCard("Excalibur", 30, "card_image/weapons/weaponCard3");
        AllyCard   sirtristan = new AllyCard("Sir Tristan", 10, 0, 20, 0, null, "Queen Iseult", false, "card_image/special/specialCard4");
        WeaponCard lance      = new WeaponCard("Lance", 20, "card_image/weapons/weaponCard4");
        WeaponCard lance2     = new WeaponCard("Lance", 20, "card_image/weapons/weaponCard4");
        WeaponCard dagger     = new WeaponCard("Dagger", 5, "card_image/weapons/weaponCard2");


        players.Add(ai);
        players.Add(new Player(1));
        players.Add(new Player(2));

        //SPONSOR QUEST
        QuestCard quest = new QuestCard("Boar Hunt", 2, "Boar", "card_image/quest/questCard4");

        ai.addCard(thieves);
        Assert.IsNull(ai.sponsorQuest(quest, players));
        ai.addCard(thieves2);
        Assert.IsNull(ai.sponsorQuest(quest, players));
        ai.addCard(boar);
        List <List <Card> > stages = ai.sponsorQuest(quest, players);

        Assert.IsTrue(stages [0].Contains(thieves));
        Assert.IsTrue(stages [1].Contains(boar));
        ai.addCard(excalibur);
        ai.addCard(excalibur2);
        ai.addCard(lance);
        stages = ai.sponsorQuest(quest, players);
        Assert.IsTrue(stages [0].Contains(thieves));
        Assert.IsTrue(stages [0].Contains(excalibur2));
        Assert.AreEqual(stages [0].Count, 2);
        Assert.IsTrue(stages [1].Contains(boar));
        Assert.IsTrue(stages [1].Contains(excalibur));
        Assert.IsTrue(stages [1].Contains(lance));
        Assert.AreEqual(stages [1].Count, 3);
        players [1].AddShields(3);
        //2 shield to evolve
        Assert.IsNull(ai.sponsorQuest(quest, players));
        //reset player 1
        players [1] = new Player(1);

        //JOIN AND PLAY QUEST
        ai         = new AIPlayer(0, 1);
        players[0] = ai;
        Assert.IsFalse(ai.joinQuest(quest, players));
        ai.addCard(thieves);
        ai.addCard(boar);
        ai.addCard(lance);
        ai.addCard(lance2);
        ai.addCard(excalibur);
        Assert.IsFalse(ai.joinQuest(quest, players));
        ai.addCard(excalibur2);
        //2 foe cards from the quest sponsor
        Assert.IsTrue(ai.joinQuest(quest, players));
        ai          = new AIPlayer(0, 1);
        players [0] = ai;
        ai.addCard(thieves);
        ai.addCard(boar);
        ai.addCard(excalibur);
        ai.addCard(sirtristan);
        Assert.IsFalse(ai.joinQuest(quest, players));
        ai.addCard(lance);
        Assert.IsTrue(ai.joinQuest(quest, players));

        //will play lance and excalibur and sir tristan
        ai.addCard(dagger);
        List <Card> played = ai.playQuest(players, -1, true, false);

        Assert.IsTrue(played.Contains(sirtristan));
        Assert.IsTrue(played.Contains(excalibur));
        Assert.IsTrue(played.Contains(lance));
        Assert.IsTrue(played.Contains(dagger));
        Assert.AreEqual(played.Count, 4);

        ai          = new AIPlayer(0, 1);
        players [0] = ai;
        ai.addCard(excalibur);
        ai.addCard(sirtristan);
        ai.addCard(lance);
        ai.addCard(dagger);
        ai.addCard(excalibur2);
        ai.addCard(lance2);

        played = ai.playQuest(players, -1, false, false);
        Assert.IsTrue(played.Contains(dagger));
        Assert.IsTrue(played.Contains(lance));
        Assert.IsTrue(played.Contains(sirtristan));
        Assert.AreEqual(played.Count, 3);

        //TOURNAMENT
        TournamentCard tournament = new TournamentCard("Tournament at Camelot", 3, "card_image/tournament/TournamentCard");

        Assert.IsFalse(ai.joinTournament(tournament, players));
        players [1].AddShields(3);
        Assert.IsTrue(ai.joinTournament(tournament, players));
        //remove shields
        players [1] = new Player(1);

        played = ai.playTournament(tournament, players);
        Assert.IsTrue(played.Contains(lance));
        Assert.IsTrue(played.Contains(excalibur));
        Assert.AreEqual(played.Count, 2);

        players [1].AddShields(3);
        played = ai.playTournament(tournament, players);
        Assert.IsTrue(played.Contains(sirtristan));
        Assert.IsTrue(played.Contains(excalibur));
        Assert.IsTrue(played.Contains(lance));
        Assert.IsTrue(played.Contains(dagger));
        Assert.AreEqual(played.Count, 4);
    }
Example #37
0
        public GameState(Game1 game, GraphicsDevice graphicsDevice, ContentManager content)
            : base(game, graphicsDevice, content)
        {
            difficultyCase = 0;
            _spriteBatch   = new SpriteBatch(_graphicsDevice);
            //use this.Content to load your game content here
            var ballTexture             = _content.Load <Texture2D>("Ball");
            var playerTexture           = _content.Load <Texture2D>("Player1");
            var player2Texture          = _content.Load <Texture2D>("player2");
            var buttonTexture           = _content.Load <Texture2D>("home");
            var buttonFont              = _content.Load <SpriteFont>("ButtonFont");
            var DifficultybuttonTexture = _content.Load <Texture2D>("difficultyButton");
            var DifficultybuttonFont    = _content.Load <SpriteFont>("ButtonDifficultyFont");
            var pausebuttonTexture      = _content.Load <Texture2D>("Pause");

            score      = new Score(_content.Load <SpriteFont>("File"));
            screenFont = new ScreenText(_content.Load <SpriteFont>("ScreenFont"));

            var HomeButton = new Button(buttonTexture, buttonFont)
            {
                Position = new Vector2(Game1.screenWidth / 20, screenHeight - screenHeight / 10),
                Text     = "",
            };

            HomeButton.Click += HomeButton_Click;

            var PauseButton = new Button(pausebuttonTexture, buttonFont)
            {
                Position = new Vector2(screenWidth / 2, screenHeight - screenHeight / 20),
                Text     = "",
            };

            PauseButton.Click += PauseButton_Click;

            var DifficultyButton = new Button(DifficultybuttonTexture, DifficultybuttonFont)
            {
                Position = new Vector2(Game1.screenWidth / 8, screenHeight - screenHeight / 10),
                Text     = "Play Style",
            };

            DifficultyButton.Click += DifficultyButton_Click;

            var MultiplayerButton = new Button(DifficultybuttonTexture, DifficultybuttonFont)
            {
                Position = new Vector2((Game1.screenWidth / 4) * 3, screenHeight - screenHeight / 10),
                Text     = "Player 2",
            };

            MultiplayerButton.Click += MultiplayerButton_Click;

            _componentsPause = new List <Component>()
            {
                HomeButton,
                DifficultyButton,
                PauseButton,
                MultiplayerButton,
            };
            _components = new List <Component>()
            {
                PauseButton,
            };

            ball = new Ball(ballTexture)
            {
                position = new Vector2((screenWidth / 2) - (ballTexture.Width / 2), (screenHeight / 2) - (ballTexture.Height / 2)), //positions the ball in the centre of the screen
                score    = score,
            };

            AIplayer = new AIPlayer(player2Texture)
            {
                position = new Vector2(Game1.screenWidth - (Game1.screenWidth / 10), (screenHeight / 2) - (playerTexture.Height / 2)),
            };

            Player1 = new Player(playerTexture)
            {
                position = new Vector2(Game1.screenWidth / 15, (screenHeight / 2) - (playerTexture.Height / 2)),
            };

            //load in the sprites
            sprites = new List <Sprite>()
            {
                ball,
                Player1,
                AIplayer,
            };

            Pause       = false;
            Multiplayer = false;
        }
Example #38
0
 public AIExecutor(AIPlayer _player)
 {
     player = _player;
     behaviours = new Queue<ExecuteBehaviour>();
     deQueue = false;
 }
Example #39
0
 public AICollector(AIPlayer _player)
 {
     player = _player;
 }
Example #40
0
 public ExecuteBehaviour(DecidedMessage _msg, AIPlayer _player)
 {
     msg = _msg;
     player = _player;
 }
Example #41
0
 public AIExecutor(AIPlayer _player)
 {
     player     = _player;
     behaviours = new Queue <ExecuteBehaviour>();
     deQueue    = false;
 }
Example #42
0
 public AICollector(AIPlayer _player)
 {
     player = _player;
 }
Example #43
0
 public ExecuteBehaviour(DecidedMessage _msg, AIPlayer _player)
 {
     msg    = _msg;
     player = _player;
 }
Example #44
0
 public ExecuteThink(DecidedMessage _msg, AIPlayer _player)
     : base(_msg, _player)
 {
     m_ThinkTime = Random.Range(2, 3);
 }
Example #45
0
 // Use this for initialization
 void Start()
 {
     isWinner = 0;
     backToMain.SetActive (false);
     isXTurn = true;
     aiPlayer = GameObject.Find ("AIPlayer").GetComponent<AIPlayer> ();
 }
Example #46
0
 public AIDecider(AIPlayer _player)
 {
     player = _player;
 }
Example #47
0
 // Update is called once per frame
 void Update()
 {
     if (isGameOver)
     {
         return;
     }
     if (isSomethingSelected)
     {
         if (Input.GetMouseButtonDown(0))
         {
             var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
             if (Physics.Raycast(ray, out RaycastHit hit))
             {
                 if (hit.transform.gameObject.GetComponent <InteractableObject>())
                 {
                     var interactable = hit.transform.gameObject.GetComponent <InteractableObject>();
                     if (selectedPlayer is AICleaner && selectedPlayer)
                     {
                         var aiCleaner = selectedPlayer.GetComponent <AICleaner>();
                         if (!aiCleaner.isHoldingSomething)
                         {
                             aiCleaner.SetObjectToInteract(interactable);
                         }
                     }
                     selectedPlayer.MoveAgentToNewPos(interactable.transform.position);
                 }
                 else if (hit.transform.gameObject.GetComponent <GrabableObjects>())
                 {
                     var grabable = hit.transform.gameObject.GetComponent <GrabableObjects>();
                     if (selectedPlayer is AICleaner && selectedPlayer)
                     {
                         var aiCleaner = selectedPlayer.GetComponent <AICleaner>();
                         if (!aiCleaner.isHoldingSomething)
                         {
                             aiCleaner.SetObjectToGrab(grabable);
                         }
                     }
                     selectedPlayer.MoveAgentToNewPos(grabable.transform.position);
                 }
                 else if (hit.transform.gameObject.GetComponent <StorageObject>())
                 {
                     var storage = hit.transform.gameObject.GetComponent <StorageObject>();
                     if (selectedPlayer is AICleaner && selectedPlayer)
                     {
                         var aiCleaner = selectedPlayer.GetComponent <AICleaner>();
                         if (aiCleaner.isHoldingSomething)
                         {
                             aiCleaner.GoToTruck(storage);
                         }
                     }
                     selectedPlayer.MoveAgentToNewPos(storage.transform.position);
                 }
                 else
                 {
                     var hitPos = hit.point;
                     selectedPlayer.MoveAgentToNewPos(hitPos);
                 }
             }
         }
         else if (Input.GetMouseButtonDown(1))
         {
             selectedPlayer.DeselectPlayer();
             selectedPlayer = null;
         }
     }
 }
Example #48
0
        internal void Initialize(int numSystems, Texture2D SystemTexture, Texture2D RingTexture,
            Vector2 MapSize, Texture2D[] planetTextures, ref AIPlayer[] aiPlayers, ref Player player,
            Texture2D SectorTexture, SpriteFont Font, GraphicsDevice device, GraphicsDeviceManager graphics,
            SpriteBatch spriteBatch)
        {
            playerName = player.Name + " of " + player.faction.Name;
            font = Font;
            sectorTexture = SectorTexture;
            string playerSysID;
            NumSystems = numSystems;
            systex = SystemTexture;
            ringtex = RingTexture;
            AllSystems = new PlanetsSystem[NumSystems];
            Width = (int)MapSize.X;
            Height = (int)MapSize.Y;
            selectedSystem = 0;
            PlanetTextures = planetTextures;
            string username = Environment.UserName;
            var PLANET_NAME_FILES = System.IO.File.ReadAllLines(@"C:\\Users\\" + username + "\\Documents\\RES\\TextAssets\\planetNames.txt");
            var SYSTEM_NAME_FILES = System.IO.File.ReadAllLines(@"C:\\Users\\" + username + "\\Documents\\RES\\TextAssets\\systemNames.txt");
            planetNames = new List<string>(PLANET_NAME_FILES); //Lit of all available planet names, each one is removed when used
            systemNames = new List<string>(SYSTEM_NAME_FILES);
            AIPlayerNumbers = new List<int>(aiPlayers.Length); //list is limited to number of AI
            planetMapGenerator = new MapGenerator(device, spriteBatch);


            List<Player> tempPlayerList = new List<Player>();
            tempPlayerList.Add(player);
            foreach (Player p in aiPlayers)
            {
                tempPlayerList.Add(p);
            }
            int currentPlayer = 0;
            bool isPlayerSystem = true;

            PlayerNumber = StrategyGame.r.Next(0, NumSystems);

            #region AIPlayer list position setup

            for (int i = 0; i < aiPlayers.Length; i++) //Setting up the number in the list of systems where the AI Players will be 
            {
                int tempIDNumber = 0;
                do
                {
                    tempIDNumber = StrategyGame.r.Next(0, NumSystems);
                }
                while (tempIDNumber == PlayerNumber || AIPlayerNumbers.Contains(tempIDNumber));

                AIPlayerNumbers.Add(tempIDNumber);
            }

            #endregion

            SetupMapPositions(MapSize);

            //Action action = () =>
            //{
            #region Player Systems

            size = PlayerSystemSize;
            SystemPosition = RandCoordinates(size, true);
            NumPlanets = 5;
            rect = new Rectangle(SystemPosition, new Point(size, size));
            SystemColour = player.faction.colour;

            randomName = StrategyGame.r.Next(0, systemNames.Count);
            systemName = systemNames[randomName];
            systemNames.RemoveAt(randomName); //make sure the name can't be assigned twice

            AllSystems[PlayerNumber] = new PlanetsSystem(rect, systex, ringtex, NumPlanets, planetTextures,
                SystemColour, ref planetNames, systemName, SystemIndex, gridPosition, new EventHandler(UpdateResources), 
                PlayerNumber, planetMapGenerator, player);
            playerSysID = systemName;
            player.AddSystem(ref AllSystems[PlayerNumber]);

            for (int i = 0; i < AllSystems[PlayerNumber].Planets; i++)
            {
                if (AllSystems[PlayerNumber].PlanetsList[i].PlanetTier == 2)
                {
                    player.AddPlanet(ref AllSystems[PlayerNumber], i);
                    //add planet to player list
                }
            }
            #endregion


            for (int i = 0; i < NumSystems; i++)
            {

                #region AIPlayerSystems

                if (AIPlayerNumbers.Contains(i)) //coords are being all set the same and sizes are being set to 200 - fix
                {
                    size = PlayerSystemSize;
                    NumPlanets = 5;

                    randomName = StrategyGame.r.Next(0, systemNames.Count);
                    systemName = systemNames[randomName];
                    systemNames.RemoveAt(randomName);


                    randomName = StrategyGame.r.Next(0, planetNames.Count);
                    tempPlanetName = planetNames[randomName];
                    planetNames.RemoveAt(randomName);

                    SystemPosition = RandAICoordinates(size);
                    rect = new Rectangle(SystemPosition, new Point(size, size));
                    SystemColour = Color.Red;
                    isPlayerSystem = true;
                    currentPlayer++;              
                }

                #endregion

                else if (i >= 0 && i < NumSystems && i != PlayerNumber)
                {
                    size = StrategyGame.r.Next(MinSize, MaxSize);
                    NumPlanets = StrategyGame.r.Next(1, 5);
                    SystemColour = Color.White;

                    randomName = StrategyGame.r.Next(0, systemNames.Count);
                    systemName = systemNames[randomName];
                    systemNames.RemoveAt(randomName);

                    SystemPosition = RandCoordinates(size);

                    rect = new Rectangle(SystemPosition, new Point(size, size));


                    randomName = StrategyGame.r.Next(0, planetNames.Count);
                    tempPlanetName = planetNames[randomName];
                    planetNames.RemoveAt(randomName);
                    isPlayerSystem = false;

                }
                if (i != PlayerNumber) //players system has to be initialized first - don't want to override it 
                {
                    if (isPlayerSystem)
                    {
                        AllSystems[i] = new PlanetsSystem(rect, systex, ringtex, NumPlanets, 
                            planetTextures, SystemColour, ref planetNames, systemName, SystemIndex, 
                            gridPosition, new EventHandler(UpdateResources), i,
                            planetMapGenerator, tempPlayerList[currentPlayer]);

                        aiPlayers[currentPlayer - 1].AddSystem(ref AllSystems[i]);

                        for (int index = 0; index < AllSystems[i].Planets; index++)
                        {
                            if (AllSystems[i].PlanetsList[index].PlanetTier == 2)
                            {
                                aiPlayers[currentPlayer - 1].AddPlanet(ref AllSystems[i], index);
                                //add planet to player list
                            }
                        }
                    }
                    else
                    {
                        AllSystems[i] = new PlanetsSystem(rect, systex, ringtex, NumPlanets, planetTextures, 
                            SystemColour, ref planetNames, systemName, SystemIndex, gridPosition, 
                            new EventHandler(UpdateResources), i, planetMapGenerator);
                    }
                }
            }
            selectedSystem = PlayerNumber;
            AllSystems[selectedSystem].OnSelected();

            int systemCount = 0;
            foreach (PlanetsSystem system in AllSystems)
            {
                int sectorCount = 0;
                foreach (MapSector sector in SectorsList)
                {
                    int count = 0;
                    foreach (Point p in sector.ContainedCoords)
                    {
                        if (system.GridPosition == p)
                        {
                            sector.AddSystem(ref AllSystems[systemCount], count);
                            system.Sector = Int32.Parse(sector.Name);
                            AllSystems[systemCount].AllSystemsListIndex = systemCount;
                            if (system.ID == playerSysID)
                            {
                                CurrentSector = sectorCount;
                            }
                        }

                        count++;
                    }
                    sectorCount++;
                }
                systemCount++;
            }
            //};
            //Task t = new Task(action);
            //t.RunSynchronously();
            //t.Wait();

            PLANET_NAME_FILES = null;
            SYSTEM_NAME_FILES = null;
        }
Example #49
0
 public ExecuteDragThink(DecidedMessage _msg, AIPlayer _player)
     : base(_msg, _player)
 {
     m_ThinkTime = 0.5f;
 }
Example #50
0
 public ExecuteThink(DecidedMessage _msg, AIPlayer _player) : base(_msg, _player)
 {
     m_ThinkTime = Random.Range(2, 3);
 }
 private void Awake()
 {
     _instance = this;
 }