关于斗地主算法讨论(一)
首先 我们 需要 判断 手中拿到的牌型, 比如你有多少个9,多少个10 这时候 我们就需要对 手中的牌进行聚合假设 A, B ,C ,D 分别代表四个花色,Q66代表 小王,K99 代表大王
你现在拿到的牌型如下 "B1", "C4", "A1", "B7", "C8", "C7", "C10", "K99", "B13", "D13", "A2", "B6", "D8", "A3", "D12", "D10"
go语言逻辑处理如下:
package main
import (
"fmt"
"strconv"
"strings"
)
func Rm_duplicateString(list []string) []string {
var x []string = []string{}
for _, i := range list {
if len(x) == 0 {
x = append(x, i)
} else {
for k, v := range x {
if i == v {
break
}
if k == len(x)-1 {
x = append(x, i)
}
}
}
}
return x
}
func Rm_duplicateInt(list []int) []int {
var x []int = []int{}
for _, i := range list {
if len(x) == 0 {
x = append(x, i)
} else {
for k, v := range x {
if i == v {
break
}
if k == len(x)-1 {
x = append(x, i)
}
}
}
}
return x
}
func aggregationlist(e []string) (aggregation []mapint) {
var cardstring []string = []string{}
var cardintsort []int = []int{}
var cardint []int = []int{}
for _, v := range e {
s := strings.Split(v, "")
if len(s) == 1 {
cardstring = append(cardstring, s)
} else if len(s) > 1 {
cardstring = append(cardstring, strings.Join(s, ""))
}
}
for _, k := range cardstring {
l, _ := strconv.Atoi(k)
cardint = append(cardint, l)
}
cardintsort = Rm_duplicateInt(cardint)
for _, o := range cardintsort {
count := 0
for _, q := range cardint {
if q == o {
count = count + 1
}
}
//k := []int{o, count}
k := make(mapint)
k = count
aggregation = append(aggregation, k)
}
return aggregation
}
func main() {
a := []string{"B1", "C4", "A1", "B7", "C8", "C7", "C10", "K99", "B13", "D13", "A2", "B6", "D8", "A3", "D12", "D10"}
fmt.Println(aggregationlist(a))
}
*************************************************************************************************
GoSublime r17.11.14-1 9o: type `help` for help and command documentation
[ `go run 10.go` | done: 8.832s ]
map map map map map map map map map map]
[ F:/mygo/ ] # 斗地主是不是还需要积分板?
页:
[1]