public override int ChoseOption(Possibilities optionType) { int val = 0; switch ((int)optionType) { case (int)Possibilities.General: val = IntelligentGeneralChoice(); break; case (int)Possibilities.Neighbours: val = goalRoad.getdestinations()[1].getID(); break; case (int)Possibilities.Railroad: val = goalRoad.getdestinations()[0].getID(); break; case (int)Possibilities.stationCards: val = goalStation.getID(); break; case (int)Possibilities.stationCities: val = goalStation.getID(); return(val); case (int)Possibilities.leastImportantTraincard: foreach (KeyValuePair <TrainCard, int> card in traincards) { val = (int)card.Key.getColor(); } return(val); case (int)Possibilities.visibleTraincards: if (firstloop) { foreach (TrainCard card in ActionsMethods.visibleTraincards) { if (goalRoad != null) { if (goalRoad.getColor() != Color.Grijs && card.getColor() == goalRoad.getColor()) { val = (int)goalRoad.getColor(); return(val); } } else if (card.getColor() == Color.Locomotief) { return((int)Color.Locomotief); } } } else { foreach (TrainCard card in ActionsMethods.visibleTraincards) { val = (int)card.getColor(); return(val); } } firstloop = false; break; } return(val); }
public static bool Pickcards(Player player, Railroad road) { Dictionary <TrainCard, int> traincards = player.GetTraincards(); { int amountOfLocomotives = road.getAmountOfLocomotives(); int railLength = road.getRailLength() - amountOfLocomotives; Color kleur = road.getColor(); bool hasCard = false; int /*temp = 0,*/ maxamount = 0; Console.WriteLine("this track needs {0} locomotives", amountOfLocomotives); if (amountOfLocomotives > 0) { foreach (KeyValuePair <TrainCard, int> playercard in traincards) // met index werken? { if (playercard.Key.getColor() == Color.Locomotief) { hasCard = true; if (playercard.Value >= amountOfLocomotives) { Console.WriteLine("you have enough locomotives"); player.GetTraincards()[playercard.Key] -= amountOfLocomotives; TrainCard card = playercard.Key; for (int i = 0; i < amountOfLocomotives; i++) { usedCardsDeck.Add(card); } break; } else { Console.WriteLine("you don't have enough locomotives to make the track"); if (!(player is IntelligentPlayer)) { MessageBox.Show("you don't have enough locomotives to make the track"); } return(false); } } } if (!hasCard) { Console.WriteLine("you dont have any locomotives"); if (!(player is IntelligentPlayer)) { MessageBox.Show("you don't have enough locomotives to make the track"); } return(false); } } // de maximumwaarde wordt gezocht int amountLoco = 0; foreach (KeyValuePair <TrainCard, int> card in traincards) { if (card.Value > maxamount && card.Key.getColor() != Color.Locomotief) { maxamount = card.Value; } else if (card.Key.getColor() == Color.Locomotief) { amountLoco = card.Value; } } maxamount += amountLoco; if (railLength > 0) { if (railLength <= maxamount) { bool colorfound = false; if (kleur == Color.Grijs) { TrainCard traincard = null; Console.WriteLine("Please chose a color"); //bool firsttime = true; string a = null; Dictionary <TrainCard, int> possibleCard = goodCards(player, railLength); /*misschien beter een dictionary van object int maken*/ Dictionary <string, int> possiblities = new Dictionary <string, int>(); foreach (KeyValuePair <TrainCard, int> de in possibleCard) { a += "\t" + de.Key.ToString(); possiblities.Add(de.Key.ToString(), (int)de.Key.getColor()); } Console.WriteLine(a); if (!(player is IntelligentPlayer)) { int val = GetInput(possiblities, player); traincard = new TrainCard((Color)val); } else { traincard = new TrainCard((Color)possiblities.Values.ToList()[0]); // sorry, heb hiervoor geen intelligentie meer geïmplementeerd } foreach (KeyValuePair <TrainCard, int> card in traincards) { if (card.Key.getColor() == traincard.getColor()) { if (railLength > card.Value) { int temp = card.Value; railLength -= temp; TrainCard tCard = card.Key; for (int i = 0; i < temp; i++) { usedCardsDeck.Add(tCard); } traincards[card.Key] = 0; foreach (KeyValuePair <TrainCard, int> trCard in traincards) { if (trCard.Key.getColor() == Color.Locomotief) { traincards[trCard.Key] -= railLength; tCard = trCard.Key; for (int i = 0; i < railLength; i++) { usedCardsDeck.Add(tCard); } return(true); } } } else { traincards[card.Key] -= railLength; traincard = card.Key; for (int i = 0; i < railLength; i++) { usedCardsDeck.Add(traincard); } return(true); } } } } else { // indien de kleur van het spoort vasligt foreach (KeyValuePair <TrainCard, int> card in traincards) { if (card.Key.getColor() == kleur) { colorfound = true; // indien je voldoende kaarten hebt van die kleur (zonder locomotieven bij te leggen) if (card.Value >= railLength) { traincards[card.Key] -= railLength; player.addRailroad(road); TrainCard trCard = card.Key; for (int i = 0; i < railLength; i++) { usedCardsDeck.Add(trCard); } return(true); } else { foreach (KeyValuePair <TrainCard, int> pair in traincards) { if (pair.Key.getColor() == Color.Locomotief) { int val = traincards[card.Key]; traincards[card.Key] = 0; traincards[pair.Key] -= (railLength - val); TrainCard trCard = card.Key; for (int i = 0; i < railLength - val; i++) { usedCardsDeck.Add(trCard); } return(true); } } } } else if (amountLoco >= railLength) { foreach (KeyValuePair <TrainCard, int> pair in traincards) { if (pair.Key.getColor() == Color.Locomotief) { traincards[pair.Key] -= (railLength); TrainCard trCard = pair.Key; for (int i = 0; i < railLength; i++) { usedCardsDeck.Add(trCard); } return(true); } } } } return(false); if (!colorfound) { if (amountLoco >= railLength) { foreach (KeyValuePair <TrainCard, int> card in traincards) { traincards[card.Key] -= amountLoco; TrainCard trCard = card.Key; for (int i = 0; i < railLength; i++) { usedCardsDeck.Add(trCard); } return(true); } } Console.WriteLine("U heeft geen kaarten van dit type kleur"); if (!(player is IntelligentPlayer)) { MessageBox.Show("you dont have any cards of this type color"); } } } } else { Console.WriteLine("you dont have enough cards of the same type to build the track"); if (!(player is IntelligentPlayer)) { MessageBox.Show("you dont have enough cards of the same type to build the track"); } } } else { player.addRailroad(road); Console.WriteLine("The railroad {0} was successfully added", road.ToString()); ExtensionMethods.WaitForUser(); return(true); } //ExtensionMethods.WaitForUser(); returnLocomotives(traincards, amountOfLocomotives); return(false); } }