summaryrefslogtreecommitdiff
path: root/Analizator9000
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2012-11-19 15:50:04 +0000
committeremkael <emkael@tlen.pl>2012-11-19 15:50:04 +0000
commit942644c79227d9fab2f80730ccf49a7e76bfb503 (patch)
tree8baca01390441a9e71f2b6605e9981bbe212cbc2 /Analizator9000
parent4443f7172edd9f54b9786d96b668bc5bd539d15b (diff)
* "average" action in dealer scripts
* dealer output encoding fix git-svn-id: https://svn.emkael.info/an9k@26 05ec0d5d-773b-4d93-9e23-c81a7ac79feb
Diffstat (limited to 'Analizator9000')
-rw-r--r--Analizator9000/Analizator9000/DealerParser.cs65
-rw-r--r--Analizator9000/Analizator9000/DealerWrapper.cs2
-rw-r--r--Analizator9000/Analizator9000/Form1.Designer.cs28
-rw-r--r--Analizator9000/Analizator9000/Form1.cs5
4 files changed, 98 insertions, 2 deletions
diff --git a/Analizator9000/Analizator9000/DealerParser.cs b/Analizator9000/Analizator9000/DealerParser.cs
index 1ed640c..b542554 100644
--- a/Analizator9000/Analizator9000/DealerParser.cs
+++ b/Analizator9000/Analizator9000/DealerParser.cs
@@ -28,6 +28,10 @@ namespace Analizator9000
/// Pre-dealt cards, indexed by player. Compiles into 'predeal' section of onput script.
/// </summary>
public Dictionary<String, String[]> predeal = new Dictionary<String, String[]>();
+ /// <summary>
+ /// "Actions" for Dealer to the check average value of.
+ /// </summary>
+ public List<String> actions = new List<String>();
/// <summary>
/// Loads the input script file and parses it. Parses out everything outside of predeal/condition/produce/generate/action sections.
@@ -123,6 +127,56 @@ namespace Analizator9000
}
}
break;
+ case "action":
+ Regex pattern = new Regex(@"(?<comma>,)|(?<open>\()|(?<close>\))|(?<token>[^,\(\)]*)");
+ MatchCollection matches = pattern.Matches(section.Aggregate((a, b) => a + b));
+ List<String> tokens = new List<String>();
+ foreach (Match match in matches)
+ {
+ int groupNo = 0;
+ foreach (Group group in match.Groups)
+ {
+ if (group.Success && groupNo > 0)
+ {
+ tokens.Add(group.Value);
+ }
+ groupNo++;
+ }
+ }
+ int open = 0;
+ List<String> actions = new List<String>();
+ String currentAction = "";
+ foreach (String token in tokens)
+ {
+ switch (token)
+ {
+ case "(":
+ open++;
+ currentAction += token;
+ break;
+ case ")":
+ open--;
+ currentAction += token;
+ break;
+ case ",":
+ if (open == 0)
+ {
+ actions.Add(currentAction.Trim());
+ currentAction = "";
+ }
+ else
+ {
+ currentAction += token;
+ }
+ break;
+ default:
+ currentAction += token;
+ break;
+ }
+ }
+ actions.Add(currentAction.Trim());
+ this.actions = actions.Where(s => s.StartsWith("average")).ToList();
+ break;
}
}
}
@@ -167,7 +221,16 @@ namespace Analizator9000
file.WriteLine("produce");
file.WriteLine(this.produce);
file.WriteLine("action");
- file.WriteLine("printoneline");
+ file.Write("printoneline");
+ foreach (String action in this.actions)
+ {
+ if (action.Trim().Length > 0)
+ {
+ file.WriteLine(",");
+ file.Write("average " + action);
+ }
+ }
+ file.WriteLine();
file.Close();
return filename;
}
diff --git a/Analizator9000/Analizator9000/DealerWrapper.cs b/Analizator9000/Analizator9000/DealerWrapper.cs
index e538d5e..e7ade21 100644
--- a/Analizator9000/Analizator9000/DealerWrapper.cs
+++ b/Analizator9000/Analizator9000/DealerWrapper.cs
@@ -5,6 +5,7 @@ using System.Text;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;
+using System.Globalization;
namespace Analizator9000
{
@@ -128,6 +129,7 @@ namespace Analizator9000
pInfo.UseShellExecute = false;
pInfo.RedirectStandardOutput = true;
pInfo.RedirectStandardError = true;
+ pInfo.StandardOutputEncoding = pInfo.StandardErrorEncoding = Encoding.UTF8;
this.debugWriteLine(pInfo.FileName + " " + pInfo.Arguments);
Process dealerProc = new Process();
dealerProc.StartInfo = pInfo;
diff --git a/Analizator9000/Analizator9000/Form1.Designer.cs b/Analizator9000/Analizator9000/Form1.Designer.cs
index 84a5ffd..619e0a5 100644
--- a/Analizator9000/Analizator9000/Form1.Designer.cs
+++ b/Analizator9000/Analizator9000/Form1.Designer.cs
@@ -107,6 +107,8 @@
this.analyzeFileDialog = new System.Windows.Forms.OpenFileDialog();
this.resultTextBox = new System.Windows.Forms.TextBox();
this.abortButton = new System.Windows.Forms.Button();
+ this.label23 = new System.Windows.Forms.Label();
+ this.actionsBox = new System.Windows.Forms.RichTextBox();
this.generateGroup.SuspendLayout();
this.tableLayoutPanel1.SuspendLayout();
this.analyzeGroup.SuspendLayout();
@@ -115,6 +117,8 @@
//
// generateGroup
//
+ this.generateGroup.Controls.Add(this.actionsBox);
+ this.generateGroup.Controls.Add(this.label23);
this.generateGroup.Controls.Add(this.conditionBox);
this.generateGroup.Controls.Add(this.generateButton);
this.generateGroup.Controls.Add(this.produceBox);
@@ -139,7 +143,7 @@
this.conditionBox.Font = new System.Drawing.Font("Lucida Console", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
this.conditionBox.Location = new System.Drawing.Point(10, 202);
this.conditionBox.Name = "conditionBox";
- this.conditionBox.Size = new System.Drawing.Size(476, 137);
+ this.conditionBox.Size = new System.Drawing.Size(253, 137);
this.conditionBox.TabIndex = 11;
this.conditionBox.Text = "";
//
@@ -954,6 +958,7 @@
//
// statusListBox
//
+ this.statusListBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
this.statusListBox.FormattingEnabled = true;
this.statusListBox.Location = new System.Drawing.Point(531, 343);
this.statusListBox.Name = "statusListBox";
@@ -985,6 +990,25 @@
this.abortButton.UseVisualStyleBackColor = true;
this.abortButton.Click += new System.EventHandler(this.abortButton_Click);
//
+ // label23
+ //
+ this.label23.AutoSize = true;
+ this.label23.Location = new System.Drawing.Point(269, 186);
+ this.label23.Name = "label23";
+ this.label23.Size = new System.Drawing.Size(134, 13);
+ this.label23.TabIndex = 12;
+ this.label23.Text = "Zdarzenia do sprawdzenia:";
+ //
+ // actionsBox
+ //
+ this.actionsBox.AcceptsTab = true;
+ this.actionsBox.Font = new System.Drawing.Font("Lucida Console", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
+ this.actionsBox.Location = new System.Drawing.Point(269, 202);
+ this.actionsBox.Name = "actionsBox";
+ this.actionsBox.Size = new System.Drawing.Size(217, 137);
+ this.actionsBox.TabIndex = 13;
+ this.actionsBox.Text = "";
+ //
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -1095,6 +1119,8 @@
private System.Windows.Forms.Label label19;
private System.Windows.Forms.Button abortButton;
private System.Windows.Forms.Button button3;
+ private System.Windows.Forms.Label label23;
+ private System.Windows.Forms.RichTextBox actionsBox;
}
}
diff --git a/Analizator9000/Analizator9000/Form1.cs b/Analizator9000/Analizator9000/Form1.cs
index d4cf024..ad2e595 100644
--- a/Analizator9000/Analizator9000/Form1.cs
+++ b/Analizator9000/Analizator9000/Form1.cs
@@ -81,6 +81,10 @@ namespace Analizator9000
predealSouthDiamondsBox.Text = parser.predeal["south"][2];
predealSouthClubsBox.Text = parser.predeal["south"][3];
}
+ foreach (String action in parser.actions)
+ {
+ actionsBox.Text += action.Substring("average".Length) + "\n";
+ }
generateFileNameTextBox.Text = generateFileDialog.FileName;
}
catch (Exception ex)
@@ -116,6 +120,7 @@ namespace Analizator9000
predeal.Value[i] = predeal.Value[i].ToUpper().Replace('D', 'Q').Replace('W', 'J').Replace("10", "T");
}
}
+ parser.actions = actionsBox.Text.Split('\n').ToList();
}
catch (Exception ex)
{