Refactor code, added new checkXu test cases(9 latterns)
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package pattern
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
type PatternDivision struct {
|
||||
Ke int
|
||||
Shun int
|
||||
Dui int
|
||||
Gang int
|
||||
}
|
||||
type Fan struct {
|
||||
Id int
|
||||
Name string
|
||||
Pattern PatternDivision
|
||||
ExcludeIds []int
|
||||
Value int
|
||||
}
|
||||
|
||||
func FansEncoder(fans []Fan) ([]byte, error) {
|
||||
return json.MarshalIndent(fans, "", " ")
|
||||
}
|
||||
|
||||
func FansDecoder(bytedata []byte) ([]Fan, error) {
|
||||
var fans []Fan
|
||||
err := json.Unmarshal(bytedata, &fans)
|
||||
return fans, err
|
||||
}
|
||||
|
||||
func FansToFile(fans []Fan, filepath string) error {
|
||||
jsonBytes, err := FansEncoder(fans)
|
||||
if err != nil {
|
||||
log.Fatalf("Can't encode fan xing: %v", err)
|
||||
return err
|
||||
}
|
||||
err = os.WriteFile(filepath, jsonBytes, 0644)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to write fan xing into a file(%s): %v", filepath, err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func DivisionHelperOnNumbers(tiles [9]int) {
|
||||
|
||||
}
|
||||
func HandPatternDivide() {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user