-
Notifications
You must be signed in to change notification settings - Fork 272
/
utils.go
75 lines (68 loc) · 1.47 KB
/
utils.go
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
74
75
package main
import (
"fmt"
"os"
"github.com/fatih/color"
"bufio"
)
func errorExit(args ...interface{}) {
fmt.Fprintln(os.Stderr, args...)
fmt.Println("按任意键退出...")
bufio.NewReader(os.Stdin).ReadByte()
os.Exit(1)
}
//
// 进张数优劣
func getWaitsCountColor(shanten int, waitsCount float64) color.Attribute {
_getWaitsCountColor := func(fixedWaitsCount float64) color.Attribute {
switch {
case fixedWaitsCount < 13: // 4.3*3
return color.FgHiCyan // FgHiBlue FgHiCyan
case fixedWaitsCount <= 18: // 6*3
return color.FgHiYellow
default: // >6*3
return color.FgHiRed
}
}
if shanten == 0 {
return _getWaitsCountColor(waitsCount * 3)
}
weight := 1
for i := 1; i < shanten; i++ {
weight *= 2
}
return _getWaitsCountColor(waitsCount / float64(weight))
}
// 他家中张舍牌提示
func getOtherDiscardAlertColor(index int) color.Attribute {
if index >= 27 {
return color.FgWhite
}
switch index%9 + 1 {
case 1, 2, 8, 9:
return color.FgWhite
case 3, 7:
return color.FgHiYellow
case 4, 5, 6:
return color.FgHiRed
default:
panic(fmt.Errorf("[getOtherDiscardAlertColor] 代码有误: index = %d", index))
}
}
// 铳率高低
func getNumRiskColor(risk float64) color.Attribute {
switch {
//case risk < 3:
// return color.FgHiBlue
case risk < 5:
return color.FgHiCyan
//case risk < 7.5:
// return color.FgYellow
case risk < 10:
return color.FgHiYellow
case risk < 15:
return color.FgHiRed
default:
return color.FgRed
}
}