diff options
-rw-r--r-- | BCDD.csproj | 2 | ||||
-rw-r--r-- | ParContract.cs | 73 | ||||
-rw-r--r-- | ParScore.cs | 25 |
3 files changed, 100 insertions, 0 deletions
diff --git a/BCDD.csproj b/BCDD.csproj index 50be342..4cc12ec 100644 --- a/BCDD.csproj +++ b/BCDD.csproj @@ -49,6 +49,8 @@ <ItemGroup>
<Compile Include="BCalcWrapper.cs" />
<Compile Include="DDTable.cs" />
+ <Compile Include="ParContract.cs" />
+ <Compile Include="ParScore.cs" />
<Compile Include="PBNBoard.cs" />
<Compile Include="PBNFile.cs" />
<Compile Include="Program.cs" />
diff --git a/ParContract.cs b/ParContract.cs new file mode 100644 index 0000000..fe08284 --- /dev/null +++ b/ParContract.cs @@ -0,0 +1,73 @@ +using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace BCDD
+{
+ class ParContract
+ {
+ public int Level = 0;
+ public char Denomination;
+ public char Declarer;
+ public bool Doubled = false;
+ public int Score = 0;
+
+ public ParContract() { }
+
+ public ParContract(int level, char denom, char declarer, bool doubled, int score)
+ {
+ this.Level = level;
+ this.Denomination = denom;
+ this.Declarer = declarer;
+ this.Doubled = doubled;
+ this.Score = score;
+ }
+
+ public ParContract Validate()
+ {
+ if (this.Score == 0)
+ {
+ return this;
+ }
+ if (this.Level < 1 || this.Level > 7)
+ {
+ throw new ParScoreInvalidException("Invalid par contract level: " + this.Level.ToString());
+ }
+ if (!"CDHSN".Contains(this.Denomination))
+ {
+ throw new ParScoreInvalidException("Invalid par contract denomination: " + this.Denomination);
+ }
+ if (!"NESW".Contains(this.Declarer))
+ {
+ throw new ParScoreInvalidException("Invalid par contract declarer: " + this.Declarer);
+ }
+ return this;
+ }
+
+ override public String ToString()
+ {
+ if (this.Score == 0)
+ {
+ return "PASS";
+ }
+ String contract = this.Level.ToString() + this.Denomination;
+ String risk = this.Doubled ? "x" : "";
+ String declarer = " " + this.Declarer;
+ String result = " " + this.Score.ToString("+#;-#;0");
+ return contract + risk + declarer + result;
+ }
+
+ public override bool Equals(object other)
+ {
+ ParContract obj = (ParContract)(other);
+ return this.Level == obj.Level && this.Denomination == obj.Denomination && this.Score == obj.Score;
+ }
+
+ public override int GetHashCode()
+ {
+ return this.Score + this.Level + 10000 * this.Denomination;
+ }
+
+ }
+}
diff --git a/ParScore.cs b/ParScore.cs new file mode 100644 index 0000000..2204145 --- /dev/null +++ b/ParScore.cs @@ -0,0 +1,25 @@ +using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Text.RegularExpressions;
+
+namespace BCDD
+{
+ class ParScoreInvalidException : FieldNotFoundException
+ {
+ public ParScoreInvalidException() : base() { }
+ public ParScoreInvalidException(String msg) : base(msg) { }
+ }
+
+ class ParScore
+ {
+ private PBNBoard board;
+
+ public ParScore(PBNBoard board)
+ {
+ this.board = board;
+ }
+
+ }
+}
|