[收藏]连连看自动寻道算法
连连看自动寻道算法
onClipEvent (load) {
_root.yb._alpha = 0;
var zt = new Array();
var jilu1 = new Array();
var jilu2 = new Array();
var jilu3 = new Array();
var jilu4 = new Array();
b = 0;
val = 1;
for (i=0; i<12; i++) {
for (j=0; j<12; j++) {
a = attachMovie("ttt", "ttt"+val, val);
a._x = j*32-50;
a._y = i*32-80;
a.onPress = pres;
a.onRollOut = rele;
a.n = val;
zt[val] = 1;
//初始为第一帧;
val++;
}
}
for (i=1; i<=12; i++) {
tellTarget ("ttt"+i) {
gotoAndStop(9);
}
zt[i] = 9;
}
for (i=133; i<=144; i++) {
tellTarget ("ttt"+i) {
gotoAndStop(9);
}
zt[i] = 9;
}
for (i=1; i<=133; i=i+12) {
tellTarget ("ttt"+i) {
gotoAndStop(9);
}
zt[i] = 9;
}
for (i=12; i<=144; i=i+12) {
tellTarget ("ttt"+i) {
gotoAndStop(9);
}
zt[i] = 9;
}
for (i=1; i<=137; i++) {
if (zt[i] != 9) {
ra = random(10)+1;
zt[i] = ra;
selectframe(ra);
}
}
//列出矩阵;
function pres() {
t = this.n;
if (b != 0) {
_root.yb._alpha = 0;
//c2=this._currentframe;
first = b;
second = this.n;
ss=zt[second];
if(bb==ss){
//记录判断点类型;
line1_x = getProperty("ttt"+first, _x);
line1_y = getProperty("ttt"+first, _y);
line2_x = getProperty("ttt"+second, _x);
line2_y = getProperty("ttt"+second, _y);
if (line1_x == line2_x) {
line4 = "同一列";
_root.control.panduan_lie();
} else if (line1_y == line2_y) {
_root.control.panduan_hang();
line4 = "同一行";
} else {
_root.control.panduan_cuowei();
line4 = "错开位";
}
}
//判断两个点是否在同一列上;
//c=this._currentframe;
b = 0;
} else {
_root.yb._alpha = 50;
_root.yb._x = this._x+546;
_root.yb._y = this._y+5;
b = this.n;
bb=zt[b];
//this.gotoandstop(2);
c = this._currentframe;
}
}
function panduan_lie() {
g = 1000;
br = 0;
//两点在同一列上的处理函数;
if (math.abs(first-second) == 12) {
_root.control.ok();
} else {
//1
line1 = Math.floor(first/12);
line2 = Math.floor(second/12);
for (i=1; i<=12; i++) {
jilu1[i] = line1*12+i;
jilu2[i] = line2*12+i;
}
for (i=1; i<=12; i++) {
//2
if (jilu1[i] != first) {
if (zt[jilu1[i]] == 9 and zt[jilu2[i]] == 9) {
l = jiance_lie1(jilu1[i], jilu2[i]);
if (l>0) {
if (l<g) {
g = l;
g1 = jilu1[i];
g2 = jilu2[i];
}
//_root.control.ok();
}
}
} else {
l = jiance_lie2(jilu1[i], jilu2[i]);
if (l == 100) {
_root.control.shuxian0(jilu1[i], jilu2[i]);
br = 1;
break;
}
}
}
if (g != 1000 and br == 0) {
guaixian2_lie(g1, g2);
}
//2
}
//1
}
function panduan_hang() {
g = 1000;
br = 0;
//两点在同一行上的处理函数;
if (math.abs(first-second) == 1) {
_root.control.ok();
} else {
line1 = first%12;
line2 = second%12;
for (i=1; i<=12; i++) {
jilu1[i] = line1+(i-1)*12;
jilu2[i] = line2+(i-1)*12;
}
for (i=1; i<=12; i++) {
if (jilu1[i] != first) {
if (zt[jilu1[i]] == 9 and zt[jilu2[i]] == 9) {
f = jiance_hen1(jilu1[i], jilu2[i]);
if (f>0) {
if (f<g) {
g = f;
g1 = jilu1[i];
g2 = jilu2[i];
}
}
}
} else {
f = jiance_hen2(jilu1[i], jilu2[i]);
if (f == 100) {
_root.control.henxiang0(jilu1[i], jilu2[i]);
br = 1;
break;
}
}
}
}
if (g != 1000 and br == 0) {
guaixian2_hen(g1, g2);
}
}
function jiance_hen1(x, y) {
//检测两点是否为通路的函数;
p1 = 0;
p2 = 0;
p3 = 0;
co = 0;
if (x>y) {
//1
dis = x-y-1;
for (z=1; z<=dis; z++) {
q = x-z;
if (zt[q] == 9) {
p1++;
}
}
} else {
dis = y-x-1;
for (z=1; z<=dis; z++) {
q = y-z;
if (zt[q] == 9) {
p1++;
}
}
}
//1
if (p1 == dis) {
p1 = 100;
}
//横向检测;<-
if (first>x) {
dis = (first-x)/12-1;
if (dis == 0) {
p2 = 100;
} else {
for (z=1; z<=dis; z++) {
q = first-z*12;
if (zt[q] == 9) {
p2++;
}
}
}
} else {
dis = (x-first)/12-1;
if (dis == 0) {
p2 = 100;
} else {
for (z=1; z<=dis; z++) {
q = x-z*12;
if (zt[q] == 9) {
p2++;
}
}
}
}
if (p2 == dis) {
p2 = 100;
}
if (second>y) {
dis = (second-y)/12-1;
if (dis == 0) {
p3 = 100;
} else {
for (z=1; z<=dis; z++) {
q = second-z*12;
if (zt[q] == 9) {
p3++;
}
}
}
} else {
dis = (y-second)/12-1;
if (dis == 0) {
p3 = 100;
} else {
for (z=1; z<=dis; z++) {
q = y-z*12;
if (zt[q] == 9) {
p3++;
}
}
}
}
if (p3 == dis) {
p3 = 100;
}
p = p1+p2+p3;
if (p == 300) {
co = math.abs(x-y)+math.abs(second-y)/12+math.abs(first-x)/12;
}
return (co);
}
function jiance_hen2(x, y) {
p4 = 0;
if (x>y) {
dis = x-y-1;
for (z=1; z<=dis; z++) {
q = x-z;
if (zt[q] == 9) {
p4++;
}
}
} else {
dis = y-x-1;
for (z=1; z<=dis; z++) {
q = y-z;
if (zt[q] == 9) {
p4++;
}
}
}
if (p4 == dis) {
p4 = 100;
}
return (p4);
}
function jiance_lie1(x, y) {
p1 = 0;
p2 = 0;
p3 = 0;
co = 0;
if (x>y) {
dis = (x-y)/12-1;
for (z=1; z<=dis; z++) {
q = x-z*12;
if (zt[q] == 9) {
p1++;
}
}
} else {
dis = (y-x)/12-1;
for (z=1; z<=dis; z++) {
q = y-z*12;
if (zt[q] == 9) {
p1++;
}
}
}
if (p1 == dis) {
p1 = 100;
}
//纵向检测《---
if (first>x) {
dis = first-x-1;
for (z=1; z<=dis; z++) {
q = first-z;
if (zt[q] == 9) {
p2++;
}
}
} else {
dis = x-first-1;
for (z=1; z<=dis; z++) {
q = x-z;
if (zt[q] == 9) {
p2++;
}
}
}
if (p2 == dis) {
p2 = 100;
}
if (second>y) {
dis = second-y-1;
for (z=1; z<=dis; z++) {
q = second-z;
if (zt[q] == 9) {
p3++;
}
}
} else {
dis = y-second-1;
for (z=1; z<=dis; z++) {
q = y-z;
if (zt[q] == 9) {
p3++;
}
}
}
if (p3 == dis) {
p3 = 100;
}
p = p1+p2+p3;
if (p == 300) {
co = math.abs(x-y)/12+math.abs(second-y)+math.abs(first-x);
}
return (co);
}
function jiance_lie2(x, y) {
p4 = 0;
if (x>y) {
dis = (x-y)/12-1;
for (z=1; z<=dis; z++) {
q = x-z*12;
if (zt[q] == 9) {
p4++;
}
}
} else {
dis = (y-x)/12-1;
for (z=1; z<=dis; z++) {
q = y-z*12;
if (zt[q] == 9) {
p4++;
}
}
}
if (p4 == dis) {
p4 = 100;
}
return (p4);
}
function panduan_cuowei() {
g = 1000;
gg = 1000;
br = 0;
j = 0;
k = 0;
line1 = first%12;
line2 = second%12;
line3 = math.floor(first/12);
line4 = math.floor(second/12);
for (i=1; i<=12; i++) {
jilu1[i] = line1+(i-1)*12;
jilu2[i] = line2+(i-1)*12;
//HANG
jilu3[i] = line3*12+i;
jilu4[i] = line4*12+i;
//LIE
}
for (i=1; i<=12; i++) {
if (jilu1[i] == first) {
if (zt[jilu2[i]] == 9) {
w = jiance_cuowei01(jilu2[i]);
if (w == 200) {
guaixian1_hen1(jilu2[i]);
_root.control.ok();
br = 1;
break;
}
}
} else if (jilu2[i] == second) {
if (zt[jilu1[i]] == 9) {
w = jiance_cuowei02(jilu1[i]);
if (w == 200) {
guaixian1_hen2(jilu1[i]);
_root.control.ok();
br = 1;
break;
}
}
}
if (zt[jilu1[i]] == 9 and zt[jilu2[i]] == 9) {
j = jiance_hen1(jilu1[i], jilu2[i]);
}
if (j>0) {
if (j<g) {
g = j;
g1 = jilu1[i];
g2 = jilu2[i];
}
//_root.control.ok();
} else {
if (zt[jilu3[i]] == 9 and zt[jilu4[i]] == 9) {
k = jiance_lie1(jilu3[i], jilu4[i]);
}
if (k>0) {
if (k<gg) {
gg = k;
g3 = jilu3[i];
g4 = jilu4[i];
}
}
}
}
if (br == 0) {
if (g != 1000) {
guaixian2_hen(g1, g2);
br = 1;
} else if (gg != 1000) {
guaixian2_lie(g3, g4);
}
}
}
function jiance_cuowei01(x) {
//错位状态1;
p1 = 0;
p2 = 0;
dis = math.abs(x-first)-1;
if (dis == 0) {
p1 = 100;
} else {
if (x>first) {
for (z=1; z<=dis; z++) {
q = x-z;
if (zt[q] == 9) {
p1++;
}
}
} else {
for (z=1; z<=dis; z++) {
q = first-z;
if (zt[q] == 9) {
p1++;
}
}
}
if (p1 == dis) {
p1 = 100;
}
}
dis = math.abs((second-x))/12-1;
if (dis == 0) {
p2 == 100;
} else {
if (second>x) {
for (z=1; z<=dis; z++) {
q = second-z*12;
if (zt[q] == 9) {
p2++;
}
}
} else {
dis = math.abs(dis);
for (z=1; z<=dis; z++) {
q = x-z*12;
if (zt[q] == 9) {
p2++;
}
}
}
}
if (p2 == dis) {
p2 = 100;
}
return (p1+p2);
}
function jiance_cuowei02(x) {
//错位状态2;
p1 = 0;
p2 = 0;
dis = math.abs(x-second)-1;
if (dis == 0) {
p1 = 100;
} else {
if (x>second) {
for (z=1; z<=dis; z++) {
q = x-z;
if (zt[q] == 9) {
p1++;
}
}
} else {
for (z=1; z<=dis; z++) {
q = second-z;
if (zt[q] == 9) {
p1++;
}
}
}
if (p1 == dis) {
p1 = 100;
}
}
dis = math.abs((first-x))/12-1;
if (dis == 0) {
p2 == 100;
} else {
if (first>x) {
for (z=1; z<=dis; z++) {
q = first-z*12;
if (zt[q] == 9) {
p2++;
}
}
} else {
dis = math.abs(dis);
for (z=1; z<=dis; z++) {
q = x-z*12;
if (zt[q] == 9) {
p2++;
}
}
}
}
if (p2 == dis) {
p2 = 100;
}
return (p1+p2);
}
function henxiang0(x, y) {
//横线0拐点画线函数;
//tellTarget ("ttt"+y) {
// gotoAndPlay(10);
//}
if (x>y) {
dis = x-y-1;
for (z=1; z<=dis; z++) {
q = x-z;
tellTarget ("ttt"+q) {
gotoAndPlay(10);
}
}
} else {
dis = y-x-1;
for (z=1; z<=dis; z++) {
q = y-z;
tellTarget ("ttt"+q) {
gotoAndPlay(10);
}
}
}
_root.control.ok();
}
function shuxian0(x, y) {
//竖线0拐点画线函数;
if (x>y) {
dis = (x-y)/12-1;
for (z=1; z<=dis; z++) {
q = x-z*12;
tellTarget ("ttt"+q) {
gotoAndPlay(13);
}
}
} else {
dis = (y-x)/12-1;
for (z=1; z<=dis; z++) {
q = y-z*12;
tellTarget ("ttt"+q) {
gotoAndPlay(13);
}
}
}
_root.control.ok();
}
function guaixian1_hen1(x) {
if (x>first and x<second) {
tellTarget ("ttt"+x) {
gotoAndPlay(19);
}
} else if (x>first and x>second) {
tellTarget ("ttt"+x) {
gotoAndPlay(25);
}
} else if (x<first and x<second) {
tellTarget ("ttt"+x) {
gotoAndPlay(16);
}
} else {
tellTarget ("ttt"+x) {
gotoAndPlay(22);
}
}
dis = math.abs(x-first)-1;
if (dis != 0) {
if (x>first) {
for (z=1; z<=dis; z++) {
q = x-z;
tellTarget ("ttt"+q) {
gotoAndPlay(10);
}
}
} else {
for (z=1; z<=dis; z++) {
q = first-z;
tellTarget ("ttt"+q) {
gotoAndPlay(10);
}
}
}
}
dis = math.abs((second-x))/12-1;
if (dis != 0) {
if (second>x) {
for (z=1; z<=dis; z++) {
q = second-z*12;
tellTarget ("ttt"+q) {
gotoAndPlay(13);
}
}
} else {
dis = math.abs(dis);
for (z=1; z<=dis; z++) {
q = x-z*12;
tellTarget ("ttt"+q) {
gotoAndPlay(13);
}
}
}
}
}
function guaixian1_hen2(x) {
if (x>first and x<second) {
tellTarget ("ttt"+x) {
gotoAndPlay(22);
}
} else if (x>first and x>second) {
tellTarget ("ttt"+x) {
gotoAndPlay(25);
}
} else if (x<first and x<second) {
tellTarget ("ttt"+x) {
gotoAndPlay(16);
}
} else {
tellTarget ("ttt"+x) {
gotoAndPlay(19);
}
}
dis = math.abs(x-second)-1;
if (dis != 0) {
if (x>second) {
for (z=1; z<=dis; z++) {
q = x-z;
tellTarget ("ttt"+q) {
gotoAndPlay(10);
}
}
} else {
for (z=1; z<=dis; z++) {
q = second-z;
tellTarget ("ttt"+q) {
gotoAndPlay(10);
}
}
}
}
dis = math.abs((first-x))/12-1;
if (dis != 0) {
if (first>x) {
for (z=1; z<=dis; z++) {
q = first-z*12;
tellTarget ("ttt"+q) {
gotoAndPlay(13);
}
}
} else {
dis = math.abs(dis);
for (z=1; z<=dis; z++) {
q = x-z*12;
tellTarget ("ttt"+q) {
gotoAndPlay(13);
}
}
}
}
}
function guaixian2_hen(x, y) {
if (x<first and y<second and x<y) {
tellTarget ("ttt"+x) {
gotoAndPlay(16);
}
tellTarget ("ttt"+y) {
gotoAndPlay(19);
}
} else if (x<first and y<second and x>y) {
tellTarget ("ttt"+x) {
gotoAndPlay(19);
}
tellTarget ("ttt"+y) {
gotoAndPlay(16);
}
} else if (x>first and y>second and x<y) {
tellTarget ("ttt"+x) {
gotoAndPlay(22);
}
tellTarget ("ttt"+y) {
gotoAndPlay(25);
}
} else if (x>first and y>second and x>y) {
tellTarget ("ttt"+x) {
gotoAndPlay(25);
}
tellTarget ("ttt"+y) {
gotoAndPlay(22);
}
} else if (x>first and y<second and x<y) {
tellTarget ("ttt"+x) {
gotoAndPlay(22);
}
tellTarget ("ttt"+y) {
gotoAndPlay(19);
}
} else if (x>first and y<second and x>y) {
tellTarget ("ttt"+x) {
gotoAndPlay(25);
}
tellTarget ("ttt"+y) {
gotoAndPlay(16);
}
} else if (x<first and y>second and x<y) {
tellTarget ("ttt"+x) {
gotoAndPlay(16);
}
tellTarget ("ttt"+y) {
gotoAndPlay(25);
}
} else {
tellTarget ("ttt"+x) {
gotoAndPlay(19);
}
tellTarget ("ttt"+y) {
gotoAndPlay(22);
}
}
if (x>y) {
dis = x-y-1;
for (z=1; z<=dis; z++) {
q = x-z;
tellTarget ("ttt"+q) {
gotoAndPlay(10);
}
}
} else {
dis = y-x-1;
for (z=1; z<=dis; z++) {
q = y-z;
tellTarget ("ttt"+q) {
gotoAndPlay(10);
}
}
}
if (first>x) {
dis = (first-x)/12-1;
if (dis != 0) {
for (z=1; z<=dis; z++) {
q = first-z*12;
tellTarget ("ttt"+q) {
gotoAndPlay(13);
}
}
}
} else {
dis = (x-first)/12-1;
if (dis != 0) {
for (z=1; z<=dis; z++) {
q = x-z*12;
tellTarget ("ttt"+q) {
gotoAndPlay(13);
}
}
}
}
if (second>y) {
dis = (second-y)/12-1;
if (dis != 0) {
for (z=1; z<=dis; z++) {
q = second-z*12;
tellTarget ("ttt"+q) {
gotoAndPlay(13);
}
}
}
} else {
dis = (y-second)/12-1;
if (dis != 0) {
for (z=1; z<=dis; z++) {
q = y-z*12;
tellTarget ("ttt"+q) {
gotoAndPlay(13);
}
}
}
}
_root.control.ok();
}
function guaixian2_lie(x, y) {
if (x<first and y<second and x<y) {
tellTarget ("ttt"+x) {
gotoAndPlay(16);
}
tellTarget ("ttt"+y) {
gotoAndPlay(22);
}
} else if (x<first and y<second and x>y) {
tellTarget ("ttt"+x) {
gotoAndPlay(22);
}
tellTarget ("ttt"+y) {
gotoAndPlay(16);
}
} else if (x>first and y>second and x<y) {
tellTarget ("ttt"+x) {
gotoAndPlay(19);
}
tellTarget ("ttt"+y) {
gotoAndPlay(25);
}
} else if (x>first and y>second and x>y) {
tellTarget ("ttt"+x) {
gotoAndPlay(25);
}
tellTarget ("ttt"+y) {
gotoAndPlay(19);
}
} else if (x>first and y<second and x>y) {
tellTarget ("ttt"+x) {
gotoAndPlay(25);
}
tellTarget ("ttt"+y) {
gotoAndPlay(16);
}
} else if (x>first and y<second and x<y) {
tellTarget ("ttt"+x) {
gotoAndPlay(19);
}
tellTarget ("ttt"+y) {
gotoAndPlay(22);
}
} else if (x<first and y>second and x<y) {
tellTarget ("ttt"+x) {
gotoAndPlay(16);
}
tellTarget ("ttt"+y) {
gotoAndPlay(25);
}
} else {
tellTarget ("ttt"+x) {
gotoAndPlay(22);
}
tellTarget ("ttt"+y) {
gotoAndPlay(19);
}
}
if (x>y) {
dis = (x-y)/12-1;
for (z=1; z<=dis; z++) {
q = x-z*12;
tellTarget ("ttt"+q) {
gotoAndPlay(13);
}
}
} else {
dis = (y-x)/12-1;
for (z=1; z<=dis; z++) {
q = y-z*12;
tellTarget ("ttt"+q) {
gotoAndPlay(13);
}
}
}
if (first>x) {
dis = first-x-1;
for (z=1; z<=dis; z++) {
q = first-z;
tellTarget ("ttt"+q) {
gotoAndPlay(10);
}
}
} else {
dis = x-first-1;
for (z=1; z<=dis; z++) {
q = x-z;
tellTarget ("ttt"+q) {
gotoAndPlay(10);
}
}
}
if (second>y) {
dis = second-y-1;
for (z=1; z<=dis; z++) {
q = second-z;
tellTarget ("ttt"+q) {
gotoAndPlay(10);
}
}
} else {
dis = y-second-1;
for (z=1; z<=dis; z++) {
q = y-z;
tellTarget ("ttt"+q) {
gotoAndPlay(10);
}
}
}
_root.control.ok();
}
function selectframe(number) {
switch (number) {
case 1 :
tellTarget ("ttt"+i) {
gotoAndStop(1);
}
break;
case 2 :
tellTarget ("ttt"+i) {
gotoAndStop(2);
}
break;
case 3 :
tellTarget ("ttt"+i) {
gotoAndStop(3);
}
break;
case 4 :
tellTarget ("ttt"+i) {
gotoAndStop(4);
}
break;
case 5 :
tellTarget ("ttt"+i) {
gotoAndStop(5);
}
break;
case 6 :
tellTarget ("ttt"+i) {
gotoAndStop(6);
}
break;
case 7 :
tellTarget ("ttt"+i) {
gotoAndStop(7);
}
break;
case 8 :
tellTarget ("ttt"+i) {
gotoAndStop(8);
}
break;
case 9 :
tellTarget ("ttt"+i) {
gotoAndStop(28);
}
break;
case 10 :
tellTarget ("ttt"+i) {
gotoAndStop(29);
}
break;
}
}
function ok() {
//可消除的处理函数;
tellTarget ("ttt"+first) {
gotoAndStop(9);
}
zt[first] = 9;
tellTarget ("ttt"+second) {
gotoAndStop(9);
}
zt[second] = 9;
c = zt[second];
}
}
//julu数组为待检测点,ZT数组为各点状态;
//9:消除;10:横线;13:竖线;16:「;19:7;22:L;25:」;
基本思路就是分两种情况考虑寻道算法,
为每一个小牌取个名字,(我用程序生成,并用数组记录下每个牌的状态,是无牌状态还是有牌状态)
一是在同行同列上
只要判断从起点到终点的所有牌的状态是否都为无牌状态,也就是起点牌到终点牌是否是连通的
二是只有一个拐点
先检测它们的所在行列所在的交汇点,判断他们的交绘点是否为无牌状态,如果是则继续判断从该交绘点分别到起点和终点间是否为连通,这时的方法同第一种方法一样.
三是有两个拐点
同样先判断这两个点所在行和列的两个交汇点,先判断两个交汇点间是否为空,若是则继续判断两个交汇点到起点终点是否为连通,这两中判断也可以分解为是第一种状态来进行判断
onClipEvent (load) {
_root.yb._alpha = 0;
var zt = new Array();
var jilu1 = new Array();
var jilu2 = new Array();
var jilu3 = new Array();
var jilu4 = new Array();
b = 0;
val = 1;
for (i=0; i<12; i++) {
for (j=0; j<12; j++) {
a = attachMovie("ttt", "ttt"+val, val);
a._x = j*32-50;
a._y = i*32-80;
a.onPress = pres;
a.onRollOut = rele;
a.n = val;
zt[val] = 1;
//初始为第一帧;
val++;
}
}
for (i=1; i<=12; i++) {
tellTarget ("ttt"+i) {
gotoAndStop(9);
}
zt[i] = 9;
}
for (i=133; i<=144; i++) {
tellTarget ("ttt"+i) {
gotoAndStop(9);
}
zt[i] = 9;
}
for (i=1; i<=133; i=i+12) {
tellTarget ("ttt"+i) {
gotoAndStop(9);
}
zt[i] = 9;
}
for (i=12; i<=144; i=i+12) {
tellTarget ("ttt"+i) {
gotoAndStop(9);
}
zt[i] = 9;
}
for (i=1; i<=137; i++) {
if (zt[i] != 9) {
ra = random(10)+1;
zt[i] = ra;
selectframe(ra);
}
}
//列出矩阵;
function pres() {
t = this.n;
if (b != 0) {
_root.yb._alpha = 0;
//c2=this._currentframe;
first = b;
second = this.n;
ss=zt[second];
if(bb==ss){
//记录判断点类型;
line1_x = getProperty("ttt"+first, _x);
line1_y = getProperty("ttt"+first, _y);
line2_x = getProperty("ttt"+second, _x);
line2_y = getProperty("ttt"+second, _y);
if (line1_x == line2_x) {
line4 = "同一列";
_root.control.panduan_lie();
} else if (line1_y == line2_y) {
_root.control.panduan_hang();
line4 = "同一行";
} else {
_root.control.panduan_cuowei();
line4 = "错开位";
}
}
//判断两个点是否在同一列上;
//c=this._currentframe;
b = 0;
} else {
_root.yb._alpha = 50;
_root.yb._x = this._x+546;
_root.yb._y = this._y+5;
b = this.n;
bb=zt[b];
//this.gotoandstop(2);
c = this._currentframe;
}
}
function panduan_lie() {
g = 1000;
br = 0;
//两点在同一列上的处理函数;
if (math.abs(first-second) == 12) {
_root.control.ok();
} else {
//1
line1 = Math.floor(first/12);
line2 = Math.floor(second/12);
for (i=1; i<=12; i++) {
jilu1[i] = line1*12+i;
jilu2[i] = line2*12+i;
}
for (i=1; i<=12; i++) {
//2
if (jilu1[i] != first) {
if (zt[jilu1[i]] == 9 and zt[jilu2[i]] == 9) {
l = jiance_lie1(jilu1[i], jilu2[i]);
if (l>0) {
if (l<g) {
g = l;
g1 = jilu1[i];
g2 = jilu2[i];
}
//_root.control.ok();
}
}
} else {
l = jiance_lie2(jilu1[i], jilu2[i]);
if (l == 100) {
_root.control.shuxian0(jilu1[i], jilu2[i]);
br = 1;
break;
}
}
}
if (g != 1000 and br == 0) {
guaixian2_lie(g1, g2);
}
//2
}
//1
}
function panduan_hang() {
g = 1000;
br = 0;
//两点在同一行上的处理函数;
if (math.abs(first-second) == 1) {
_root.control.ok();
} else {
line1 = first%12;
line2 = second%12;
for (i=1; i<=12; i++) {
jilu1[i] = line1+(i-1)*12;
jilu2[i] = line2+(i-1)*12;
}
for (i=1; i<=12; i++) {
if (jilu1[i] != first) {
if (zt[jilu1[i]] == 9 and zt[jilu2[i]] == 9) {
f = jiance_hen1(jilu1[i], jilu2[i]);
if (f>0) {
if (f<g) {
g = f;
g1 = jilu1[i];
g2 = jilu2[i];
}
}
}
} else {
f = jiance_hen2(jilu1[i], jilu2[i]);
if (f == 100) {
_root.control.henxiang0(jilu1[i], jilu2[i]);
br = 1;
break;
}
}
}
}
if (g != 1000 and br == 0) {
guaixian2_hen(g1, g2);
}
}
function jiance_hen1(x, y) {
//检测两点是否为通路的函数;
p1 = 0;
p2 = 0;
p3 = 0;
co = 0;
if (x>y) {
//1
dis = x-y-1;
for (z=1; z<=dis; z++) {
q = x-z;
if (zt[q] == 9) {
p1++;
}
}
} else {
dis = y-x-1;
for (z=1; z<=dis; z++) {
q = y-z;
if (zt[q] == 9) {
p1++;
}
}
}
//1
if (p1 == dis) {
p1 = 100;
}
//横向检测;<-
if (first>x) {
dis = (first-x)/12-1;
if (dis == 0) {
p2 = 100;
} else {
for (z=1; z<=dis; z++) {
q = first-z*12;
if (zt[q] == 9) {
p2++;
}
}
}
} else {
dis = (x-first)/12-1;
if (dis == 0) {
p2 = 100;
} else {
for (z=1; z<=dis; z++) {
q = x-z*12;
if (zt[q] == 9) {
p2++;
}
}
}
}
if (p2 == dis) {
p2 = 100;
}
if (second>y) {
dis = (second-y)/12-1;
if (dis == 0) {
p3 = 100;
} else {
for (z=1; z<=dis; z++) {
q = second-z*12;
if (zt[q] == 9) {
p3++;
}
}
}
} else {
dis = (y-second)/12-1;
if (dis == 0) {
p3 = 100;
} else {
for (z=1; z<=dis; z++) {
q = y-z*12;
if (zt[q] == 9) {
p3++;
}
}
}
}
if (p3 == dis) {
p3 = 100;
}
p = p1+p2+p3;
if (p == 300) {
co = math.abs(x-y)+math.abs(second-y)/12+math.abs(first-x)/12;
}
return (co);
}
function jiance_hen2(x, y) {
p4 = 0;
if (x>y) {
dis = x-y-1;
for (z=1; z<=dis; z++) {
q = x-z;
if (zt[q] == 9) {
p4++;
}
}
} else {
dis = y-x-1;
for (z=1; z<=dis; z++) {
q = y-z;
if (zt[q] == 9) {
p4++;
}
}
}
if (p4 == dis) {
p4 = 100;
}
return (p4);
}
function jiance_lie1(x, y) {
p1 = 0;
p2 = 0;
p3 = 0;
co = 0;
if (x>y) {
dis = (x-y)/12-1;
for (z=1; z<=dis; z++) {
q = x-z*12;
if (zt[q] == 9) {
p1++;
}
}
} else {
dis = (y-x)/12-1;
for (z=1; z<=dis; z++) {
q = y-z*12;
if (zt[q] == 9) {
p1++;
}
}
}
if (p1 == dis) {
p1 = 100;
}
//纵向检测《---
if (first>x) {
dis = first-x-1;
for (z=1; z<=dis; z++) {
q = first-z;
if (zt[q] == 9) {
p2++;
}
}
} else {
dis = x-first-1;
for (z=1; z<=dis; z++) {
q = x-z;
if (zt[q] == 9) {
p2++;
}
}
}
if (p2 == dis) {
p2 = 100;
}
if (second>y) {
dis = second-y-1;
for (z=1; z<=dis; z++) {
q = second-z;
if (zt[q] == 9) {
p3++;
}
}
} else {
dis = y-second-1;
for (z=1; z<=dis; z++) {
q = y-z;
if (zt[q] == 9) {
p3++;
}
}
}
if (p3 == dis) {
p3 = 100;
}
p = p1+p2+p3;
if (p == 300) {
co = math.abs(x-y)/12+math.abs(second-y)+math.abs(first-x);
}
return (co);
}
function jiance_lie2(x, y) {
p4 = 0;
if (x>y) {
dis = (x-y)/12-1;
for (z=1; z<=dis; z++) {
q = x-z*12;
if (zt[q] == 9) {
p4++;
}
}
} else {
dis = (y-x)/12-1;
for (z=1; z<=dis; z++) {
q = y-z*12;
if (zt[q] == 9) {
p4++;
}
}
}
if (p4 == dis) {
p4 = 100;
}
return (p4);
}
function panduan_cuowei() {
g = 1000;
gg = 1000;
br = 0;
j = 0;
k = 0;
line1 = first%12;
line2 = second%12;
line3 = math.floor(first/12);
line4 = math.floor(second/12);
for (i=1; i<=12; i++) {
jilu1[i] = line1+(i-1)*12;
jilu2[i] = line2+(i-1)*12;
//HANG
jilu3[i] = line3*12+i;
jilu4[i] = line4*12+i;
//LIE
}
for (i=1; i<=12; i++) {
if (jilu1[i] == first) {
if (zt[jilu2[i]] == 9) {
w = jiance_cuowei01(jilu2[i]);
if (w == 200) {
guaixian1_hen1(jilu2[i]);
_root.control.ok();
br = 1;
break;
}
}
} else if (jilu2[i] == second) {
if (zt[jilu1[i]] == 9) {
w = jiance_cuowei02(jilu1[i]);
if (w == 200) {
guaixian1_hen2(jilu1[i]);
_root.control.ok();
br = 1;
break;
}
}
}
if (zt[jilu1[i]] == 9 and zt[jilu2[i]] == 9) {
j = jiance_hen1(jilu1[i], jilu2[i]);
}
if (j>0) {
if (j<g) {
g = j;
g1 = jilu1[i];
g2 = jilu2[i];
}
//_root.control.ok();
} else {
if (zt[jilu3[i]] == 9 and zt[jilu4[i]] == 9) {
k = jiance_lie1(jilu3[i], jilu4[i]);
}
if (k>0) {
if (k<gg) {
gg = k;
g3 = jilu3[i];
g4 = jilu4[i];
}
}
}
}
if (br == 0) {
if (g != 1000) {
guaixian2_hen(g1, g2);
br = 1;
} else if (gg != 1000) {
guaixian2_lie(g3, g4);
}
}
}
function jiance_cuowei01(x) {
//错位状态1;
p1 = 0;
p2 = 0;
dis = math.abs(x-first)-1;
if (dis == 0) {
p1 = 100;
} else {
if (x>first) {
for (z=1; z<=dis; z++) {
q = x-z;
if (zt[q] == 9) {
p1++;
}
}
} else {
for (z=1; z<=dis; z++) {
q = first-z;
if (zt[q] == 9) {
p1++;
}
}
}
if (p1 == dis) {
p1 = 100;
}
}
dis = math.abs((second-x))/12-1;
if (dis == 0) {
p2 == 100;
} else {
if (second>x) {
for (z=1; z<=dis; z++) {
q = second-z*12;
if (zt[q] == 9) {
p2++;
}
}
} else {
dis = math.abs(dis);
for (z=1; z<=dis; z++) {
q = x-z*12;
if (zt[q] == 9) {
p2++;
}
}
}
}
if (p2 == dis) {
p2 = 100;
}
return (p1+p2);
}
function jiance_cuowei02(x) {
//错位状态2;
p1 = 0;
p2 = 0;
dis = math.abs(x-second)-1;
if (dis == 0) {
p1 = 100;
} else {
if (x>second) {
for (z=1; z<=dis; z++) {
q = x-z;
if (zt[q] == 9) {
p1++;
}
}
} else {
for (z=1; z<=dis; z++) {
q = second-z;
if (zt[q] == 9) {
p1++;
}
}
}
if (p1 == dis) {
p1 = 100;
}
}
dis = math.abs((first-x))/12-1;
if (dis == 0) {
p2 == 100;
} else {
if (first>x) {
for (z=1; z<=dis; z++) {
q = first-z*12;
if (zt[q] == 9) {
p2++;
}
}
} else {
dis = math.abs(dis);
for (z=1; z<=dis; z++) {
q = x-z*12;
if (zt[q] == 9) {
p2++;
}
}
}
}
if (p2 == dis) {
p2 = 100;
}
return (p1+p2);
}
function henxiang0(x, y) {
//横线0拐点画线函数;
//tellTarget ("ttt"+y) {
// gotoAndPlay(10);
//}
if (x>y) {
dis = x-y-1;
for (z=1; z<=dis; z++) {
q = x-z;
tellTarget ("ttt"+q) {
gotoAndPlay(10);
}
}
} else {
dis = y-x-1;
for (z=1; z<=dis; z++) {
q = y-z;
tellTarget ("ttt"+q) {
gotoAndPlay(10);
}
}
}
_root.control.ok();
}
function shuxian0(x, y) {
//竖线0拐点画线函数;
if (x>y) {
dis = (x-y)/12-1;
for (z=1; z<=dis; z++) {
q = x-z*12;
tellTarget ("ttt"+q) {
gotoAndPlay(13);
}
}
} else {
dis = (y-x)/12-1;
for (z=1; z<=dis; z++) {
q = y-z*12;
tellTarget ("ttt"+q) {
gotoAndPlay(13);
}
}
}
_root.control.ok();
}
function guaixian1_hen1(x) {
if (x>first and x<second) {
tellTarget ("ttt"+x) {
gotoAndPlay(19);
}
} else if (x>first and x>second) {
tellTarget ("ttt"+x) {
gotoAndPlay(25);
}
} else if (x<first and x<second) {
tellTarget ("ttt"+x) {
gotoAndPlay(16);
}
} else {
tellTarget ("ttt"+x) {
gotoAndPlay(22);
}
}
dis = math.abs(x-first)-1;
if (dis != 0) {
if (x>first) {
for (z=1; z<=dis; z++) {
q = x-z;
tellTarget ("ttt"+q) {
gotoAndPlay(10);
}
}
} else {
for (z=1; z<=dis; z++) {
q = first-z;
tellTarget ("ttt"+q) {
gotoAndPlay(10);
}
}
}
}
dis = math.abs((second-x))/12-1;
if (dis != 0) {
if (second>x) {
for (z=1; z<=dis; z++) {
q = second-z*12;
tellTarget ("ttt"+q) {
gotoAndPlay(13);
}
}
} else {
dis = math.abs(dis);
for (z=1; z<=dis; z++) {
q = x-z*12;
tellTarget ("ttt"+q) {
gotoAndPlay(13);
}
}
}
}
}
function guaixian1_hen2(x) {
if (x>first and x<second) {
tellTarget ("ttt"+x) {
gotoAndPlay(22);
}
} else if (x>first and x>second) {
tellTarget ("ttt"+x) {
gotoAndPlay(25);
}
} else if (x<first and x<second) {
tellTarget ("ttt"+x) {
gotoAndPlay(16);
}
} else {
tellTarget ("ttt"+x) {
gotoAndPlay(19);
}
}
dis = math.abs(x-second)-1;
if (dis != 0) {
if (x>second) {
for (z=1; z<=dis; z++) {
q = x-z;
tellTarget ("ttt"+q) {
gotoAndPlay(10);
}
}
} else {
for (z=1; z<=dis; z++) {
q = second-z;
tellTarget ("ttt"+q) {
gotoAndPlay(10);
}
}
}
}
dis = math.abs((first-x))/12-1;
if (dis != 0) {
if (first>x) {
for (z=1; z<=dis; z++) {
q = first-z*12;
tellTarget ("ttt"+q) {
gotoAndPlay(13);
}
}
} else {
dis = math.abs(dis);
for (z=1; z<=dis; z++) {
q = x-z*12;
tellTarget ("ttt"+q) {
gotoAndPlay(13);
}
}
}
}
}
function guaixian2_hen(x, y) {
if (x<first and y<second and x<y) {
tellTarget ("ttt"+x) {
gotoAndPlay(16);
}
tellTarget ("ttt"+y) {
gotoAndPlay(19);
}
} else if (x<first and y<second and x>y) {
tellTarget ("ttt"+x) {
gotoAndPlay(19);
}
tellTarget ("ttt"+y) {
gotoAndPlay(16);
}
} else if (x>first and y>second and x<y) {
tellTarget ("ttt"+x) {
gotoAndPlay(22);
}
tellTarget ("ttt"+y) {
gotoAndPlay(25);
}
} else if (x>first and y>second and x>y) {
tellTarget ("ttt"+x) {
gotoAndPlay(25);
}
tellTarget ("ttt"+y) {
gotoAndPlay(22);
}
} else if (x>first and y<second and x<y) {
tellTarget ("ttt"+x) {
gotoAndPlay(22);
}
tellTarget ("ttt"+y) {
gotoAndPlay(19);
}
} else if (x>first and y<second and x>y) {
tellTarget ("ttt"+x) {
gotoAndPlay(25);
}
tellTarget ("ttt"+y) {
gotoAndPlay(16);
}
} else if (x<first and y>second and x<y) {
tellTarget ("ttt"+x) {
gotoAndPlay(16);
}
tellTarget ("ttt"+y) {
gotoAndPlay(25);
}
} else {
tellTarget ("ttt"+x) {
gotoAndPlay(19);
}
tellTarget ("ttt"+y) {
gotoAndPlay(22);
}
}
if (x>y) {
dis = x-y-1;
for (z=1; z<=dis; z++) {
q = x-z;
tellTarget ("ttt"+q) {
gotoAndPlay(10);
}
}
} else {
dis = y-x-1;
for (z=1; z<=dis; z++) {
q = y-z;
tellTarget ("ttt"+q) {
gotoAndPlay(10);
}
}
}
if (first>x) {
dis = (first-x)/12-1;
if (dis != 0) {
for (z=1; z<=dis; z++) {
q = first-z*12;
tellTarget ("ttt"+q) {
gotoAndPlay(13);
}
}
}
} else {
dis = (x-first)/12-1;
if (dis != 0) {
for (z=1; z<=dis; z++) {
q = x-z*12;
tellTarget ("ttt"+q) {
gotoAndPlay(13);
}
}
}
}
if (second>y) {
dis = (second-y)/12-1;
if (dis != 0) {
for (z=1; z<=dis; z++) {
q = second-z*12;
tellTarget ("ttt"+q) {
gotoAndPlay(13);
}
}
}
} else {
dis = (y-second)/12-1;
if (dis != 0) {
for (z=1; z<=dis; z++) {
q = y-z*12;
tellTarget ("ttt"+q) {
gotoAndPlay(13);
}
}
}
}
_root.control.ok();
}
function guaixian2_lie(x, y) {
if (x<first and y<second and x<y) {
tellTarget ("ttt"+x) {
gotoAndPlay(16);
}
tellTarget ("ttt"+y) {
gotoAndPlay(22);
}
} else if (x<first and y<second and x>y) {
tellTarget ("ttt"+x) {
gotoAndPlay(22);
}
tellTarget ("ttt"+y) {
gotoAndPlay(16);
}
} else if (x>first and y>second and x<y) {
tellTarget ("ttt"+x) {
gotoAndPlay(19);
}
tellTarget ("ttt"+y) {
gotoAndPlay(25);
}
} else if (x>first and y>second and x>y) {
tellTarget ("ttt"+x) {
gotoAndPlay(25);
}
tellTarget ("ttt"+y) {
gotoAndPlay(19);
}
} else if (x>first and y<second and x>y) {
tellTarget ("ttt"+x) {
gotoAndPlay(25);
}
tellTarget ("ttt"+y) {
gotoAndPlay(16);
}
} else if (x>first and y<second and x<y) {
tellTarget ("ttt"+x) {
gotoAndPlay(19);
}
tellTarget ("ttt"+y) {
gotoAndPlay(22);
}
} else if (x<first and y>second and x<y) {
tellTarget ("ttt"+x) {
gotoAndPlay(16);
}
tellTarget ("ttt"+y) {
gotoAndPlay(25);
}
} else {
tellTarget ("ttt"+x) {
gotoAndPlay(22);
}
tellTarget ("ttt"+y) {
gotoAndPlay(19);
}
}
if (x>y) {
dis = (x-y)/12-1;
for (z=1; z<=dis; z++) {
q = x-z*12;
tellTarget ("ttt"+q) {
gotoAndPlay(13);
}
}
} else {
dis = (y-x)/12-1;
for (z=1; z<=dis; z++) {
q = y-z*12;
tellTarget ("ttt"+q) {
gotoAndPlay(13);
}
}
}
if (first>x) {
dis = first-x-1;
for (z=1; z<=dis; z++) {
q = first-z;
tellTarget ("ttt"+q) {
gotoAndPlay(10);
}
}
} else {
dis = x-first-1;
for (z=1; z<=dis; z++) {
q = x-z;
tellTarget ("ttt"+q) {
gotoAndPlay(10);
}
}
}
if (second>y) {
dis = second-y-1;
for (z=1; z<=dis; z++) {
q = second-z;
tellTarget ("ttt"+q) {
gotoAndPlay(10);
}
}
} else {
dis = y-second-1;
for (z=1; z<=dis; z++) {
q = y-z;
tellTarget ("ttt"+q) {
gotoAndPlay(10);
}
}
}
_root.control.ok();
}
function selectframe(number) {
switch (number) {
case 1 :
tellTarget ("ttt"+i) {
gotoAndStop(1);
}
break;
case 2 :
tellTarget ("ttt"+i) {
gotoAndStop(2);
}
break;
case 3 :
tellTarget ("ttt"+i) {
gotoAndStop(3);
}
break;
case 4 :
tellTarget ("ttt"+i) {
gotoAndStop(4);
}
break;
case 5 :
tellTarget ("ttt"+i) {
gotoAndStop(5);
}
break;
case 6 :
tellTarget ("ttt"+i) {
gotoAndStop(6);
}
break;
case 7 :
tellTarget ("ttt"+i) {
gotoAndStop(7);
}
break;
case 8 :
tellTarget ("ttt"+i) {
gotoAndStop(8);
}
break;
case 9 :
tellTarget ("ttt"+i) {
gotoAndStop(28);
}
break;
case 10 :
tellTarget ("ttt"+i) {
gotoAndStop(29);
}
break;
}
}
function ok() {
//可消除的处理函数;
tellTarget ("ttt"+first) {
gotoAndStop(9);
}
zt[first] = 9;
tellTarget ("ttt"+second) {
gotoAndStop(9);
}
zt[second] = 9;
c = zt[second];
}
}
//julu数组为待检测点,ZT数组为各点状态;
//9:消除;10:横线;13:竖线;16:「;19:7;22:L;25:」;
基本思路就是分两种情况考虑寻道算法,
为每一个小牌取个名字,(我用程序生成,并用数组记录下每个牌的状态,是无牌状态还是有牌状态)
一是在同行同列上
只要判断从起点到终点的所有牌的状态是否都为无牌状态,也就是起点牌到终点牌是否是连通的
二是只有一个拐点
先检测它们的所在行列所在的交汇点,判断他们的交绘点是否为无牌状态,如果是则继续判断从该交绘点分别到起点和终点间是否为连通,这时的方法同第一种方法一样.
三是有两个拐点
同样先判断这两个点所在行和列的两个交汇点,先判断两个交汇点间是否为空,若是则继续判断两个交汇点到起点终点是否为连通,这两中判断也可以分解为是第一种状态来进行判断