Skip to content

Commit c0f5957

Browse files
committed
first commit
0 parents  commit c0f5957

157 files changed

Lines changed: 30146 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Main/.idea/.idea.ReplayParser/.idea/.name

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Main/.idea/.idea.ReplayParser/.idea/contentModel.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Main/.idea/.idea.ReplayParser/.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Main/.idea/.idea.ReplayParser/.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Main/.idea/.idea.ReplayParser/.idea/workspace.xml

Lines changed: 423 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Main/.idea/.idea.ReplayParser/riderModule.iml

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Main/.vs/ReplayParser/v14/.suo

158 KB
Binary file not shown.

Main/Program.cs

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.IO;
6+
using ReplayParser.Loader;
7+
using ReplayParser.Actions;
8+
using System.Diagnostics;
9+
10+
namespace ReplayParser.FeatureExtraction
11+
{
12+
class Program
13+
{
14+
private const char separater = ',';
15+
16+
17+
static void Main(string[] args)
18+
{
19+
20+
21+
if (args == null || args.Length == 0 || String.IsNullOrEmpty(args[0]))
22+
{
23+
Console.WriteLine("You need to specify a folder containing the replays.");
24+
return;
25+
}
26+
27+
// Set path of folder containing replay files
28+
string filepath = args[0];
29+
if (!Directory.Exists(filepath))
30+
{
31+
Console.WriteLine("Could not find the folder specified.");
32+
return;
33+
}
34+
35+
int take = 0;
36+
if (args.Length > 1)
37+
{
38+
take = int.Parse(args[1]);
39+
}
40+
41+
Stopwatch sw = new Stopwatch();
42+
sw.Start();
43+
44+
// Define building features.
45+
var buildingFeatures = new List<Entities.ObjectType>()
46+
{ Entities.ObjectType.Barracks, Entities.ObjectType.SupplyDepot,
47+
Entities.ObjectType.CommandCenter, Entities.ObjectType.Refinery,
48+
Entities.ObjectType.EngineeringBay, Entities.ObjectType.Bunker,
49+
Entities.ObjectType.Academy, Entities.ObjectType.Factory,
50+
Entities.ObjectType.MissileTurret, Entities.ObjectType.ComsatStation,
51+
Entities.ObjectType.MachineShop, Entities.ObjectType.Starport,
52+
Entities.ObjectType.Armory, Entities.ObjectType.ScienceFacility,
53+
Entities.ObjectType.ControlTower, Entities.ObjectType.PhysicsLab,
54+
Entities.ObjectType.CovertOps, Entities.ObjectType.NuclearSilo
55+
};
56+
57+
// Get list of replay filesnames
58+
var files = Directory.EnumerateFiles(filepath, "*.rep");
59+
if (take > 0)
60+
files = files.Take(take);
61+
62+
// Initialize the streamwriter for the output comma-separated file.
63+
using (var terranOut = new StreamWriter("terran.csv"))
64+
{
65+
66+
// Write the head of the output-file with the features.
67+
string featureString = "";
68+
featureString += "\"GAME\"" + separater;
69+
featureString += "\"PLAYER\"" + separater;
70+
foreach (var feature in buildingFeatures)
71+
{
72+
featureString += "\"" + feature.ToString().ToUpper() + "\"" + separater;
73+
}
74+
terranOut.WriteLine(featureString.TrimEnd(separater));
75+
76+
int count = 1;
77+
78+
// Iterate each replay file.
79+
string aggregateString = "";
80+
foreach (var file in files)
81+
{
82+
83+
// Parse replay
84+
var replay = ReplayLoader.LoadReplay(file);
85+
86+
// Filter out anything but terran, while getting players
87+
var players = replay.Players.Where(x => x.RaceType == Entities.RaceType.Terran);
88+
if (players == null || players.Count() == 0 || players.Count() > 2)
89+
continue;
90+
91+
// Iterate through each terran player.
92+
foreach (var player in players)
93+
{
94+
// Get the build actions of the given player
95+
var playerActions = replay.Actions.Where(x => x.Player == player
96+
&& x.ActionType == Entities.ActionType.Build)
97+
.Cast<BuildAction>();
98+
99+
if (playerActions.Count() == 0)
100+
continue;
101+
102+
// Begin building output string.
103+
aggregateString = "\"" + Path.GetFileName(file).Replace(separater, '_') + "\"" + separater;
104+
aggregateString += "\"" + player.Name.Replace(separater, '_') + "\"" + separater;
105+
106+
// Get first build time for each feature building
107+
foreach (var feature in buildingFeatures)
108+
{
109+
var buildTime = playerActions.Where(x => x.ObjectType == feature)
110+
.OrderBy(x => x.Frame)
111+
.Select(x => x.Frame)
112+
.FirstOrDefault() / 23; // The time is in "Ticks" - divide by 23 to approximate seconds.
113+
aggregateString += buildTime.ToString() + separater;
114+
}
115+
116+
// Write out the players features and flush
117+
terranOut.WriteLine(aggregateString.TrimEnd(separater));
118+
terranOut.Flush();
119+
120+
121+
}
122+
123+
Console.WriteLine("File #"+count+": (" + Path.GetFileName(file) + ") processed!");
124+
count++;
125+
}
126+
127+
terranOut.Flush();
128+
129+
} // Disposing streamwriter
130+
131+
sw.Stop();
132+
133+
Console.WriteLine("Done! Time: " + sw.Elapsed);
134+
}
135+
}
136+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace ReplayParser.Clusterer.BuildorderTree
7+
{
8+
public class Node<T>
9+
{
10+
private T data;
11+
private long occurances = 0;
12+
private NodeList<T> neighbors = null;
13+
14+
public Node() { }
15+
public Node(T data) : this(0, data, null) { }
16+
public Node(long occurances, T data, NodeList<T> neighbors)
17+
{
18+
this.data = data;
19+
this.neighbors = neighbors;
20+
this.occurances = occurances;
21+
}
22+
23+
public T Value
24+
{
25+
get
26+
{
27+
return data;
28+
}
29+
set
30+
{
31+
data = value;
32+
}
33+
}
34+
35+
public long Occurances
36+
{
37+
get
38+
{
39+
return occurances;
40+
}
41+
set
42+
{
43+
occurances = value;
44+
}
45+
}
46+
47+
public NodeList<T> Neighbors
48+
{
49+
get
50+
{
51+
return neighbors;
52+
}
53+
set
54+
{
55+
neighbors = value;
56+
}
57+
}
58+
59+
public void Visit(Action<Node<T>> v)
60+
{
61+
v(this);
62+
foreach (Node<T> n in Neighbors)
63+
{
64+
n.Visit(v);
65+
}
66+
}
67+
}
68+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Collections.ObjectModel;
6+
using ReplayParser.Interfaces;
7+
using ReplayParser.Actions;
8+
9+
namespace ReplayParser.Clusterer.BuildorderTree
10+
{
11+
public class NodeList<T> : Collection<Node<T>>
12+
{
13+
14+
public NodeList() : base() { }
15+
16+
public NodeList(int initialSize)
17+
{
18+
// Add the specified number of items
19+
for (int i = 0; i < initialSize; i++)
20+
base.Items.Add(default(Node<T>));
21+
}
22+
23+
public Node<T> FindByValue(T value)
24+
{
25+
// search the list for the value
26+
foreach (Node<T> node in Items)
27+
if (node.Value.Equals(value))
28+
return node;
29+
30+
// if we reached here, we didn't find a matching node
31+
return null;
32+
}
33+
34+
// Visit every node in graph
35+
public void Traverse(Action<Node<T>> v)
36+
{
37+
foreach (Node<T> i in Items)
38+
{
39+
i.Visit(v);
40+
}
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)