aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fl.fischer@fau.de>2017-02-18 19:39:31 +0100
committerFlorian Fischer <florian.fl.fischer@fau.de>2017-02-18 19:39:31 +0100
commit23ac00e3ae0f2810a4c6fe77744cb7d66cd4b427 (patch)
tree60bb7fe0cc773406cbafe8165817b57095f90979
parentf6a7a62c9de6348532cdf608ef554bc78c433935 (diff)
downloadgoffel-23ac00e3ae0f2810a4c6fe77744cb7d66cd4b427.tar.gz
goffel-23ac00e3ae0f2810a4c6fe77744cb7d66cd4b427.zip
score: improve Insert() and Cancel() error strings
-rw-r--r--logic/score.go21
1 files changed, 10 insertions, 11 deletions
diff --git a/logic/score.go b/logic/score.go
index 816e0ab..6d864b5 100644
--- a/logic/score.go
+++ b/logic/score.go
@@ -4,7 +4,6 @@
package logic
import (
- "errors"
"fmt"
)
@@ -75,7 +74,7 @@ func (s Score) String() string {
func (s_ *Score) Insert(d Dices, pos int) (int, error) {
s := *s_
if pos < 0 || pos > 12 {
- return 0, errors.New("Index out of range")
+ return 0, fmt.Errorf("Position %d out of range", pos)
}
if s[pos] == -1 {
switch pos {
@@ -84,37 +83,37 @@ func (s_ *Score) Insert(d Dices, pos int) (int, error) {
s[pos] = d.Sum(0)
return s[pos], nil
}
- return 0, errors.New("Not three of a kind")
+ return 0, fmt.Errorf("%v is not %s", d, ScoreNames[pos])
case 7:
if d.IsFourOfAKind() {
s[pos] = d.Sum(0)
return s[pos], nil
}
- return 0, errors.New("Not four of a kind")
+ return 0, fmt.Errorf("%v is not %s", d, ScoreNames[pos])
case 8:
if d.IsFullHouse() {
s[pos] = 25
return 25, nil
}
- return 0, errors.New("Not a full house")
+ return 0, fmt.Errorf("%v is not %s", d, ScoreNames[pos])
case 9:
if d.IsSmallStraight() {
s[pos] = 30
return 30, nil
}
- return 0, errors.New("Not a small straight")
+ return 0, fmt.Errorf("%v is not %s", d, ScoreNames[pos])
case 10:
if d.IsLargeStraight() {
s[pos] = 40
return 40, nil
}
- return 0, errors.New("Not a large straight")
+ return 0, fmt.Errorf("%v is not %s", d, ScoreNames[pos])
case 11:
if d.IsYahtzee() {
s[pos] = 50
return 50, nil
}
- return 0, errors.New("Not a yahtzee")
+ return 0, fmt.Errorf("%v is not %s", d, ScoreNames[pos])
case 12:
s[pos] = d.Sum(0)
return s[pos], nil
@@ -122,17 +121,17 @@ func (s_ *Score) Insert(d Dices, pos int) (int, error) {
s[pos] = d.Sum(pos + 1)
return s[pos], nil
}
- return 0, errors.New("Already recorded")
+ return 0, fmt.Errorf("%s (%d) is already recorded", ScoreNames[pos], pos+1)
}
func (s_ *Score) Cancel(pos int) error {
s := *s_
if pos < 0 || pos > 12 {
- return errors.New("Index out of range")
+ return fmt.Errorf("Position %d out of range", pos)
}
if s[pos] == -1 {
s[pos] = 0
return nil
}
- return errors.New("Already recorded")
+ return fmt.Errorf("%s (%d) is already recorded", ScoreNames[pos], pos+1)
}