幽灵资源网 Design By www.bzswh.com
详细请看 Github:https://github.com/shanhuijie/GoWatch/tree/master/fiveinarow
five in a row (五子棋成功预测)
从横、纵、 左斜升、 左斜降 四个角度判断
const(
matrix = 50*50
point = 3
)
type Coordinat struct{
x int
y int
}
type Allinat struct{
key []Coordinat
}
func InArray(need Coordinat, needArr []Coordinat) bool {
for _,v := range needArr{
if need == v{
return true
}
}
return false
}
func inverted(tmp []int) bool { //倒序检查
var i int
for k := len(tmp)-1; k>=0;k--{
if k == 0{ //最后一个下标说明无法对比
return false
}
if tmp[k]-1 == tmp[k]{ //说明值是连续数字
i++
if i == point{ //如果达到连续数就返回
return true
}
}else{
return false
}
}
return false
}
func postive(tmp []int) bool { //正序检查
var i int
for ck, cv := range tmp {
if ck == len(tmp)-1{ //最后一个下标说明无法对比
return false
}
if cv+1 == tmp[ck+1] { //说明值是连续数字
i++
if i == point{ //如果达到连续数就返回
return true
}
}else{
return false
}
}
return false
}
func Slope(inat *Allinat,coor Coordinat) bool {
var (
Xmax,Xmin int = coor.x+4,coor.x-4
Ymax,Ymin int = coor.y+4,coor.y-4
j,p int
lrise,lfall Coordinat
//tmp []int
)
if Xmin < 0 {
Xmin = 0
}
if Ymin < 0 {
Ymin = 0
}
for i:=Xmin; i<=Xmax; i++{
Xmin = Xmin+1
Ymin = Ymin+1
lrise.x = Xmin
lrise.y = Ymin
if InArray(lrise,inat.key) {
j++
//fmt.Println(lrise,j)
if j == point{
return true
}
}
if Ymin == Ymax {
break
}
}
for ii := Xmax; ii>=Xmin; ii--{
Xmax = Xmax-1
Ymin = Ymin+1
lfall.x = Xmax
lfall.y = Ymin
if InArray(lfall,inat.key) {
p++
//fmt.Println(lfall,p)
if p == point{
return true
}
}
if Ymin == Ymax {
return false
}
}
return false
}
func lengthways(inat *Allinat,coor Coordinat) bool {
var (
max,min int = coor.x+4,coor.x-4
tmp []int
)
if min < 0 {
min = 0
}
for _,c := range inat.key{
if (max >= c.x && c.y == coor.y) || (min >= c.x && c.y == coor.y){
tmp = append(tmp,c.x)
}
}
sort.Ints(tmp)
if (inverted(tmp) == true) || (postive(tmp) == true) {
return true
}
return false
}
func crosswise(inat *Allinat,coor Coordinat) bool {
var (
max,min int = coor.y+4,coor.y-4
tmp []int
)
for _,c := range inat.key{
if (max >= c.y && c.x == coor.x) || (min >= c.y && c.x == coor.x){
tmp = append(tmp,c.y)
}
}
sort.Ints(tmp)
if (inverted(tmp) == true) || (postive(tmp) == true) {
return true
}
return false
}
func IsFive(inat *Allinat,coor Coordinat) bool {
ok := crosswise(inat,coor)
ok2 := lengthways(inat,coor)
ok3 := Slope(inat,coor)
//slope(inat)
if ok == true || ok2 == true || ok3 == true{
return true
}
return false
}
func (inat *Allinat)AddCoordinat(coor Coordinat){
for _,coslice := range inat.key{
if coslice == coor {
return
}
}
c := IsFive(inat,coor)
fmt.Println(c,"*****",coor)
if c == false{ //not finish five
inat.key = append(inat.key,coor)
fmt.Println("没有连成")
return
}
fmt.Println("连成point颗")
return
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
幽灵资源网 Design By www.bzswh.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
幽灵资源网 Design By www.bzswh.com
暂无评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。