impl some hands
This commit is contained in:
@@ -1,5 +1,41 @@
|
||||
package operation
|
||||
|
||||
import "local/sandbox/cards/src/entity"
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"local/sandbox/cards/src/entity"
|
||||
)
|
||||
|
||||
type Int func(*entity.Game, interface{}) int
|
||||
|
||||
var intStringified = map[string]Int{
|
||||
"royalFlush": royalFlush,
|
||||
"straightFlush": straightFlush,
|
||||
"fourOfAKind": fourOfAKind,
|
||||
"fullHouse": fullHouse,
|
||||
"flush": flush,
|
||||
"straight": straight,
|
||||
"threeOfAKind": threeOfAKind,
|
||||
"twoPair": twoPair,
|
||||
"pair": pair,
|
||||
"highCard": highCard,
|
||||
}
|
||||
|
||||
func (foo *Int) UnmarshalJSON(b []byte) error {
|
||||
var s string
|
||||
if err := json.Unmarshal(b, &s); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return foo.FromString(s)
|
||||
}
|
||||
|
||||
func (foo *Int) FromString(s string) error {
|
||||
for k, v := range intStringified {
|
||||
if k == s {
|
||||
*foo = v
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return errors.New("unknown int method " + s)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user