aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fl.fischer@fau.de>2017-02-18 19:48:20 +0100
committerFlorian Fischer <florian.fl.fischer@fau.de>2017-02-18 19:48:20 +0100
commitc4f76699aa1459564792395f272052fce6b433bd (patch)
tree49f6220ec4d2314b6e5afbce1f84feeb24f7baf4
parent23ac00e3ae0f2810a4c6fe77744cb7d66cd4b427 (diff)
downloadgoffel-c4f76699aa1459564792395f272052fce6b433bd.tar.gz
goffel-c4f76699aa1459564792395f272052fce6b433bd.zip
TIL dice is the plural of die
-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
-rw-r--r--uis/interactive.go2
-rw-r--r--uis/server.go2
5 files changed, 17 insertions, 17 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)
diff --git a/uis/interactive.go b/uis/interactive.go
index ab23971..e493878 100644
--- a/uis/interactive.go
+++ b/uis/interactive.go
@@ -20,7 +20,7 @@ type Interactive struct {
players []intPlayer
}
-var dices Dices
+var dices Dice
var reader = bufio.NewReader(os.Stdin)
func (i *Interactive) Run() {
diff --git a/uis/server.go b/uis/server.go
index 321b507..f4e51e8 100644
--- a/uis/server.go
+++ b/uis/server.go
@@ -161,7 +161,7 @@ func (c *client) getBest() ([]player, int) {
}
func (c *client) round(round int, wg *sync.WaitGroup) {
- dice := logic.Dices{}
+ dice := logic.Dice{}
var msg sMsg
for _, p := range c.players {