//Strategy 2: Just the strongest possible hand public List <Card> play2(int aiId, TournamentCard storyCard, List <Player> players) { Player ai = players [aiId]; Dictionary <Card, int> cards = new Dictionary <Card, int>(); List <Card> keys = new List <Card>(); //filter weapon cards for (int i = 0; i < ai.hand.Count; i++) { if (ai.hand [i] is WeaponCard) { if (cards.ContainsKey(ai.hand [i])) { int amount = cards [ai.hand [i]] + 1; cards [ai.hand [i]] = amount; } else { cards.Add(ai.hand [i], 1); keys.Add(ai.hand [i]); } } else if (ai.hand [i] is AllyCard) { keys.Add(ai.hand[i]); } } return(keys); }
public void SetupStoryCardCheck() { if (drawnStoryCard != null) { Debug.Log("DRAWN STORY CARD: " + drawnStoryCard.name); UIUtil.EmptyPanel(questStagePanel); questStageBPTotal.text = ""; questStageNumber.text = ""; //setup quest , tournament or event if (drawnStoryCard.type == "Event Card") { currentEvent = (EventCard)drawnStoryCard; } else if (drawnStoryCard.type == "Tournament Card") { userInput.ActivateBooleanCheck("Do you want to participate?"); currentTournament = (TournamentCard)drawnStoryCard; } else if (drawnStoryCard.type == "Quest Card") { //store player that first drew the quest card QuestState.questDrawer = currentPlayerIndex; userInput.ActivateBooleanCheck("Do you want to sponsor this quest?"); currentQuest = (QuestCard)drawnStoryCard; } numIterations = 0; UIUtil.AddCardToPanel(UIUtil.CreateUIElement(drawnStoryCard, cardPrefab), questPanel); drawnStoryCard = null; } }
public void Test_TournamentCard() { TournamentCard tourneyCard = new TournamentCard("Tourney", 10, "Test.png"); Assert.AreEqual(tourneyCard.name, "Tourney"); Assert.AreEqual(tourneyCard.shields, 10); Assert.AreEqual(tourneyCard.asset, "Test.png"); }
public bool StoryCardDone() { if (isDoneStoryEvent) { //discard story card into story discard pile if (currentEvent != null) { List <Card> cards = new List <Card>(); cards.Add(currentEvent); GameUtil.DiscardCards(storyDeck, cards, storyDeckDiscardPileUIButton); // storyDeckDiscardPileUIButton.myCard = currentEvent; //storyDeckDiscardPileUIButton.ChangeTexture(); //storyDeck.discard.Add(currentEvent); } else if (currentQuest != null) { List <Card> cards = new List <Card>(); cards.Add(currentQuest); GameUtil.DiscardCards(storyDeck, cards, storyDeckDiscardPileUIButton); //storyDeckDiscardPileUIButton.myCard = currentQuest; //storyDeckDiscardPileUIButton.ChangeTexture(); //storyDeck.discard.Add(currentQuest); } else if (currentTournament != null) { List <Card> cards = new List <Card>(); cards.Add(currentTournament); GameUtil.DiscardCards(storyDeck, cards, storyDeckDiscardPileUIButton); //storyDeckDiscardPileUIButton.myCard = currentTournament; //storyDeckDiscardPileUIButton.ChangeTexture(); //storyDeck.discard.Add(currentTournament); } isDoneStoryEvent = false; currentEvent = null; currentQuest = null; currentTournament = null; //reset players participation GameUtil.ResetPlayers(players); UIUtil.EmptyPanel(questPanel); System.Array.Clear(queriedCards, 0, queriedCards.Length); //reset turn to draw new story card drawStoryCard = true; GameUtil.ToggleDeckAnimation(storyDeckUIButton, drawStoryCard); userInput.DeactivateUI(); // just in case UIUtil.UpdatePlayerTurn(this); // go to next turn return(true); } return(false); }
public List <Card> playTournament(TournamentCard storyCard, List <Player> players) { if (strategyNumber == 1) { return(participateTournamentBehaviour.play1(_playerId, storyCard, players)); } else { return(participateTournamentBehaviour.play2(_playerId, storyCard, players)); } }
public override bool ParticipateInTournament(TournamentCard tournamentCard) { foreach (Player player in tournamentCard.Match.Players) { if (promotableThroughTournament(player, tournamentCard)) { return(true); } } return(false); }
public void TournamentCard_CreatedWithGiven_WillHaveTheVariables() { var tournament = new TournamentCard("Tournament Card", "Tournament at Camelot", " ", 3); tournament.display(); Assert.AreEqual("Tournament Card", tournament.type); Assert.AreEqual("Tournament at Camelot", tournament.name); Assert.AreEqual(" ", tournament.texturePath); Assert.AreEqual(3, tournament.shields); Assert.IsNotNull(tournament.tournament); // Use the Assert class to test conditions. }
//Should The AI Participate in the Tournenment public bool DoIParticipateInTournament(List <Player> players, TournamentCard card) { bool participate = false; bool aggro = false; int rankCounter = 0; for (int i = 0; i < players.Count; i++) // { if (players[i].rank == 0) { if (players[i].shieldCounter > 3) { participate = true; aggro = true; break; } } if (players[i].rank == 1) { if (players[i].shieldCounter > 5) { participate = true; aggro = true; break; } } if (players[i].rank == 2) { if (players[i].shieldCounter > 10) { participate = true; aggro = true; break; } } } if (participate && aggro) { //currBehaviour = SponsorQuest(_hand); } if (participate && !aggro) { //currBehaviour = SponsorQuest(_hand); } else { //currBehaviour = Backout(); } return(participate); }
public bool joinTournament(TournamentCard storyCard, List <Player> players) { int value = storyCard.shields; bool couldWin = someoneCouldWin(value, players); if (strategyNumber == 1) { return(participateTournamentBehaviour.join1(couldWin)); } else { return(participateTournamentBehaviour.join2(couldWin)); } }
//Strategy 1 public List <Card> play1(int aiId, TournamentCard storyCard, List <Player> players) { Player ai = players [aiId]; int value = storyCard.shields; int[] requirements = new int[] { 5, 7, 10 }; bool strongest = false; for (int playerId = 0; playerId < players.Count; playerId++) { Player currPlayer = players [playerId]; if (currPlayer.shieldCounter + value >= requirements [currPlayer.rank] && playerId != aiId) { strongest = true; break; } } Dictionary <string, int> cards = new Dictionary <string, int>(); List <Card> keys = new List <Card>(); if (strongest) { //play strongest return(strongestCombination(ai.hand)); } else { //play only duplicates List <Card> playCards = new List <Card>(); for (int i = 0; i < keys.Count; i++) { if (cards [keys [i].name] > 1) { playCards.Add(keys [i]); } } return(playCards); } }
public override List <BattleCard> PlayCardsInTournament(TournamentCard tournamentCard, Player player) { bool strongestHand = false; foreach (Player participant in tournamentCard.Participants) { if ((promotableThroughTournament(participant, tournamentCard)) && (participant != player)) { strongestHand = true; } } Hand hand = player.Hand; List <BattleCard> playing = new List <BattleCard>(); if (strongestHand) { playing.AddRange(hand.GetDistinctCards <WeaponCard>().Cast <BattleCard>().ToList()); playing.AddRange(hand.GetDistinctCards <Amour>().Cast <BattleCard>().ToList()); playing.AddRange(hand.GetCards <AllyCard>().Cast <BattleCard>().ToList()); } else { HashSet <Type> foundWeaponTypes = new HashSet <Type>(); foreach (WeaponCard weapon in hand.GetCards <WeaponCard>()) { Type t = weapon.GetType(); if (foundWeaponTypes.Contains(t)) { playing.Add(weapon); } else { foundWeaponTypes.Add(t); } } } return(playing); }
public override List <BattleCard> PlayCardsInTournament(TournamentCard TournamentCard, Player player) { int currentBattlePoints = player.BattlePointsInPlay(); List <BattleCard> playableCards = player.Hand.BattleCards; playableCards.Sort((x, y) => - x.BattlePoints.CompareTo(y.BattlePoints)); List <BattleCard> cardsToPlay = new List <BattleCard>(); foreach (BattleCard card in playableCards) { if (currentBattlePoints >= tournamentTargetBattlePoints) { break; } if (hasDuplicate(cardsToPlay, card)) { continue; } cardsToPlay.Add(card); currentBattlePoints += card.BattlePoints; } player.Match.Log(player.Username + " plays " + Utils.Stringify.CommaList <BattleCard>(cardsToPlay)); return(cardsToPlay); }
public abstract bool ParticipateInTournament(TournamentCard tournamentCard);
// Set the current story card. public void setCard(Card c) { _tournamentCard = (TournamentCard)c; }
public void execute(List <Player> player, Card storyCard, Controller game) { //Ally cards on field do not matter !!!!!!! so only player rank and what he adds in if (TournamentState.state == "Participation" && TournamentState.tourneyRound == 1) { //do participation check code QueryingUtil.ParticipationCheck("Tournament", game); //done checking for participation if (game.numIterations >= game.numPlayers) { TournamentState.numberOfParticipants = GameUtil.CheckParticipation(game.players); if (GameUtil.CheckParticipation(game.players) > 1) { //there are more than 1 person participating TournamentState.state = "CardQuery"; //participants draw one card for (int i = 0; i < game.players.Count; i++) { if (game.players[i].participating) { game.players[i].hand.Add(GameUtil.DrawFromDeck(game.adventureDeck, 1)[0]); } } UIUtil.PopulatePlayerBoard(game); //just in case game.numIterations = 0; //for next part of tourney game.userInput.DeactivateUI(); game.userInput.ActivateCardUIPanel("What AMOUR , ALLY , OR WEAPON CARDS do you want to use?"); } else { //game is done resolve the tournament no one or 1 person participating //resolve tournament TournamentCard myCard = (TournamentCard)storyCard; for (int i = 0; i < game.players.Count; i++) { if (game.players[i].participating) { Debug.Log("number of shields" + myCard.shields); game.players[i].addShields(1 + myCard.shields); } } //reset values game.isDoneStoryEvent = true; TournamentState.state = "Participation"; TournamentState.numberOfParticipants = 0; TournamentState.tourneyRound = 1; TournamentState.undiscardedCards = null; TournamentState.cardsToBeDiscarded = new List <Card>(); } } } else if (TournamentState.state == "CardQuery") { //query players for cards QueryingUtil.CardQuerying("Tournament", game); //done querying if (game.numIterations >= game.numPlayers) { int maximumBP = 0; int totalPlayer = 0; List <int> playerTotals = new List <int>(); //concatonate results //ensuring deep copy List <List <Card> > temp = new List <List <Card> >(game.queriedCards); if (TournamentState.tourneyRound == 1) { TournamentState.undiscardedCards = new List <Card> [game.queriedCards.Length]; //copy everything System.Array.Copy(game.queriedCards, TournamentState.undiscardedCards, game.queriedCards.Length); } else { //concat results for (int i = 0; i < game.queriedCards.Length; i++) { if (game.queriedCards[i] != null) { for (int j = 0; j < game.queriedCards[i].Count; j++) { TournamentState.undiscardedCards[i].Add(game.queriedCards[i][j]); } } } } //debugging purposes for (int i = 0; i < TournamentState.undiscardedCards.Length; i++) { if (TournamentState.undiscardedCards[i] != null) { for (int j = 0; j < TournamentState.undiscardedCards[i].Count; j++) { Debug.Log(TournamentState.undiscardedCards[i][j].name); } } } for (int i = 0; i < TournamentState.undiscardedCards.Length; i++) { //not participating if (!(game.players[i].participating)) { playerTotals.Add(-100); continue; } else { if (TournamentState.undiscardedCards[i] != null) { //sum up card battle pts for (int j = 0; j < TournamentState.undiscardedCards[i].Count; j++) { if (TournamentState.undiscardedCards[i][j].type == "Weapon Card") { WeaponCard weapon = (WeaponCard)TournamentState.undiscardedCards[i][j]; totalPlayer += weapon.battlePoints; } else if (TournamentState.undiscardedCards[i][j].type == "Amour Card") { AmourCard amour = (AmourCard)TournamentState.undiscardedCards[i][j]; totalPlayer += amour.battlePoints; } } //add player's rank BP only totalPlayer += game.players[i].CalculateBP("", player); } else { //if he is participating and didn't add anything use his rank only totalPlayer = game.players[i].CalculateBP("", player); } } //add all totals to trace winner playerTotals.Add(totalPlayer); Debug.Log(i.ToString() + ": " + totalPlayer); //check for maximum if (maximumBP < totalPlayer) { maximumBP = totalPlayer; } totalPlayer = 0; } //discard weapon Cards for (int i = 0; i < TournamentState.undiscardedCards.Length; i++) { if (TournamentState.undiscardedCards[i] != null) { for (int j = 0; j < TournamentState.undiscardedCards[i].Count; j++) { if (TournamentState.undiscardedCards[i][j].type == "Weapon Card") { //discard weapon card TournamentState.cardsToBeDiscarded.Add(TournamentState.undiscardedCards[i][j]); TournamentState.undiscardedCards[i].RemoveAt(j); j--; } } } } //discard weapon cards if (TournamentState.cardsToBeDiscarded != null && TournamentState.cardsToBeDiscarded.Count > 0) { GameUtil.DiscardCards(game.adventureDeck, TournamentState.cardsToBeDiscarded, game.adventureDeckDiscardPileUIButton); } //discard all cards at the end of tourney if (TournamentState.tourneyRound == 2) { //discard everything //discard undiscarded cards for (int i = 0; i < TournamentState.undiscardedCards.Length; i++) { if (TournamentState.undiscardedCards[i] != null && TournamentState.undiscardedCards[i].Count > 0) { GameUtil.DiscardCards(game.adventureDeck, TournamentState.undiscardedCards[i], game.adventureDeckDiscardPileUIButton); } } } Debug.Log("Deciding winners"); List <int> winners = new List <int>(); for (int i = 0; i < playerTotals.Count; i++) { if (playerTotals[i] < maximumBP) { //ppl who got beat game.players[i].participating = false; } else { //winners winners.Add(i); } } //check for player discard game.playerStillOffending = GameUtil.PlayerOffending(game.players); if (game.playerStillOffending) { game.numIterations = 0; //find first offending player while (!game.players[game.currentPlayerIndex].handCheck() && game.numIterations < game.numPlayers) { //doesn't need to discard update turn game.numIterations++; UIUtil.UpdatePlayerTurn(game); } game.userInput.ActivateDiscardCheck("You need to Discard " + (game.players[game.currentPlayerIndex].hand.Count - 12).ToString() + " Cards"); } //undecided another round if (winners.Count >= 2 && TournamentState.tourneyRound == 1) { Debug.Log("Couldn't find winners"); TournamentState.tourneyRound = 2; game.numIterations = 0; game.userInput.ActivateCardUIPanel("What AMOUR , ALLY , OR WEAPON CARDS do you want to use?"); Debug.Log("There is a draw"); //requery cards System.Array.Clear(game.queriedCards, 0, game.queriedCards.Length); // game.queriedCards.Clear(); TournamentState.cardsToBeDiscarded.Clear(); } else { Debug.Log("found winners"); //we are done we have a winner or winners for (int i = 0; i < winners.Count; i++) { TournamentCard myCard = (TournamentCard)storyCard; Debug.Log("shields: " + myCard.shields); game.players[winners[i]].addShields(TournamentState.numberOfParticipants + myCard.shields); } //reset everything game.isDoneStoryEvent = true; TournamentState.state = "Participation"; TournamentState.numberOfParticipants = 0; TournamentState.tourneyRound = 1; System.Array.Clear(game.queriedCards, 0, game.queriedCards.Length); System.Array.Clear(TournamentState.undiscardedCards, 0, TournamentState.undiscardedCards.Length); TournamentState.cardsToBeDiscarded.Clear(); } } } }
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); }
public override bool ParticipateInTournament(TournamentCard tournamentCard) { tournamentCard.Match.Log(tournamentCard.Match.CurrentPlayer.Username + "joins the tournament"); return(true); }
public abstract List <BattleCard> PlayCardsInTournament(TournamentCard TournamentCard, Player player);
// for AI deciding to sponsor tournament protected bool promotableThroughTournament(Player player, TournamentCard tournamentCard) { return(player.Rank.ShieldsToVictory() <= tournamentCard.Shields); }
public override List <BattleCard> PlayCardsInTournament(TournamentCard TournamentCard, Player player) { throw new NotImplementedException(); }
public override bool ParticipateInTournament(TournamentCard tournamentCard) { throw new NotImplementedException(); }