aboutsummaryrefslogtreecommitdiff
path: root/logic
diff options
context:
space:
mode:
Diffstat (limited to 'logic')
-rw-r--r--logic/dice.go (renamed from logic/dices.go)28
-rw-r--r--logic/dice_test.go (renamed from logic/dices_test.go)0
-rw-r--r--logic/score.go2
3 files changed, 15 insertions, 15 deletions
diff --git a/logic/dices.go b/logic/dice.go
index d6a8952..a5cbade 100644
--- a/logic/dices.go
+++ b/logic/dice.go
@@ -17,15 +17,15 @@ func SetFancyPrint(f bool) {
fancy = f
}
-type Dices [5]int
+type Dice [5]int
-func NewDices() Dices {
- d := Dices{}
+func NewDice() Dice {
+ d := Dice{}
d.Roll(nil)
return d
}
-func (d *Dices) Roll(i []int) error {
+func (d *Dice) Roll(i []int) error {
if i == nil || len(i) == 0 {
i = []int{1, 2, 3, 4, 5}
}
@@ -39,7 +39,7 @@ func (d *Dices) Roll(i []int) error {
return nil
}
-func (d Dices) String() string {
+func (d Dice) String() string {
s := ""
for _, v := range d {
if fancy {
@@ -51,7 +51,7 @@ func (d Dices) String() string {
return fmt.Sprintf("%s", s)
}
-func (d Dices) Sum(i int) int {
+func (d Dice) Sum(i int) int {
s := 0
for _, v := range d {
if v == i || i == 0 {
@@ -61,7 +61,7 @@ func (d Dices) Sum(i int) int {
return s
}
-func (d Dices) sumSame() []int {
+func (d Dice) sumSame() []int {
s := []int{1}
idx := 0
for i := 1; i < 5; i++ {
@@ -76,24 +76,24 @@ func (d Dices) sumSame() []int {
return s
}
-func (d Dices) IsThreeOfAKind() bool {
+func (d Dice) IsThreeOfAKind() bool {
return d.sumSame()[0] >= 3
}
-func (d Dices) IsFourOfAKind() bool {
+func (d Dice) IsFourOfAKind() bool {
return d.sumSame()[0] >= 4
}
-func (d Dices) IsFullHouse() bool {
+func (d Dice) IsFullHouse() bool {
s := d.sumSame()
return s[0] == 3 && s[1] == 2
}
-func (d Dices) IsYahtzee() bool {
+func (d Dice) IsYahtzee() bool {
return d.sumSame()[0] >= 5
}
-func (d Dices) isStraight(length int) bool {
+func (d Dice) isStraight(length int) bool {
s := 1
max_s := s
for i := 0; i < 4; i++ {
@@ -112,10 +112,10 @@ func (d Dices) isStraight(length int) bool {
return max_s >= length
}
-func (d Dices) IsSmallStraight() bool {
+func (d Dice) IsSmallStraight() bool {
return d.isStraight(4)
}
-func (d Dices) IsLargeStraight() bool {
+func (d Dice) IsLargeStraight() bool {
return d.isStraight(5)
}
diff --git a/logic/dices_test.go b/logic/dice_test.go
index 2a6c67c..2a6c67c 100644
--- a/logic/dices_test.go
+++ b/logic/dice_test.go
diff --git a/logic/score.go b/logic/score.go
index 6d864b5..1e51571 100644
--- a/logic/score.go
+++ b/logic/score.go
@@ -71,7 +71,7 @@ func (s Score) String() string {
return str
}
-func (s_ *Score) Insert(d Dices, pos int) (int, error) {
+func (s_ *Score) Insert(d Dice, pos int) (int, error) {
s := *s_
if pos < 0 || pos > 12 {
return 0, fmt.Errorf("Position %d out of range", pos)