private Card SetStrategy(PlayerState p, List <Card> hand) { Card bestCard = null; int currentAge = ResourceManager.GetInstance().getGameState().getAge(); if (p.getPlayedCards().Count() == 0) { bestCard = BuildWonder(p, hand); } if (bestCard == null) { if (noOfPlayers == 3 || noOfPlayers == 7) { if (p.getBoard().getCurrentWonderLevel() != currentAge) { bestCard = BuildWonder(p, hand); } } } if (bestCard == null) { bestCard = SetMilitaryStrategy(p, hand); } if (bestCard == null) { bestCard = SetScienceStrategy(p, hand); } if (bestCard == null) { bestCard = SetCommerceStrategy(p, hand); } if (bestCard == null) { bestCard = SetCivilianStrategy(p, hand); } if (bestCard == null) { strategy = new RandomStrategy(); bestCard = strategy.getNextCard(p, hand); } return(bestCard); }
private Card SetMilitaryStrategy(PlayerState p, List <Card> hand) { int currentAge = ResourceManager.GetInstance().getGameState().getAge(); PlayerState left = ResourceManager.GetInstance().getGameState().getLeftPlayer(p); PlayerState right = ResourceManager.GetInstance().getGameState().getRightPlayer(p); if ((left.getMilitaryPower() >= p.getMilitaryPower() - currentAge) || (right.getMilitaryPower() >= p.getMilitaryPower() - currentAge)) { strategy = new MilitaryStrategy(); Card c = strategy.getNextCard(p, hand); return(c); } return(null); }
public Card discardCard(PlayerState p, List <Card> hand) { bool jackEmUp = false; int currentAge = ResourceManager.GetInstance().getGameState().getAge(); List <PlayerState> players = ResourceManager.GetInstance().getGameState().getPlayers(); for (int i = 0; i < players.Count(); i++) { if ((players[i].getBoard().getName() == "WB3") || (players[i].getBoard().getName() == "WB7") || (players[i].getBoard().getName() == "WB8") || (players[i].getBoard().getName() == "WB13") || (players[i].getBoard().getName() == "WB14")) { jackEmUp = true; } } if (jackEmUp && currentAge == 1) { for (int i = 0; i < hand.Count(); i++) { if (hand[i].getName() == "R6" || hand[i].getName() == "R10") { return(hand[i]); } } } if (jackEmUp && currentAge == 2) { for (int i = 0; i < hand.Count(); i++) { if (hand[i].getName() == "R55") { return(hand[i]); } } } Random _r = new Random(); var r = new Random(); int index = r.Next(0, hand.Count()); return(hand[index]); }
//Mouse Click for "Play Card" button public void playerMoveButton_Click(object sender, EventArgs e) { if (player.getPlayedACard() == false) { int numCards = player.getHand().Count; for (int i = 0; i < player.getHand().Count; i++) { Card c = player.getHand()[i]; Image img = (Image)playBoard.Children[(56 + i)]; if (img.ActualHeight > 150)//this is the selected card { if (img.Source != new BitmapImage(new Uri(@"pack://*****:*****@"pack://application:,,,/Images/EmptyCard.png", UriKind.RelativeOrAbsolute)); PlayerGameBoard play = new PlayerGameBoard(parent, player, game); } else { ResourceManager manager = ResourceManager.GetInstance(game); manager.resetResources(player); ResourceBuying window = new ResourceBuying(ResourceManager.GetInstance().GetCombinedResources(player), c, this, game); window.Show(); } } } } } }
//attempts to build a wonder public Card buildWonder(PlayerState p, List <Card> hand) { if (ResourceManager.GetInstance().ValidateWonder(p)) { for (int i = 0; i < hand.Count; i++) { if (hand[i].getType() == strategy) { p.setWonderCards(hand[i]); p.getBoard().incrementWonderLevel(p); return(hand[i]); } } return(hand[0]); } return(null); }
public StartGame(List <Player> pending) { numPlayers = pending.Count; cardlistCreator lstC = new cardlistCreator(); allCards = lstC.getCardList(); cards = filterCards(allCards); boards = new CreateBoards().getBoards(); makePlayers(pending); game = new GameState(cards, players, boards); ResourceManager.GetInstance(game);// }
public ResourceBuying(Resources res, Card c, PlayerGameBoard p, GameState g) { resources = res; //Console.WriteLine(resources.ToString()); card = c; board = p; game = g; manager = ResourceManager.GetInstance(); you = manager.getGameState().getPlayerNum(resources.getPlayerName()[1]); InitializeComponent(); createButtons(); createValueFields(); }
private void buttonPlay_Click(object sender, RoutedEventArgs e) { if (rm.ValidateCard(player, cardToPlay)) { player.addPlayedCards(cardToPlay); this.Close(); PlayerGameBoard play = new PlayerGameBoard(parent, player, rm.getGameState()); } else { this.Close(); ResourceManager manager = ResourceManager.GetInstance(rm.getGameState()); manager.resetResources(player); ResourceBuying window = new ResourceBuying(ResourceManager.GetInstance().GetCombinedResources(player), cardToPlay, view, rm.getGameState()); window.Show(); } }
private Card BuildWonder(PlayerState p, List <Card> hand) { if (p.getBoard().notMaxYet()) { for (int i = 0; i < hand.Count(); i++) { if (hand[i].getType() == 1 || hand[i].getType() == 2) { if (ResourceManager.GetInstance().ValidateWonder(p)) { strategy = new CommerceStrategy(); p.setWonderCards(hand[i]); p.getBoard().incrementWonderLevel(p); return(hand[i]); } } } } return(null); }
private bool TradeCard(PlayerState p, Card c) { int trade = ResourceManager.GetInstance().validateTrade(p, c, 0); if ((trade > 0) && (p.getCoins() >= trade)) { p.updateCoins(-trade); ResourceManager.GetInstance().getGameState().getRightPlayer(p).updateCoins(trade); p.addPlayedCards(c); return(true); } trade = ResourceManager.GetInstance().validateTrade(p, c, 1); if ((trade > 0) && (p.getCoins() >= trade)) { p.updateCoins(-trade); ResourceManager.GetInstance().getGameState().getLeftPlayer(p).updateCoins(trade); p.addPlayedCards(c); return(true); } return(false); }
//please the primary card for the type baes AIs public Card playPrimary(PlayerState p, List <Card> hand) { int trade; for (int i = 0; i < hand.Count; i++) { if (hand[i].getType() == strategy) { if (ResourceManager.GetInstance().ValidateCard(p, hand[i])) { //System.Console.WriteLine("ScienceStrategy():: getNextCard({0})", hand[i]); p.addPlayedCards(hand[i]); return(hand[i]); } trade = ResourceManager.GetInstance().validateTrade(p, hand[i], 0); if ((trade > 0) && (p.getCoins() >= trade)) { //.WriteLine(p.getName() + " trading for " + trade); p.updateCoins(-trade); ResourceManager.GetInstance().getGameState().getRightPlayer(p).updateCoins(trade); p.addPlayedCards(hand[i]); return(hand[i]); } trade = ResourceManager.GetInstance().validateTrade(p, hand[i], 1); if ((trade > 0) && (p.getCoins() >= trade)) { //Console.WriteLine(p.getName() + " trading for " + trade); p.updateCoins(-trade); ResourceManager.GetInstance().getGameState().getLeftPlayer(p).updateCoins(trade); p.addPlayedCards(hand[i]); return(hand[i]); } } } return(null); }
//plays a resource or commodity public Card playSecondary(PlayerState p, List <Card> hand) { for (int i = 0; i < hand.Count; i++) { if ((hand[i].getType() == 1) && (ResourceManager.GetInstance().ValidateCard(p, hand[i]))) { //System.Console.WriteLine("ScienceStrategy():: getNextCard({0})", hand[i]); p.addPlayedCards(hand[i]); return(hand[i]); } } for (int i = 0; i < hand.Count; i++) { if ((hand[i].getType() == 2) && (ResourceManager.GetInstance().ValidateCard(p, hand[i]))) { //System.Console.WriteLine("ScienceStrategy():: getNextCard({0})", hand[i]); p.addPlayedCards(hand[i]); return(hand[i]); } } return(null); }
private Card SetCommerceStrategy(PlayerState p, List <Card> hand) { for (int i = 0; i < hand.Count(); i++) { if (hand[i].getName() == "C0123" || hand[i].getName() == "C0124") { if (ResourceManager.GetInstance().ValidateCard(p, hand[i])) { strategy = new CommerceStrategy(); p.addPlayedCards(hand[i]); return(hand[i]); } } if (noOfPlayers == 3) { if (hand[i].getName() == "C031" || hand[i].getName() == "CO33" || hand[i].getName() == "CO71" || hand[i].getName() == "CO74" || hand[i].getName() == "CO77" || hand[i].getName() == "CO121" || hand[i].getName() == "CO125") { if (ResourceManager.GetInstance().ValidateCard(p, hand[i])) { strategy = new CommerceStrategy(); p.addPlayedCards(hand[i]); return(hand[i]); } } } if (noOfPlayers == 4) { if (hand[i].getName() == "C028" || hand[i].getName() == "CO79" || hand[i].getName() == "C0120") { if (ResourceManager.GetInstance().ValidateCard(p, hand[i])) { strategy = new CommerceStrategy(); p.addPlayedCards(hand[i]); return(hand[i]); } } } if (noOfPlayers == 5) { if (hand[i].getName() == "C029" || hand[i].getName() == "CO75" || hand[i].getName() == "C0126") { if (ResourceManager.GetInstance().ValidateCard(p, hand[i])) { strategy = new CommerceStrategy(); p.addPlayedCards(hand[i]); return(hand[i]); } } } if (noOfPlayers == 6) { if (hand[i].getName() == "C036" || hand[i].getName() == "CO72" || hand[i].getName() == "C076" || hand[i].getName() == "CO78" || hand[i].getName() == "C0122" || hand[i].getName() == "C0124") { if (ResourceManager.GetInstance().ValidateCard(p, hand[i])) { strategy = new CommerceStrategy(); p.addPlayedCards(hand[i]); return(hand[i]); } } } if (noOfPlayers == 7) { if (hand[i].getName() == "C030" || hand[i].getName() == "C032" || hand[i].getName() == "C034" || hand[i].getName() == "C032" || hand[i].getName() == "C073" || hand[i].getName() == "C080" || hand[i].getName() == "C0127") { if (ResourceManager.GetInstance().ValidateCard(p, hand[i])) { strategy = new CommerceStrategy(); p.addPlayedCards(hand[i]); return(hand[i]); } } } /*if (TradeCard(p, hand[i])) * return hand[i];*/ } return(null); }
public Card getNextCard(PlayerState p, List <Card> hand) { List <CivilianCard> civCards = new List <CivilianCard>(); for (int i = 0; i < hand.Count; i++) { if (hand[i].getType() == 3) { System.Console.WriteLine("CivilianStrategy():: getNextCard({0})", hand[i]); civCards.Add((CivilianCard)hand[i]); } } // && (ResourceManager.GetInstance().ValidateCard(p, hand[i])) int trade; while (civCards.Count != 0) { CivilianCard bestCard = civCards[0]; for (int i = 1; i < civCards.Count; i++) { if (bestCard.getVictoryPoints() < civCards[i].getVictoryPoints()) { bestCard = civCards[i]; } } if (ResourceManager.GetInstance().ValidateCard(p, bestCard)) { p.addPlayedCards(bestCard); return(bestCard); } trade = ResourceManager.GetInstance().validateTrade(p, bestCard, 0); if ((trade > 0) && (p.getCoins() >= trade)) { //.WriteLine(p.getName() + " trading for " + trade); p.updateCoins(-trade); ResourceManager.GetInstance().getGameState().getRightPlayer(p).updateCoins(trade); p.addPlayedCards(bestCard); return(bestCard); } trade = ResourceManager.GetInstance().validateTrade(p, bestCard, 1); if ((trade > 0) && (p.getCoins() >= trade)) { //Console.WriteLine(p.getName() + " trading for " + trade); p.updateCoins(-trade); p.addPlayedCards(bestCard); ResourceManager.GetInstance().getGameState().getLeftPlayer(p).updateCoins(trade); return(bestCard); } civCards.Remove(bestCard); } Card cur = ult.playSecondary(p, hand); if (cur != null) { return(cur); } cur = ult.buildWonder(p, hand); if (cur != null) { return(cur); } return(ult.playAnyCard(p, hand)); }
public Card getNextCard(PlayerState p, List <Card> hand) { PlayerState left = ResourceManager.GetInstance().getGameState().getLeftPlayer(p); PlayerState right = ResourceManager.GetInstance().getGameState().getRightPlayer(p); int age = ResourceManager.GetInstance().getGameState().getAge(); Card cur; //Checks to see if AI has enough MilitaryPower to win the //the battles at the end of the Age if ((left.getMilitaryPower() >= p.getMilitaryPower() - age) || (right.getMilitaryPower() >= p.getMilitaryPower() - age)) { cur = ult.playPrimary(p, hand); if (cur != null) { return(cur); } } //attempts to play wonder to increase military if ((p.getBoard().getName().Equals("WB7")) && (p.getBoard().getCurrentWonderLevel() < 2) && (ResourceManager.GetInstance().ValidateWonder(p))) { for (int i = 0; i < hand.Count; i++) { if (hand[i].getType() != 6) { p.setWonderCards(hand[i]); p.getBoard().incrementWonderLevel(p); return(hand[i]); } } } if ((p.getBoard().getName().Equals("WB8")) && (p.getBoard().getCurrentWonderLevel() < 2) && (ResourceManager.GetInstance().ValidateWonder(p))) { for (int i = 0; i < hand.Count; i++) { if (hand[i].getType() != 6) { p.setWonderCards(hand[i]); p.getBoard().incrementWonderLevel(p); return(hand[i]); } } } cur = ult.playSecondary(p, hand); if (cur != null) { return(cur); } cur = ult.buildWonder(p, hand); if (cur != null) { return(cur); } return(ult.playAnyCard(p, hand)); }
private Card SetCivilianStrategy(PlayerState p, List <Card> hand) { for (int i = 0; i < hand.Count(); i++) { if (noOfPlayers == 3 || noOfPlayers == 7) { if (hand[i].getName() == "C22" || hand[i].getName() == "C23" || hand[i].getName() == "C63" || hand[i].getName() == "C64") { if (ResourceManager.GetInstance().ValidateCard(p, hand[i])) { strategy = new CivilianStrategy(); p.addPlayedCards(hand[i]); return(hand[i]); } } } if (noOfPlayers == 3 || noOfPlayers == 6) { if (hand[i].getName() == "C24" || hand[i].getName() == "C25" || hand[i].getName() == "C108" || hand[i].getName() == "C109") { if (ResourceManager.GetInstance().ValidateCard(p, hand[i])) { strategy = new CivilianStrategy(); p.addPlayedCards(hand[i]); return(hand[i]); } } } } int vc = 0, index = 0; for (int i = 0; i < hand.Count(); i++) { if (hand[i] is CivilianCard) { CivilianCard c = (CivilianCard)hand[i]; if (c.getVictoryPoints() > vc) { vc = c.getVictoryPoints(); index = i; } } } if (index != 0) { if (ResourceManager.GetInstance().ValidateCard(p, hand[index])) { strategy = new CivilianStrategy(); p.addPlayedCards(hand[index]); return(hand[index]); } } return(null); }
public Card getNextCard(PlayerState p, List <Card> hand) { Random random = new Random(); int randomNumber; Card c = null; if (ResourceManager.GetInstance().ValidateWonder(p)) { randomNumber = random.Next(0, 2); Console.WriteLine("attempting to play wonder " + randomNumber); if (randomNumber == 1) { Console.WriteLine("playing wonder " + randomNumber); randomNumber = random.Next(0, hand.Count - 1); c = hand[randomNumber]; p.setWonderCards(c); p.getBoard().incrementWonderLevel(p); } } List <int> availCards = new List <int>(); for (int i = 0; i < hand.Count; i++) { availCards.Add(i); } int trade; //selects a card to play for (int i = 0; i < hand.Count; i++) { randomNumber = random.Next(0, availCards.Count - 1); c = hand[availCards[randomNumber]]; if (ResourceManager.GetInstance().ValidateCard(p, c)) { p.addPlayedCards(c); return(c); //Console.WriteLine("===================== CHECKED CARD ==========================="); } trade = ResourceManager.GetInstance().validateTrade(p, c, 0); if ((trade > 0) && (p.getCoins() >= trade)) { //.WriteLine(p.getName() + " trading for " + trade); p.updateCoins(-trade); ResourceManager.GetInstance().getGameState().getRightPlayer(p).updateCoins(trade); p.addPlayedCards(c); return(c); } trade = ResourceManager.GetInstance().validateTrade(p, c, 1); if ((trade > 0) && (p.getCoins() >= trade)) { //Console.WriteLine(p.getName() + " trading for " + trade); p.updateCoins(-trade); p.addPlayedCards(c); ResourceManager.GetInstance().getGameState().getLeftPlayer(p).updateCoins(trade); return(c); } availCards.Remove(randomNumber); //Console.Write("RANDOM STRATEGY:: AGE :: "); //Console.WriteLine(ResourceManager.GetInstance().getGameState().getAge()); } return(null); }