From d972baf90fe99ef9ecd9881b063e2594710912a4 Mon Sep 17 00:00:00 2001 From: emkael Date: Thu, 15 Nov 2012 02:35:48 +0000 Subject: * bcalc wrapper git-svn-id: https://svn.emkael.info/an9k@7 05ec0d5d-773b-4d93-9e23-c81a7ac79feb --- .../Analizator9000/Analizator9000.csproj | 2 + Analizator9000/Analizator9000/BCalcWrapper.cs | 51 ++++++++++++++++++ Analizator9000/Analizator9000/DealerWrapper.cs | 2 +- Analizator9000/Analizator9000/Form1.Designer.cs | 61 +++++++++++----------- Analizator9000/Analizator9000/Form1.cs | 11 +++- 5 files changed, 95 insertions(+), 32 deletions(-) create mode 100644 Analizator9000/Analizator9000/BCalcWrapper.cs (limited to 'Analizator9000') 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 @@ TRACE prompt 4 + true Icon1.ico @@ -64,6 +65,7 @@ + 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) + { } } -- cgit v1.2.3