blob: fe08284106f9888ed6f53bf1cc2975c380b39e90 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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;
}
}
}
|