void LoadCards(CardDatabase database, String s) { string[] parts = s.Split('@'); String[] cardList = parts[0].Split(','); foreach (String c in cardList) { Card curCard = database.GetCard(c); if (curCard != null) { cards.Add(curCard); } } splitType = ""; if (parts.Contains("34Split")) { splitType = "data/34SplitSmall.png"; } if (parts.Contains("25Split")) { splitType = "data/25SplitSmall.png"; } prosperity = parts.Contains("Prosperity"); }
void DrawStrategy(CardDatabase database, String s, string leaderName, bool displayRating, int x, int y) { //Leader 0: 4.18262 e1-d3-p4-gold@99|laboratory@3|militia@1|silver@99 String[] parts = s.Split('\t'); g.DrawString(leaderName, bigFont, blackBrush, x, y); x += 55; double d = Convert.ToDouble(parts[1]); g.DrawString(FormatPercentage(d), drawFont, PercentageBrush(d), x, y + 20); x += 90; int estateThreshold = Convert.ToInt32(parts[2].Split('-')[0].Replace("e", "")); int duchyThreshold = Convert.ToInt32(parts[2].Split('-')[1].Replace("d", "")); int provinceThreshold = Convert.ToInt32(parts[2].Split('-')[2].Replace("p", "")); if (prosperity) { Image template = Bitmap.FromFile("data/prosperityBuyTemplate.png"); double ratio = (double)template.Height / (double)template.Width; g.DrawImage(template, new Rectangle(x, y, 120, (int)(120.0 * ratio)), new Rectangle(0, 0, template.Width, template.Height), GraphicsUnit.Pixel); template.Dispose(); int yOffset = -3; int ySpacing = 21; g.DrawString(estateThreshold.ToString(), drawFont, blackBrush, x + 60, y + yOffset); g.DrawString(duchyThreshold.ToString(), drawFont, blackBrush, x + 60, y + yOffset + ySpacing); g.DrawString(provinceThreshold.ToString(), drawFont, blackBrush, x + 60, y + yOffset + ySpacing * 2); } else { Image template = Bitmap.FromFile("data/coreBuyTemplate.png"); double ratio = (double)template.Height / (double)template.Width; g.DrawImage(template, new Rectangle(x, y, 120, (int)(120.0 * ratio)), new Rectangle(0, 0, template.Width, template.Height), GraphicsUnit.Pixel); template.Dispose(); int yOffset = 1; int ySpacing = 31; g.DrawString(estateThreshold.ToString(), drawFont, blackBrush, x + 60, y + yOffset); g.DrawString(duchyThreshold.ToString(), drawFont, blackBrush, x + 60, y + yOffset + ySpacing); } x += 145; String[] cardParts = parts[2].Split('-')[3].Split('|'); for (int cardIndex = 0; cardIndex < cardParts.Length; cardIndex++) { Card c = database.GetCard(cardParts[cardIndex].Split('@')[0]); int count = Convert.ToInt32(cardParts[cardIndex].Split('@')[1]); if (c.fullImage == null) { c.LoadBitmaps(); } double croppedCardRatio = 252.0 / 296.0; int yOffset = 0; if (c.set == "core") { yOffset = 116; } g.DrawImage(c.fullImage, new Rectangle(x + cardIndex * 80, y, (int)75.0, (int)(75.0 * croppedCardRatio)), new Rectangle(0, yOffset, c.fullImage.Width, 252), GraphicsUnit.Pixel); //if (count > 1 && count < 99) if (count > 1) { int xOffset = 25; if (count >= 10) { xOffset = 17; } g.DrawString("x" + count.ToString(), smallFont, blackBrush, x + cardIndex * 80 + xOffset, y + 59); } } }
public DominionVisualization(CardDatabase database, String filename, String saveFilename) { if (File.Exists(saveFilename)) { return; } List <String> lines; try { lines = new List <String>(File.ReadAllLines(filename)); } catch (Exception) { // // File might be in use by the strategization process. // return; } if (lines.Count <= 1) { return; } LoadCards(database, (lines.Find(delegate(String s) { return(s.StartsWith("Kingdom cards:")); }).Split('\t')[1])); if (lines[0] == "Leaderboard") { int leaderStartIndex = lines.FindIndex(delegate(String s) { return(s.StartsWith("Leaders:")); }); int leaderCount = Convert.ToInt32(lines[leaderStartIndex].Split('\t')[1]); int tournamentWidth = cellWidth * leaderCount + 75; int tournamentHeight = cellHeight * leaderCount + 19 + 35; int tournamentX = 1095; int imageWidth = tournamentX + tournamentWidth + 20; int iamgeHeight = 205 + leaderCount * 90 + 5; int tournamentY = iamgeHeight / 2 - tournamentHeight / 2; SetupGraphics(imageWidth, iamgeHeight); DrawKingdomCards(5, 4); g.DrawString("Dominant strategies", drawFont, blackBrush, 5, 170); for (int leaderIndex = 0; leaderIndex < leaderCount; leaderIndex++) { DrawStrategy(database, lines[leaderStartIndex + leaderIndex + 1], ((char)('A' + leaderIndex)).ToString(), true, 5, 205 + leaderIndex * 90); } DrawTournament(lines, tournamentX, tournamentY); } else if (lines[0] == "Progression") { int opponentStartIndex = lines.FindIndex(delegate(String s) { return(s.StartsWith("Opponents:")); }); int opponentCount = Convert.ToInt32(lines[opponentStartIndex].Split('\t')[1]); SetupGraphics(1170, 310 + opponentCount * 90 + 6); DrawKingdomCards(5, 4); g.DrawString("Leading strategy", drawFont, blackBrush, 5, 165); DrawStrategy(database, lines.Find(delegate(String s) { return(s.StartsWith("Leader")); }), "", false, -15, 195); g.DrawString("Competing strategies", drawFont, blackBrush, 5, 275); for (int opponentIndex = 0; opponentIndex < opponentCount; opponentIndex++) { DrawStrategy(database, lines[opponentStartIndex + opponentIndex + 1], "", false, -15, 310 + opponentIndex * 90); } } else if (lines[0] == "Generation") { int leaderStartIndex = lines.FindIndex(delegate(String s) { return(s.StartsWith("Leaders:")); }); int leaderCount = Convert.ToInt32(lines[leaderStartIndex].Split('\t')[1]); SetupGraphics(1026, 210 + leaderCount * 90 + 6); DrawKingdomCards(5, 4); g.DrawString("Dominant strategies", drawFont, blackBrush, 5, 170); for (int leaderIndex = 0; leaderIndex < leaderCount; leaderIndex++) { DrawStrategy(database, lines[leaderStartIndex + leaderIndex + 1], ((char)('A' + leaderIndex)).ToString(), true, 5, 205 + leaderIndex * 90); } } else if (lines[0] == "Counters") { // // Not yet visualized; counters don't seem to be that useful since as far as I can tell there is almost always a single dominant strategy // } bmp.Save(saveFilename); g.Dispose(); bmp.Dispose(); }
public DominionVisualization(CardDatabase database, String filename, String saveFilename) { if (File.Exists(saveFilename)) return; List<String> lines; try { lines = new List<String>(File.ReadAllLines(filename)); } catch (Exception) { // // File might be in use by the strategization process. // return; } if (lines.Count <= 1) { return; } LoadCards(database, (lines.Find(delegate(String s) { return s.StartsWith("Kingdom cards:"); }).Split('\t')[1])); if (lines[0] == "Leaderboard") { int leaderStartIndex = lines.FindIndex(delegate(String s) { return s.StartsWith("Leaders:"); }); int leaderCount = Convert.ToInt32(lines[leaderStartIndex].Split('\t')[1]); int tournamentWidth = cellWidth * leaderCount + 75; int tournamentHeight = cellHeight * leaderCount + 19 + 35; int tournamentX = 1095; int imageWidth = tournamentX + tournamentWidth + 20; int iamgeHeight = 205 + leaderCount * 90 + 5; int tournamentY = iamgeHeight / 2 - tournamentHeight / 2; SetupGraphics(imageWidth, iamgeHeight); DrawKingdomCards(5, 4); g.DrawString("Dominant strategies", drawFont, blackBrush, 5, 170); for (int leaderIndex = 0; leaderIndex < leaderCount; leaderIndex++) { DrawStrategy(database, lines[leaderStartIndex + leaderIndex + 1], ((char)('A' + leaderIndex)).ToString(), true, 5, 205 + leaderIndex * 90); } DrawTournament(lines, tournamentX, tournamentY); } else if (lines[0] == "Progression") { int opponentStartIndex = lines.FindIndex(delegate(String s) { return s.StartsWith("Opponents:"); } ); int opponentCount = Convert.ToInt32(lines[opponentStartIndex].Split('\t')[1]); SetupGraphics(1170, 310 + opponentCount * 90 + 6); DrawKingdomCards(5, 4); g.DrawString("Leading strategy", drawFont, blackBrush, 5, 165); DrawStrategy(database, lines.Find(delegate(String s) { return s.StartsWith("Leader"); }), "", false, -15, 195); g.DrawString("Competing strategies", drawFont, blackBrush, 5, 275); for (int opponentIndex = 0; opponentIndex < opponentCount; opponentIndex++) { DrawStrategy(database, lines[opponentStartIndex + opponentIndex + 1], "", false, -15, 310 + opponentIndex * 90); } } else if (lines[0] == "Generation") { int leaderStartIndex = lines.FindIndex(delegate(String s) { return s.StartsWith("Leaders:"); }); int leaderCount = Convert.ToInt32(lines[leaderStartIndex].Split('\t')[1]); SetupGraphics(1026, 210 + leaderCount * 90 + 6); DrawKingdomCards(5, 4); g.DrawString("Dominant strategies", drawFont, blackBrush, 5, 170); for (int leaderIndex = 0; leaderIndex < leaderCount; leaderIndex++) { DrawStrategy(database, lines[leaderStartIndex + leaderIndex + 1], ((char)('A' + leaderIndex)).ToString(), true, 5, 205 + leaderIndex * 90); } } else if (lines[0] == "Counters") { // // Not yet visualized; counters don't seem to be that useful since as far as I can tell there is almost always a single dominant strategy // } bmp.Save(saveFilename); g.Dispose(); bmp.Dispose(); }
void LoadCards(CardDatabase database, String s) { string[] parts = s.Split('@'); String[] cardList = parts[0].Split(','); foreach (String c in cardList) { Card curCard = database.GetCard(c); if (curCard != null) cards.Add(curCard); } splitType = ""; if (parts.Contains("34Split")) splitType = "data/34SplitSmall.png"; if (parts.Contains("25Split")) splitType = "data/25SplitSmall.png"; prosperity = parts.Contains("Prosperity"); }
void DrawStrategy(CardDatabase database, String s, string leaderName, bool displayRating, int x, int y) { //Leader 0: 4.18262 e1-d3-p4-gold@99|laboratory@3|militia@1|silver@99 String[] parts = s.Split('\t'); g.DrawString(leaderName, bigFont, blackBrush, x, y); x += 55; double d = Convert.ToDouble(parts[1]); g.DrawString(FormatPercentage(d), drawFont, PercentageBrush(d), x, y + 20); x += 90; int estateThreshold = Convert.ToInt32(parts[2].Split('-')[0].Replace("e","")); int duchyThreshold = Convert.ToInt32(parts[2].Split('-')[1].Replace("d", "")); int provinceThreshold = Convert.ToInt32(parts[2].Split('-')[2].Replace("p", "")); if (prosperity) { Image template = Bitmap.FromFile("data/prosperityBuyTemplate.png"); double ratio = (double)template.Height / (double)template.Width; g.DrawImage(template, new Rectangle(x, y, 120, (int)(120.0 * ratio)), new Rectangle(0, 0, template.Width, template.Height), GraphicsUnit.Pixel); template.Dispose(); int yOffset = -3; int ySpacing = 21; g.DrawString(estateThreshold.ToString(), drawFont, blackBrush, x + 60, y + yOffset); g.DrawString(duchyThreshold.ToString(), drawFont, blackBrush, x + 60, y + yOffset + ySpacing); g.DrawString(provinceThreshold.ToString(), drawFont, blackBrush, x + 60, y + yOffset + ySpacing * 2); } else { Image template = Bitmap.FromFile("data/coreBuyTemplate.png"); double ratio = (double)template.Height / (double)template.Width; g.DrawImage(template, new Rectangle(x, y, 120, (int)(120.0 * ratio)), new Rectangle(0, 0, template.Width, template.Height), GraphicsUnit.Pixel); template.Dispose(); int yOffset = 1; int ySpacing = 31; g.DrawString(estateThreshold.ToString(), drawFont, blackBrush, x + 60, y + yOffset); g.DrawString(duchyThreshold.ToString(), drawFont, blackBrush, x + 60, y + yOffset + ySpacing); } x += 145; String[] cardParts = parts[2].Split('-')[3].Split('|'); for (int cardIndex = 0; cardIndex < cardParts.Length; cardIndex++) { Card c = database.GetCard(cardParts[cardIndex].Split('@')[0]); int count = Convert.ToInt32(cardParts[cardIndex].Split('@')[1]); if (c.fullImage == null) c.LoadBitmaps(); double croppedCardRatio = 252.0 / 296.0; int yOffset = 0; if (c.set == "core") yOffset = 116; g.DrawImage(c.fullImage, new Rectangle(x + cardIndex * 80, y, (int)75.0, (int)(75.0 * croppedCardRatio)), new Rectangle(0, yOffset, c.fullImage.Width, 252), GraphicsUnit.Pixel); //if (count > 1 && count < 99) if (count > 1) { int xOffset = 25; if(count >= 10) xOffset = 17; g.DrawString("x" + count.ToString(), smallFont, blackBrush, x + cardIndex * 80 + xOffset, y + 59); } } }