我试图制作一个交换游戏,但是当我在另一个函数中调用它们时,某些函数不起作用
有代码:
function tablegen (randuri, coloane: integer) {
tabb=new Array
for (i=1; i<=randuri; i++) {
tabb[i]=new Array
for (j=1; j<=coloane; j++) {
tabb[i][j]=Math.randomInt(5)+1
}
}
return tabb
}
function show0 (randuri, coloane: integer, v: array) {
var excnr : Number = 0
exci=new Array
excj=new Array
for (i=1; i<=randuri; i++) {
for (j=1; j<=coloane; j++) {
c1=1>2
c2=1>2
c3=1>2
if ((v[i-1][j]==v[i][j])&&(v[i+1][j]==v[i][j])) {
if (excnr>2) {
for (k=1; k<=excnr; k++) {
c1=c1||((i-1==exci[k])&&(j==excj[k]))
c2=c2||((i==exci[k])&&(j==excj[k]))
c3=c3||((i+1==exci[k])&&(j==excj[k]))
}
}
else {
c1=excnr>2
c2=excnr>2
c3=excnr>2
}
if (not(c1)) {
excnr++
exci[excnr]=i-1
excj[excnr]=j
trace(exci.toString())
trace(excj.toString())
}
if (not(c2)) {
excnr++
exci[excnr]=i
excj[excnr]=j
trace(exci.toString())
trace(excj.toString())
}
if (not(c3)) {
excnr++
exci[excnr]=i+1
excj[excnr]=j
trace(exci.toString())
trace(excj.toString())
}
}
if ((v[i][j-1]==v[i][j])&&(v[i][j+1]==v[i][j])) {
if (excnr>2) {
for (k=1; k<=excnr; k++) {
c1=c1||((j-1==excj[k])&&(i==exci[k]))
c2=c2||((j==excj[k])&&(i==exci[k]))
c3=c3||((j+1==excj[k])&&(i==exci[k]))
}
}
else {
c1=excnr>2
c2=excnr>2
c3=excnr>2
}
if (not(c1)) {
excnr++
excj[excnr]=j-1
exci[excnr]=i
trace(exci.toString())
trace(excj.toString())
}
if (not(c2)) {
excnr++
excj[excnr]=j
exci[excnr]=i
trace(exci.toString())
trace(excj.toString())
}
if (not(c3)) {
excnr++
excj[excnr]=j+1
exci[excnr]=i
trace(exci.toString())
trace(excj.toString())
}
}
trace(v[i][j])
}
}
for (k=1; k<=excnr; k++) {
v[exci[k]][excj[k]]=0
}
return v
}
function floating0 (randuri, coloane: integer, v: array) {
for (j=coloane; j>=1; j--) {
for (i=coloane; i>=1; i--) {
for (k=coloane; k>1; k--) {
if (v[k][j]==0) {
v[k][j]=v[k-1][j]
v[k-1][j]=0
}
}
}
}
return v
}
function regenerate (randuri, coloane: integer, v: array) {
for (i=1; i<=randuri; i++) {
for (j=1; j<=coloane; j++) {
if (v[i][j]==0) {
v[i][j]=Math.randomInt(5)+1
}
}
}
return v
}
function swaptest1 (r1, c1, r2, c2: integer) {
return (((r1-r2==0)&&((c1-c2==1)||(c1-c2==-1)))||((c1-c2==0)&&((r1-r2==1)||(r1-r2==-1))))
}
function swaptest2 (r1, c1, r2, c2: integer, v: array) {
a=v[r1][c1]
v[r1][c1]=v[r2][c2]
v[r2][c2]=a
v1s=(v[r1-1][c1]==v[r1-2][c1])&&(v[r1-1][c1]==v[r1][c1])
v1m=(v[r1][c1]==v[r1-1][c1])&&(v[r1][c1]==v[r1+1][c1])
v1j=(v[r1+1][c1]==v[r1][c1])&&(v[r1+1][c1]==v[r1+2][c1])
v2s=(v[r2-1][c2]==v[r2-2][c2])&&(v[r2-1][c2]==v[r2][c2])
v2m=(v[r2][c2]==v[r2-1][c2])&&(v[r2][c2]==v[r2+1][c2])
v2j=(v[r2+1][c2]==v[r2][c2])&&(v[r2+1][c2]==v[r2+2][c2])
o1s=(v[r1][c1-1]==v[r1][c1-2])&&(v[r1][c1-1]==v[r1][c1])
o1m=(v[r1][c1]==v[r1][c1-1])&&(v[r1][c1]==v[r1][c1+1])
o1d=(v[r1][c1+1]==v[r1][c1])&&(v[r1][c1+1]==v[r1][c1+2])
o2s=(v[r2][c2-1]==v[r2][c2-2])&&(v[r2][c2-1]==v[r2][c2])
o2m=(v[r2][c2]==v[r2][c2-1])&&(v[r2][c2]==v[r2][c2+1])
o2d=(v[r2][c2+1]==v[r2][c2])&&(v[r2][c2+1]==v[r2][c2+2])
o1=o1s||o1m||o1d
o2=o2s||o2m||o2d
v1=v1s||v1m||v1j
v2=v2s||v2m||v2j
p1=o1||v1
p2=o2||v2
return (p1||p2)
}
function swapper (r1, c1, r2, c2: integer, v: array) {
cond1 = (((r1-r2==0)&&((c1-c2==1)||(c1-c2==-1)))||((c1-c2==0)&&((r1-r2==1)||(r1-r2==-1))))
a=v[r1][c1]
v[r1][c1]=v[r2][c2]
v[r2][c2]=a
v1s=(v[r1-1][c1]==v[r1-2][c1])&&(v[r1-1][c1]==v[r1][c1])
v1m=(v[r1][c1]==v[r1-1][c1])&&(v[r1][c1]==v[r1+1][c1])
v1j=(v[r1+1][c1]==v[r1][c1])&&(v[r1+1][c1]==v[r1+2][c1])
v2s=(v[r2-1][c2]==v[r2-2][c2])&&(v[r2-1][c2]==v[r2][c2])
v2m=(v[r2][c2]==v[r2-1][c2])&&(v[r2][c2]==v[r2+1][c2])
v2j=(v[r2+1][c2]==v[r2][c2])&&(v[r2+1][c2]==v[r2+2][c2])
o1s=(v[r1][c1-1]==v[r1][c1-2])&&(v[r1][c1-1]==v[r1][c1])
o1m=(v[r1][c1]==v[r1][c1-1])&&(v[r1][c1]==v[r1][c1+1])
o1d=(v[r1][c1+1]==v[r1][c1])&&(v[r1][c1+1]==v[r1][c1+2])
o2s=(v[r2][c2-1]==v[r2][c2-2])&&(v[r2][c2-1]==v[r2][c2])
o2m=(v[r2][c2]==v[r2][c2-1])&&(v[r2][c2]==v[r2][c2+1])
o2d=(v[r2][c2+1]==v[r2][c2])&&(v[r2][c2+1]==v[r2][c2+2])
o1=o1s||o1m||o1d
o2=o2s||o2m||o2d
v1=v1s||v1m||v1j
v2=v2s||v2m||v2j
p1=o1||v1
p2=o2||v2
cond2 = (p1||p2)
if (cond1&&cond2) {
}
else {
a=v[r1][c1]
v[r1][c1]=v[r2][c2]
v[r2][c2]=a
}
return v
}
function start (ran, col: integer) {
t1=tablegen(ran,col)
while (true) {
t2=t1
t1=show0(ran,col,t1)
if (t1==t2) {
t1=t2
break
}
t1=floating0(ran,col,t1)
t1=regenerate(ran,col,t1)
}
return t1
}
和我做的任何事情,开始时的最后两个函数都不起作用 看起来我已经做了些什么,但错误在哪里?