/// <summary> /// /// </summary> /// <param name="digSite">Where to dig</param> /// <param name="weeks">How long to dig for</param> /// <param name="singleUseCards">Single-use cards to use</param> /// <param name="displayDigResult">Function that displays the dig result</param> public DigAction(IDigSite digSite, int weeks, List <ICard> singleUseCards, System.Action <List <IToken> > displayDigResult) { this.digSite = digSite; this.weeks = weeks; this.singleUseCards = singleUseCards; this.displayDigResult = displayDigResult; }
public Game(int playerCount) { this.Deck = new Deck(GameSettings.Cards, playerCount); AvailableCards = new CardDisplay(DrawCard, Deck.Discard); ActiveExhibitions = new ExhibitionDisplay(Deck.Discard); DigsiteInventory = new Dictionary <IDigSite, List <IToken> >(); BonusTokens = new Dictionary <IDigSite, IToken>(); foreach (IPlace place in GameSettings.Places) { if (place is IDigSite) { IDigSite digSite = (IDigSite)place; DigsiteInventory.Add(digSite, new List <IToken>()); bool bonusTokenAdded = false; foreach (IToken token in digSite.Tokens) { if (!bonusTokenAdded && token is IArtifactToken && ((IArtifactToken)token).Points == 1) { BonusTokens[digSite] = token; bonusTokenAdded = true; } else { DigsiteInventory[digSite].Add(token); } } } } Time.Configure(playerCount); }
/// <summary> /// Returns knowledge and token bonus from a list of single-use cards. /// </summary> /// <param name="digSite">dig site to dig at</param> /// <param name="singleUseCards">list of cards to use</param> /// <param name="knowledge">knowledge gained</param> /// <param name="tokenBonus">tokens gained</param> private void AddSingleUseCardsStats(IDigSite digSite, List <ICard> singleUseCards, ref int knowledge, ref int tokenBonus) { if (singleUseCards == null) { return; } foreach (ICard card in singleUseCards) { if (card is IRumorsCard && ((IRumorsCard)card).digSite == digSite) { knowledge += ((IRumorsCard)card).KnowledgeAmount; } if (card is IAssistantCard) { knowledge += 1; } if (card is IShovelCard) { tokenBonus += 1; } } return; }
private double ExpectedDigValue(IPlayer player, IDigSite digSite, int weeks) { // get token amount player.GetDigStats(digSite, null, out int knowledge, out int tokenBonus); int tokenAmount = GameSettings.DugTokenCount(knowledge, weeks) + tokenBonus; return(ExpectedValueOfToken(digSite) * tokenAmount); }
/// <summary> /// Use special permission card to renew one of his permissions /// </summary> /// <param name="digSite">digsite to renew permission at</param> /// <returns>false if player doesnt have any special permission card or if he already has permission for the digsite</returns> public bool UseSpecialPermission(IDigSite digSite) { if (SpecialPermissions > 0 && !Permissions[digSite]) { SpecialPermissions--; Permissions[digSite] = true; return(true); } return(false); }
/// <summary> /// Computes the expected number of tokens drawn /// </summary> /// <param name="digSite">where to dig</param> /// <returns>the expected value</returns> public double ExpectedNumberOfTokens(IDigSite digSite) { int bonusToken = 0; if (this.BonusTokens[digSite] != null) { bonusToken = 1; } return(assumedArtifactCount[digSite] / (assumedArtifactCount[digSite] + 16) + bonusToken); }
/// <summary> /// Called in a constructor to fill with data /// </summary> /// <param name="digSite">where to dig</param> /// <param name="player">player who is ready to dig</param> /// <param name="executeAction">method to execute action once a dig starts</param> /// <param name="tokens">tokens present at the digsite</param> private void Initialize(IDigSite digSite, IPlayer player, Func <IAction, Task> executeAction, List <IToken> tokens) { this.digSite = digSite; this.player = player; this.executeAction = executeAction; this.Text = digSite.Name; lDigSiteName.Text = digSite.Name; // display knowledge points lSpecializedKnowledgeAmount.Text = player.SpecializedKnowledge[digSite].ToString(); lGeneralKnowledgeAmount.Text = player.GeneralKnowledge.ToString(); lAssistantKnowledgeAmount.Text = player.GetAssistantKnowledge().ToString(); // display single use cards List <ICard> singleUseCards = player.GetUsableSingleUseCards(digSite); clSingleUseCards.Initialize(singleUseCards.ConvertAll(UIGame.ToView), UpdateInfo); // display tokens foreach (ITokenView token in tokens.ConvertAll(UIGame.ToView)) { if (!(token is DirtTokenView)) { flpTokens.Controls.Add(new PictureBox() { Width = 50, Height = 50, SizeMode = PictureBoxSizeMode.StretchImage, Tag = token, Image = Image.FromFile(UIConfig.IMG_FOLDER + token.FileName) }); } } weeksToDig = 0; singleUseCards = new List <ICard>(); player.GetDigStats(digSite, singleUseCards, out totalKnowledge, out tokenBonus); // token table int rowIndex; DataGridViewRow row; for (int weeks = 1; weeks <= 12; weeks++) { rowIndex = this.dgvTokenTable.Rows.Add(); row = this.dgvTokenTable.Rows[rowIndex]; row.Cells["weeksSpent"].Value = weeks; row.Cells["tokensDrawn"].Value = GameSettings.DugTokenCount(totalKnowledge, weeks); } dgvTokenTable.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; }
/// <summary> /// Computes the sum of artifact values at a given dig site /// </summary> /// <param name="digSite">Specified dig site </param> /// <returns>Sum of artifact values</returns> public int ArtifactSum(IDigSite digSite) { int sum = 0; foreach (IToken token in digSite.Tokens) { if (token is IArtifactToken) { sum += ((IArtifactToken)token).Points; } } return(sum); }
// TODO what about knowledge tokens? private double ExpectedValueOfToken(IDigSite digSite) { int tokenValueSum = 0; foreach (IToken token in Game.DigsiteInventory[digSite]) { if (token is IArtifactToken) { tokenValueSum += ((IArtifactToken)token).Points; } } return(tokenValueSum / Game.DigsiteInventory[digSite].Count); }
/// <summary> /// Opens the dig form /// </summary> /// <param name="digSite"></param> private void OpenDigForm(IDigSite digSite) { if (game.ActivePlayer is IAIPlayer) { MessageBox.Show("It's not your turn!"); return; } DigForm digForm = new DigForm(digSite, game.ActivePlayer, ExecuteActionAsync, game.DigsiteInventory[digSite]); DialogResult result = digForm.ShowDialog(); UpdateBoard(); }
private int PossibleExcavations(IPlayer player, IDigSite digSite) { int excavations = 0; for (int i = player.Time.CurrentYear; i <= Time.finalYear; i++) { excavations++; } if (!player.Permissions[digSite] && excavations > 0) { excavations--; } return(excavations); }
/// <summary> /// Computes total knowledge and token bonus for this player at given digsite. /// </summary> /// <param name="digSite">dig site to dig at</param> /// <param name="singleUseCards">single-use cards to use</param> /// <param name="knowledge">total knowledge</param> /// <param name="tokenBonus">token bonus</param> public void GetDigStats(IDigSite digSite, List <ICard> singleUseCards, out int knowledge, out int tokenBonus) { knowledge = 0; tokenBonus = 0; tokenBonus += GetShovelBonus(); knowledge += SpecializedKnowledge[digSite]; knowledge += GeneralKnowledge; knowledge += GetAssistantKnowledge(); AddSingleUseCardsStats(digSite, singleUseCards, ref knowledge, ref tokenBonus); return; }
/// <summary> /// Gets single-use cards usable at given dig site /// </summary> /// <param name="digSite"></param> /// <returns>List of usable single-use cards</returns> public List <ICard> GetUsableSingleUseCards(IDigSite digSite) { List <ICard> singleUseCards = new List <ICard>(); foreach (ICard card in Cards) { if ((card is IRumorsCard && ((IRumorsCard)card).digSite == digSite) || (Assistants == 1 && card is IAssistantCard) || (Shovels == 1 && card is IShovelCard) ) { singleUseCards.Add(card); } } return(singleUseCards); }
/// <summary> /// Randomly draws the requested amount of tokens. Keeping just the dirt. /// </summary> /// <param name="tokenAmount"></param> /// <returns>List of drawn tokens</returns> public List <IToken> DrawTokens(IDigSite digSite, int tokenAmount) { List <IToken> tokensDrawn = new List <IToken>(); List <IToken> tokens = DigsiteInventory[digSite]; for (int i = 0; i < tokenAmount; i++) { IToken tokenDrawn = tokens[random.Next(0, tokens.Count)]; if (!(tokenDrawn is IDirtToken)) { tokens.Remove(tokenDrawn); } tokensDrawn.Add(tokenDrawn); } // add bonus token if available if (BonusTokens[digSite] != null) { tokensDrawn.Add(BonusTokens[digSite]); BonusTokens[digSite] = null; } return(tokensDrawn); }
public DigForm(IDigSite digSite, IPlayer player, Func <IAction, Task> executeAction, List <IToken> tokens) { InitializeComponent(); Initialize(digSite, player, executeAction, tokens); UpdateInfo(); }
/// <summary> /// Loads all data from a .thc file. The format is specified in the documentation /// </summary> /// <param name="path"></param> public static void LoadFromFile(string path) { Places = new List <IPlace>(); Cards = new List <ICard>(); Queue <string[]> lines = new Queue <string[]>(); // load lines StreamReader sr = new StreamReader(path); string lineString; string[] line; while ((lineString = sr.ReadLine()) != null) { line = lineString.Split((char[])null, options: StringSplitOptions.RemoveEmptyEntries); if (line.Length != 0 && !line[0].Equals("") && line[0][0] != '#') // is not comment or empty { lines.Enqueue(line); } } sr.Close(); line = lines.Dequeue(); // UNIVERSITIES if (!line[0].Equals("UNIVERSITIES")) { throw new FormatException("invalid config file format"); } int index = 0; while (lines.Count > 0 && !(line = lines.Dequeue())[0].Equals("DIGSITES")) { Places.Add(new University(line[0], index++)); } // DIGSITES if (!line[0].Equals("DIGSITES")) { throw new FormatException("invalid config file format"); } while (lines.Count > 0 && !(line = lines.Dequeue())[0].Equals("CARDCHANGEPLACES")) { Places.Add(new DigSite(line[0], index++)); } // CARDCHANGEPLACES if (!line[0].Equals("CARDCHANGEPLACES")) { throw new FormatException("invalid config file format"); } while (lines.Count > 0 && !(line = lines.Dequeue())[0].Equals("STARTINGPLACE")) { Places.Add(new CardChangePlace(line[0], index++)); } if (!line[0].Equals("STARTINGPLACE")) { throw new FormatException("invalid config file format"); } StartingPlace = getPlaceByName(line[1]); int itemID = 0; // DISTRIBUTIONS line = lines.Dequeue(); if (!line[0].Equals("DISTRIBUTIONS")) { throw new FormatException("invalid config file format"); } line = lines.Dequeue(); for (int i = 0; i < Places.Where(x => x is IDigSite).Count(); i++) { if (!line[0].Equals("TOKENS")) { throw new FormatException("invalid config file format"); } IDigSite digSite = (IDigSite)getPlaceByName(line[1]); while (lines.Count > 0 && !(line = lines.Dequeue())[0].Equals("TOKENS") && !line[0].Equals("DISTANCEMATRIX")) { switch (line[0]) { case "dirt": digSite.Tokens.Add(new DirtToken(itemID++.ToString("0000"), digSite)); break; case "specializedKnowledge": digSite.Tokens.Add(new SpecializedKnowledgeToken(itemID++.ToString("0000"), digSite, int.Parse(line[1]), (IDigSite)getPlaceByName(line[2]))); break; case "generalKnowledge": digSite.Tokens.Add(new GeneralKnowledgeToken(itemID++.ToString("0000"), digSite, int.Parse(line[1]))); break; case "artifact": digSite.Tokens.Add(new ArtifactToken(itemID++.ToString("0000"), digSite, int.Parse(line[1]), line[2])); break; default: throw new FormatException("invalid config file format"); } } } // DISTANCE MATRIX if (!line[0].Equals("DISTANCEMATRIX")) { throw new FormatException("invalid config file format"); } if (!(line = lines.Dequeue())[0].Equals("PLACES")) { throw new FormatException("invalid config file format"); } int[] indexMapping = new int[Places.Count + 1]; for (int i = 1; i < indexMapping.Length; i++) { indexMapping[i] = getPlaceByName(line[i]).Index; } Distances = new int[Places.Count, Places.Count]; for (int i = 0; i < Places.Count; i++) { line = lines.Dequeue(); IPlace place = getPlaceByName(line[0]); for (int j = 1; j < indexMapping.Length; j++) { Distances[place.Index, indexMapping[j]] = int.Parse(line[j]); } } // CARDS if (!(line = lines.Dequeue())[0].Equals("CARDS")) { throw new FormatException("invalid config file format"); } line = lines.Dequeue(); while (lines.Count > 0 && !line[0].Equals("TIMEWHEEL")) { switch (line[0]) { case "specializedKnowledge": Cards.Add(new SpecializedKnowledgeCard(itemID++.ToString("0000"), (IUniversity)getPlaceByName(line[1]), int.Parse(line[2]), int.Parse(line[3]), (IDigSite)getPlaceByName(line[4]))); break; case "generalKnowledge": Cards.Add(new GeneralKnowledgeCard(itemID++.ToString("0000"), (IUniversity)getPlaceByName(line[1]), int.Parse(line[2]), int.Parse(line[3]))); break; case "rumors": Cards.Add(new RumorsCard(itemID++.ToString("0000"), (IUniversity)getPlaceByName(line[1]), int.Parse(line[2]), int.Parse(line[3]), (IDigSite)getPlaceByName(line[4]))); break; case "zeppelin": Cards.Add(new ZeppelinCard(itemID++.ToString("0000"), (IUniversity)getPlaceByName(line[1]), int.Parse(line[2]))); break; case "car": Cards.Add(new CarCard(itemID++.ToString("0000"), (IUniversity)getPlaceByName(line[1]), int.Parse(line[2]))); break; case "assistant": Cards.Add(new AssistantCard(itemID++.ToString("0000"), (IUniversity)getPlaceByName(line[1]), int.Parse(line[2]))); break; case "shovel": Cards.Add(new ShovelCard(itemID++.ToString("0000"), (IUniversity)getPlaceByName(line[1]), int.Parse(line[2]))); break; case "specialPermission": Cards.Add(new SpecialPermissionCard(itemID++.ToString("0000"), (IUniversity)getPlaceByName(line[1]), int.Parse(line[2]))); break; case "congress": Cards.Add(new CongressCard(itemID++.ToString("0000"), (IUniversity)getPlaceByName(line[1]), int.Parse(line[2]))); break; case "exhibition": List <IDigSite> artifactsRequired = new List <IDigSite>(); for (int i = 4; i < line.Length; i++) { artifactsRequired.Add((IDigSite)getPlaceByName(line[i])); } Cards.Add(new ExhibitionCard(itemID++.ToString("0000"), (IUniversity)getPlaceByName(line[1]), int.Parse(line[2]), int.Parse(line[3]), artifactsRequired)); break; default: throw new FormatException("invalid config file format"); } line = lines.Dequeue(); } // TIMEWHEEL if (!line[0].Equals("TIMEWHEEL")) { throw new FormatException("invalid config file format"); } TimeWheel = new Dictionary <int, Dictionary <int, int> >(); int knowledge; while (lines.Count > 0) { line = lines.Dequeue(); knowledge = int.Parse(line[0]); TimeWheel.Add(knowledge, new Dictionary <int, int>()); for (int i = 1; i < line.Length; i++) { TimeWheel[knowledge].Add(i, int.Parse(line[i])); } } }
public Token(string id, IDigSite digSite) : base(id) { this.DigSite = digSite; }
public SpecializedKnowledgeToken(string id, IDigSite digSite, int knowledgeAmount, IDigSite knowledgeDigSite) : base(id, digSite) { this.KnowledgeAmount = knowledgeAmount; this.KnowledgeDigSite = knowledgeDigSite; }
public double AssumedArtifacts(IDigSite digSite) { return(this.Tokens[digSite].Where(y => y is IArtifactToken).Count() + assumedArtifacts[digSite]); }
public GeneralKnowledgeToken(string id, IDigSite digSite, int knowledgeAmount) : base(id, digSite) { this.KnowledgeAmount = knowledgeAmount; }
public ArtifactToken(string id, IDigSite digSite, int points, string name) : base(id, digSite) { this.Points = points; this.Name = name; }
/// <summary> /// Moves a player to the dig site and proceeds to dig according to the amount of knowledge and weeks spend. /// </summary> /// <param name="digSite">Where to dig</param> /// <param name="weeks">How long to dig</param> /// <param name="singleUseCards">Single use cards to use</param> public virtual List <IToken> Dig(IDigSite digSite, int weeks, List <ICard> singleUseCards) { int travelTime = GameSettings.GetDistance(CurrentPlace, digSite); if (useZeppelin) { travelTime = 0; } if (Time.RemainingWeeks() < weeks + travelTime) { errorDialog("You don't have enough time!"); return(null); } if (!Permissions[digSite]) { if (SpecialPermissions > 0) { SpecialPermissions--; // Permissions[digSite] = true; not needed } else { errorDialog("You don't have a valid permisssion!"); return(null); } } if (SpecializedKnowledge[digSite] < 1) { errorDialog("You need at least one specialized knowledge!"); return(null); } MoveTo(digSite); Permissions[digSite] = false; Time.SpendWeeks(weeks); // get token amount GetDigStats(digSite, singleUseCards, out int knowledge, out int tokenBonus); int tokenAmount = GameSettings.DugTokenCount(knowledge, weeks) + tokenBonus; // draw tokens and give them to player List <IToken> dugTokens = drawTokens(digSite, tokenAmount); foreach (IToken token in dugTokens) { token.UpdateStats(this); if (!(token is IDirtToken)) { Tokens[digSite].Add(token); } } // discard single-use cards used if (singleUseCards != null) { foreach (ICard card in singleUseCards) { Cards.Remove(card); discardCard(card); } } UpdateStats(); return(dugTokens); }
public DirtToken(string id, IDigSite digSite) : base(id, digSite) { }
public SpecializedKnowledgeCard(string id, IUniversity place, int weeks, int knowledgeAmount, IDigSite digSite) : base(id, place, weeks) { this.KnowledgeAmount = knowledgeAmount; this.digSite = digSite; }