/* * Input: A Player and a Card * * * Output: True or False -> Does the player have enough resources to play given card already? */ public bool ValidateCard(PlayerState p, Card c) { //_logger.ValidatingCard(p, c); //_logger.CheckDictionary(p,hashtable); //c.toString(); //Check for duplicity for (int i = 0; i < p.getPlayedCards().Count; i++) { if (c.getCardName() == p.getPlayedCards()[i].getCardName()) { if (p.getName().Equals("P0")) { System.Console.WriteLine("!Can't play card with the same name!"); } return(false); } } //Check for precards if (preCardCheck(p, c)) { return(true); } // First check what the coin costs and total resource cost are if (c.getCoinCost() == 0 && c.getTotalResourceCost() == 0) { //_logger.print(p,"Card dosn't cost anything"); UpdateResources(p, c); return(true); } // If the coin cost is not equal to 0 then does the player have enoguh coins ? if (c.getCoinCost() != 0 && c.getTotalResourceCost() == 0) { //_logger.CheckingCoins(p, c); if (c.getCoinCost() <= p.getCoins()) { UpdateResources(p, c); p.updateCoins(-c.getCoinCost()); // _logger.CheckingPlayersCoins(p); return(true); } return(false); } if (c.getTotalResourceCost() != 0) { //_logger.print(p,"Now we are working on the players Resources"); return(CheckResourceCost(p, c.getCost())); } return(false); }
public void DisplayResourceCost(PlayerState p, Card c) { if (Log(p)) { int[] cardsResourceCost = c.getCost(); Console.Write("[{0}] [{1}] Card [{2}] Costs: ", _class.GetType().Name, c.getName(), c.getCost()); var resources = Enum.GetValues(typeof(Resource)); foreach (var resource in resources) { int index = (int)resource; Console.Write("[{0} : {1:N2}] ", resource, cardsResourceCost[index]); } Console.WriteLine(); } }
//Initial call to check for card validity public bool ValidateCard (PlayerState p, Card c) { //_logger.ValidatingCard(p, c); //_logger.CheckDictionary(p,hashtable); //Check for precards if (preCardCheck(p, c)) { return true; } // First check what the coin costs and total resource cost are if (c.getCoinCost() == 0 && c.getTotalResourceCost() == 0) { //_logger.print(p,"Card dosn't cost anything"); UpdateResources(p, c); return true; } // If the coin cost is not equal to 0 then does the player have enoguh coins ? if (c.getCoinCost() != 0 && c.getTotalResourceCost() == 0) { //_logger.CheckingCoins(p, c); if (c.getCoinCost() <= p.getCoins()) { UpdateResources(p, c); p.updateCoins(-c.getCoinCost()); // _logger.CheckingPlayersCoins(p); return true; } return false; } if (c.getTotalResourceCost() != 0) { //_logger.print(p,"Now we are working on the players Resources"); return CheckResourceCost(p,c.getCost()); } return false; }
/* * Input: A Player, a Card and a direction(0 = right, 1 = left) * * * Output: number of coins required to trade for resources for card with the player * at the given direction. negitive number if impossible */ public int validateTrade(PlayerState p, Card c, int direction) { int recCost = 2; int comCost = 2; //checkes to see if a player can play card with thier own resources if (ValidateCard(p, c)) { return(0); } PlayerState trader; if ((p.getBoard().getName().Equals("WB10") && (p.getBoard().getCurrentWonderLevel() >= 1))) { recCost = 1; } if (direction == 0) { trader = gameState.getRightPlayer(p); for (int i = 0; i < p.getPlayedCards().Count; i++) { if ((p.getPlayedCards()[i].getNumber() == 31) || (p.getPlayedCards()[i].getNumber() == 32)) { recCost = 1; break; } } } else { trader = gameState.getLeftPlayer(p); for (int i = 0; i < p.getPlayedCards().Count; i++) { if ((p.getPlayedCards()[i].getNumber() == 33) || (p.getPlayedCards()[i].getNumber() == 34)) { recCost = 1; break; } } } for (int i = 0; i < p.getPlayedCards().Count; i++) { if ((p.getPlayedCards()[i].getNumber() == 35) || (p.getPlayedCards()[i].getNumber() == 36)) { comCost = 1; } } if (!baseResources.ContainsKey(trader.getName())) { return(-1); } int cost = 0; List <int> traderResources = baseResources[trader.getName()]; int[] requiredResources = new int[c.getCost().Length]; for (int i = 0; i < c.getCost().Length; i++) { requiredResources[i] = c.getCost()[i]; requiredResources[i] -= baseResources[p.getName()][i];//p.getResources()[i]; if (requiredResources[i] < 0) { requiredResources[i] = 0; } if (traderResources[i] < requiredResources[i]) { return(-1); } if (i < 4) { cost += requiredResources[i] * recCost; } else { cost += requiredResources[i] * comCost; } //Console.WriteLine("cost " + cost + " cur rec " + requiredResources[i]); } return(cost); }
/* * Input: A Player, a Card and a direction(0 = right, 1 = left) * * * Output: number of coins required to trade for resources for card with the player * at the given direction. negitive number if impossible */ public int validateTrade(PlayerState p, Card c, int direction) { int recCost = 2; int comCost = 2; //checkes to see if a player can play card with thier own resources if (ValidateCard(p, c)) { return 0; } PlayerState trader; if ((p.getBoard().getName().Equals("WB10") && (p.getBoard().getCurrentWonderLevel() >= 1))) { recCost = 1; } if (direction == 0) { trader = gameState.getRightPlayer(p); for (int i = 0; i < p.getPlayedCards().Count; i++) { if ((p.getPlayedCards()[i].getNumber() == 31) || (p.getPlayedCards()[i].getNumber() == 32)) { recCost = 1; break; } } } else { trader = gameState.getLeftPlayer(p); for (int i = 0; i < p.getPlayedCards().Count; i++) { if ((p.getPlayedCards()[i].getNumber() == 33) || (p.getPlayedCards()[i].getNumber() == 34)) { recCost = 1; break; } } } for (int i = 0; i < p.getPlayedCards().Count; i++) { if ((p.getPlayedCards()[i].getNumber() == 35) || (p.getPlayedCards()[i].getNumber() == 36)) { comCost = 1; } } if (!baseResources.ContainsKey(trader.getName())) { return -1; } int cost = 0; List<int> traderResources = baseResources[trader.getName()]; int[] requiredResources = new int[c.getCost().Length]; for (int i = 0; i < c.getCost().Length; i++) { requiredResources[i] = c.getCost()[i]; requiredResources[i] -= baseResources[p.getName()][i];//p.getResources()[i]; if (requiredResources[i] < 0) { requiredResources[i] = 0; } if (traderResources[i] < requiredResources[i]) { return -1; } if (i < 4) { cost += requiredResources[i] * recCost; } else { cost += requiredResources[i] * comCost; } Console.WriteLine("cost " + cost + " cur rec " + requiredResources[i]); } return cost; }
public bool CheckResourceCost(PlayerState p, Card c) { int[] totalResources = { 0, 0, 0, 0, 0, 0, 0 }; int[] cost = c.getCost(); int[] boardResources = p.getBoard().getResources(); List<int> playersResources = hashtable[p.getName()]; for (int i = 0; i < playersResources.Count(); i++) { totalResources[i] = (playersResources[i] + boardResources[i]); } var resources = Enum.GetValues(typeof(Resource)); foreach (var type in resources) { int resource = (int)type; if (cost[resource] > totalResources[resource]) return false; } return true; }
/* * Input: A Player and a Card * * * Output: True or False -> Does the player have enough resources to play given card already? */ public bool ValidateCard (PlayerState p, Card c) { //_logger.ValidatingCard(p, c); //_logger.CheckDictionary(p,hashtable); //c.toString(); //Check for duplicity for (int i = 0; i < p.getPlayedCards().Count; i++) { if (c.getCardName() == p.getPlayedCards()[i].getCardName()) { if (p.getName().Equals("P0")) { System.Console.WriteLine("!Can't play card with the same name!"); } return false; } } //Check for precards if (preCardCheck(p, c)) { return true; } // First check what the coin costs and total resource cost are if (c.getCoinCost() == 0 && c.getTotalResourceCost() == 0) { //_logger.print(p,"Card dosn't cost anything"); UpdateResources(p, c); return true; } // If the coin cost is not equal to 0 then does the player have enoguh coins ? if (c.getCoinCost() != 0 && c.getTotalResourceCost() == 0) { //_logger.CheckingCoins(p, c); if (c.getCoinCost() <= p.getCoins()) { UpdateResources(p, c); p.updateCoins(-c.getCoinCost()); // _logger.CheckingPlayersCoins(p); return true; } return false; } if (c.getTotalResourceCost() != 0) { //_logger.print(p,"Now we are working on the players Resources"); return CheckResourceCost(p,c.getCost()); } return false; }