summaryrefslogtreecommitdiff
path: root/Analizator9000
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2012-11-15 02:35:48 +0000
committeremkael <emkael@tlen.pl>2012-11-15 02:35:48 +0000
commitd972baf90fe99ef9ecd9881b063e2594710912a4 (patch)
tree3b0cb8c5fe0ed9d8aebd95dea39afbd69fee2d24 /Analizator9000
parentbf0f197187b2d4403d4e80da5d36048fab3834b3 (diff)
* bcalc wrapper
git-svn-id: https://svn.emkael.info/an9k@7 05ec0d5d-773b-4d93-9e23-c81a7ac79feb
Diffstat (limited to 'Analizator9000')
-rw-r--r--Analizator9000/Analizator9000/Analizator9000.csproj2
-rw-r--r--Analizator9000/Analizator9000/BCalcWrapper.cs51
-rw-r--r--Analizator9000/Analizator9000/DealerWrapper.cs2
-rw-r--r--Analizator9000/Analizator9000/Form1.Designer.cs61
-rw-r--r--Analizator9000/Analizator9000/Form1.cs11
5 files changed, 95 insertions, 32 deletions
diff --git a/Analizator9000/Analizator9000/Analizator9000.csproj b/Analizator9000/Analizator9000/Analizator9000.csproj
index aca4d4e..cb9e123 100644
--- a/Analizator9000/Analizator9000/Analizator9000.csproj
+++ b/Analizator9000/Analizator9000/Analizator9000.csproj
@@ -47,6 +47,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
+ <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>Icon1.ico</ApplicationIcon>
@@ -64,6 +65,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="BCalcWrapper.cs" />
<Compile Include="DealerParser.cs" />
<Compile Include="DealerWrapper.cs" />
<Compile Include="Form1.cs">
diff --git a/Analizator9000/Analizator9000/BCalcWrapper.cs b/Analizator9000/Analizator9000/BCalcWrapper.cs
new file mode 100644
index 0000000..c25d23b
--- /dev/null
+++ b/Analizator9000/Analizator9000/BCalcWrapper.cs
@@ -0,0 +1,51 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Runtime.InteropServices;
+using System.Windows.Forms;
+
+namespace Analizator9000
+{
+ class BCalcWrapper
+ {
+ [DllImport("bin\\libbcalcdds.dll", CallingConvention = CallingConvention.Cdecl)]
+ private static extern IntPtr bcalcDDS_new(IntPtr format, IntPtr hands, Int32 trump, Int32 leader);
+
+ [DllImport("bin\\libbcalcdds.dll", CallingConvention = CallingConvention.Cdecl)]
+ private static extern Int32 bcalcDDS_getTricksToTake(IntPtr solver);
+
+ [DllImport("bin\\libbcalcdds.dll", CallingConvention = CallingConvention.Cdecl)]
+ private static extern IntPtr bcalcDDS_getLastError(IntPtr solver);
+
+ [DllImport("bin\\libbcalcdds.dll", CallingConvention = CallingConvention.Cdecl)]
+ private static extern void bcalcDDS_delete(IntPtr solver);
+
+ private static String table = "NESW";
+ private static String trumps = "CDHSN";
+ public static int runDeal(String deal, char trumpSuit, char declarer)
+ {
+ int decl = BCalcWrapper.table.IndexOf(declarer);
+ if (decl < 0)
+ {
+ throw new Exception("Nieprawidłowy rozgrywający");
+ }
+ int leader = (decl + 1) % 4;
+ int trump = BCalcWrapper.trumps.IndexOf(trumpSuit);
+ if (trump < 0)
+ {
+ throw new Exception("Nieprawidłowe miano");
+ }
+ IntPtr solver = BCalcWrapper.bcalcDDS_new(Marshal.StringToHGlobalAnsi(BCalcWrapper.table), Marshal.StringToHGlobalAnsi(deal), trump, leader);
+ IntPtr error = BCalcWrapper.bcalcDDS_getLastError(solver);
+ String eStr = Marshal.PtrToStringAnsi(error);
+ if (eStr != null)
+ {
+ throw new Exception(eStr);
+ }
+ int ret = 13 - BCalcWrapper.bcalcDDS_getTricksToTake(solver);
+ BCalcWrapper.bcalcDDS_delete(solver);
+ return ret;
+ }
+ }
+}
diff --git a/Analizator9000/Analizator9000/DealerWrapper.cs b/Analizator9000/Analizator9000/DealerWrapper.cs
index b17c9ab..ac00e6e 100644
--- a/Analizator9000/Analizator9000/DealerWrapper.cs
+++ b/Analizator9000/Analizator9000/DealerWrapper.cs
@@ -51,7 +51,7 @@ namespace Analizator9000
this.lineCount++;
}
}
- int progress = ((int)(Convert.ToDouble(this.lineCount) / Convert.ToDouble(this.produce) * 100));
+ int progress = ((int)(100 * this.lineCount / this.produce));
this.debugForm.setProgress(progress);
this.debugWriteLine(data);
return true;
diff --git a/Analizator9000/Analizator9000/Form1.Designer.cs b/Analizator9000/Analizator9000/Form1.Designer.cs
index 3b8c459..73f609f 100644
--- a/Analizator9000/Analizator9000/Form1.Designer.cs
+++ b/Analizator9000/Analizator9000/Form1.Designer.cs
@@ -66,14 +66,14 @@
this.button1 = new System.Windows.Forms.Button();
this.generateFileNameTextBox = new System.Windows.Forms.TextBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
- this.button4 = new System.Windows.Forms.Button();
+ this.analyzeButton = new System.Windows.Forms.Button();
this.contractList = new System.Windows.Forms.ComboBox();
this.declarerList = new System.Windows.Forms.ComboBox();
this.label15 = new System.Windows.Forms.Label();
this.label14 = new System.Windows.Forms.Label();
this.label13 = new System.Windows.Forms.Label();
- this.button3 = new System.Windows.Forms.Button();
- this.analyzeFileNameTexBox = new System.Windows.Forms.TextBox();
+ this.button2 = new System.Windows.Forms.Button();
+ this.analyzeFileNameTextBox = new System.Windows.Forms.TextBox();
this.generateFileDialog = new System.Windows.Forms.OpenFileDialog();
this.progressBar = new System.Windows.Forms.ProgressBar();
this.statusListBox = new System.Windows.Forms.ListBox();
@@ -498,14 +498,14 @@
//
// groupBox2
//
- this.groupBox2.Controls.Add(this.button4);
+ this.groupBox2.Controls.Add(this.analyzeButton);
this.groupBox2.Controls.Add(this.contractList);
this.groupBox2.Controls.Add(this.declarerList);
this.groupBox2.Controls.Add(this.label15);
this.groupBox2.Controls.Add(this.label14);
this.groupBox2.Controls.Add(this.label13);
- this.groupBox2.Controls.Add(this.button3);
- this.groupBox2.Controls.Add(this.analyzeFileNameTexBox);
+ this.groupBox2.Controls.Add(this.button2);
+ this.groupBox2.Controls.Add(this.analyzeFileNameTextBox);
this.groupBox2.Location = new System.Drawing.Point(531, 12);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(513, 179);
@@ -513,14 +513,15 @@
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Analiza";
//
- // button4
+ // analyzeButton
//
- this.button4.Location = new System.Drawing.Point(7, 133);
- this.button4.Name = "button4";
- this.button4.Size = new System.Drawing.Size(497, 40);
- this.button4.TabIndex = 11;
- this.button4.Text = "ANALIZUJ";
- this.button4.UseVisualStyleBackColor = true;
+ this.analyzeButton.Location = new System.Drawing.Point(7, 133);
+ this.analyzeButton.Name = "analyzeButton";
+ this.analyzeButton.Size = new System.Drawing.Size(497, 40);
+ this.analyzeButton.TabIndex = 11;
+ this.analyzeButton.Text = "ANALIZUJ";
+ this.analyzeButton.UseVisualStyleBackColor = true;
+ this.analyzeButton.Click += new System.EventHandler(this.analyzeButton_Click);
//
// contractList
//
@@ -580,22 +581,23 @@
this.label13.TabIndex = 2;
this.label13.Text = "Kontrakt:";
//
- // button3
+ // button2
//
- this.button3.Location = new System.Drawing.Point(432, 20);
- this.button3.Name = "button3";
- this.button3.Size = new System.Drawing.Size(75, 23);
- this.button3.TabIndex = 1;
- this.button3.Text = "Wybierz plik";
- this.button3.UseVisualStyleBackColor = true;
+ this.button2.Location = new System.Drawing.Point(432, 20);
+ this.button2.Name = "button2";
+ this.button2.Size = new System.Drawing.Size(75, 23);
+ this.button2.TabIndex = 1;
+ this.button2.Text = "Wybierz plik";
+ this.button2.UseVisualStyleBackColor = true;
+ this.button2.Click += new System.EventHandler(this.button2_Click);
//
- // analyzeFileNameTexBox
+ // analyzeFileNameTextBox
//
- this.analyzeFileNameTexBox.Location = new System.Drawing.Point(7, 20);
- this.analyzeFileNameTexBox.Name = "analyzeFileNameTexBox";
- this.analyzeFileNameTexBox.ReadOnly = true;
- this.analyzeFileNameTexBox.Size = new System.Drawing.Size(419, 20);
- this.analyzeFileNameTexBox.TabIndex = 0;
+ this.analyzeFileNameTextBox.Location = new System.Drawing.Point(7, 20);
+ this.analyzeFileNameTextBox.Name = "analyzeFileNameTextBox";
+ this.analyzeFileNameTextBox.ReadOnly = true;
+ this.analyzeFileNameTextBox.Size = new System.Drawing.Size(419, 20);
+ this.analyzeFileNameTextBox.TabIndex = 0;
//
// generateFileDialog
//
@@ -618,7 +620,6 @@
//
// analyzeFileDialog
//
- this.analyzeFileDialog.FileName = "openFileDialog2";
this.analyzeFileDialog.FileOk += new System.ComponentModel.CancelEventHandler(this.analyzeFileDialog_FileOk);
//
// textBox22
@@ -703,10 +704,10 @@
private System.Windows.Forms.Label label15;
private System.Windows.Forms.Label label14;
private System.Windows.Forms.Label label13;
- private System.Windows.Forms.Button button3;
- private System.Windows.Forms.TextBox analyzeFileNameTexBox;
+ private System.Windows.Forms.Button button2;
+ private System.Windows.Forms.TextBox analyzeFileNameTextBox;
private System.Windows.Forms.OpenFileDialog analyzeFileDialog;
- private System.Windows.Forms.Button button4;
+ private System.Windows.Forms.Button analyzeButton;
private System.Windows.Forms.TextBox textBox22;
private System.Windows.Forms.RichTextBox conditionBox;
}
diff --git a/Analizator9000/Analizator9000/Form1.cs b/Analizator9000/Analizator9000/Form1.cs
index f277e4a..64dce0f 100644
--- a/Analizator9000/Analizator9000/Form1.cs
+++ b/Analizator9000/Analizator9000/Form1.cs
@@ -125,7 +125,7 @@ namespace Analizator9000
{
this.addStatusLine("Zapisano do pliku: " + filename);
}
- analyzeFileNameTexBox.Text = Path.GetFullPath(filename);
+ analyzeFileNameTextBox.Text = Path.GetFullPath(filename);
generateGroup.Enabled = true;
}
}
@@ -168,7 +168,16 @@ namespace Analizator9000
private void analyzeFileDialog_FileOk(object sender, CancelEventArgs e)
{
+ analyzeFileNameTextBox.Text = analyzeFileDialog.FileName;
+ }
+ private void button2_Click(object sender, EventArgs e)
+ {
+ analyzeFileDialog.ShowDialog();
+ }
+
+ private void analyzeButton_Click(object sender, EventArgs e)
+ {
}
}