我心血来潮在手机上编写了一个玩魔方的游戏程序,前些时在本站发布了C语言源码。后来在网上看到有人编写魔方自动求解的东西,感到很有趣味。故此在原编译的游戏程序上加了魔方自动求解的部分。这也是AI 解决问题的探讨。
游戏模式:界面上设置了12个操作按钮和3个转向按钮,用以直接操作魔方。 魔方图像块上点击可执行雷同的12个操作动作。

另加了层先法的第一步底层十字和第二步底层棱角的隐式操作按钮(step1 , step2),以及第三步上层十字到第六步六面同色的四个公式(A B C D )的隐式操作按钮。

下拉菜单设置了层先法的六个步骤的自动演示操作。

求解模式:设置魔方六个面的颜色输入界面,按实际的魔方各个块的颜色点击输入到颜色设置板即可自动求解魔方。游戏程序有详细的操作步骤记录。另有用于输出的操作步数据。






数据格式采用二个字节,按20个字节分段打印。用二个字节来设置一个操作数据单元, 此方法便于机器的输入输出。
L0 = Left 面 顺转90度, L1 = Left 面 逆转90度。F R U B D 面以此类推。
TL = Turn Left 左转, TR = Turn Right 右转
另一组测试:





以下是有详细注释的源码:
//***************************************
// 魔方求解 Seek Solve * Magic Cube
// 制作人:张纯叔 micelu@126.com
// myspringc v2.7 编译
// 编译:2025-10-06
//***************************************
Canvas cs ;
string sBarDes[10];
int nBarId[10];
string sMenu[50];
int nMenu[50];
float pi=3.1415926535;
float src[4]; //ClearDraw (cls) clear screen
string s,s1,s2,s3,s4,s5,s6,s7,s8,ss1,ss2,ss3;
float sx,sy,dx,dy;
float px,py;
FileInput filebox;
string fname; //filename
int i,j,t,k ; //t = times
int ts; //ts=calculate steps
int context,obj,id,event; //canvasProc
int bx,by; //button x y position
int bn; //button id number
int B[70]; //1 left 2 front 3 right 4 up 5 back 6 down
int SB[70]; //1 left 2 front 3 right 4 up 5 back 6 down
int cr1,cg1,cb1; //set color rgb
int scolor, scolor1 ; // switch cube color
int sw[9]; //switch Block color
//int donum; //calculate do step number
int n, sn,kn,cando;
double Rn; //random number
int tim[3]; //get Time
int hh,mm,ss;
int oldhh,oldmm,oldss;
int newhh,newmm,newss;
int mms; //show using time
string hhts,mmts,ssts, tim$;
string fma,fmb,fmc,fmd, fmd1; //formula
int ms, uf; //using formula
string dat[300]; //存储解步数据,2字节,260步
string D; //data
int St; //动画:0 不显示 ,1 显示
int status; //模式切换:0游戏,1求解
int sbx, sby;
int mode ;
main(){
setDisplay(1);
cs.Active();
cs.SetProc (context, mycanvasProc); //getProc
sBarDes[0]="开始游戏";
nBarId[0]=100;
sBarDes[1]="还原魔方";
nBarId[1]=101;
sBarDes[2]="自动演示";
nBarId[2]=102;
sBarDes[3]="模式切换";
nBarId[3]=103;
sBarDes[4]="退出程序";
nBarId[4]=104;
sBarDes[5]="AV";
nBarId[5]=105;
setToolBarHeight(6);
setButtonTextSize(13);
setButtonColor(255,240,240,240);
setButtonTextColor(255,0,0,250);
setToolBar(100,myToolBarProc,sBarDes,nBarId,6);
sMenu[0]="开始游戏";
nMenu[0]=200;
sMenu[1]="第一步:上层四棱";
nMenu[1]=201;
sMenu[2]="第二步:上层四角";
nMenu[2]=202;
sMenu[3]="第三步:二层四棱";
nMenu[3]=203;
sMenu[4]="第四步:顶层十字";
nMenu[4]=204;
sMenu[5]="第五步:顶面同色";
nMenu[5]=205;
sMenu[6]="第六步:六面同色";
nMenu[6]=206;
sMenu[7]="自动演示";
nMenu[7]=207;
sMenu[8]="查看走步记录";
nMenu[8]=208;
sMenu[9]="显示游戏图板";
nMenu[9]=209;
sMenu[10]="退出";
nMenu[10]=210;
setMenu(200,myMenuProc,sMenu,nMenu,11);
setTitle("魔方 Magic Cube ");
//*****************************
getTime (tim);
oldhh=tim[0];
oldmm=tim[1];
oldss=tim[2];
kn=2;
drawcover (); //版本信息
St=1; // 0 不显示动画,1 显示
for (i=0; i<70; i++){ SB[i]=0 ; } //init seek data
while ( ){ }
}//main ()
mycanvasProc (int context,int obj,int id,int event,float x,float y){
//**** Canvas mouse click () ****
if (event==0||event==2||event==10){ //get touch
//** screen touch & select button **
bn=0; //init buttom
kn=kn+1;
if ((kn-kn/2*2)==0){ //触控防闪烁
cando=1; }else{ cando=0; return; }
if (status==0){ //游戏模式
//设置界面操作按钮 12 cmd + 3 转向
if (x>20&&x<110){ //select button btn number
if (y>770&&y<840)bn=1;
if (y>840&&y<910)bn=2;
if (y>920&&y<980)bn=9; }
if (x>310&&x<400){ //select button btn number
if (y>760&&y<840)bn=3;
if (y>840&&y<920)bn=4;
if (y>920&&y<990)bn=10; }
if (x>120&&x<210&&y>750&&y<810)bn=5;
if (x>210&&x<300&&y>750&&y<810)bn=6;
if (x>120&&x<210&&y>815&&y<885)bn=7;
if (x>210&&x<300&&y>815&&y<885)bn=8;
if (x>120&&x<210&&y>890&&y<960)bn=11;
if (x>210&&x<300&&y>890&&y<960)bn=12;
//左旋转,右旋转,上翻转
if (x>430&&x<555&&y>750&&y<840)bn=13;
if (x>560&&x<690&&y>750&&y<840)bn=14;
if (x>490&&x<620&&y>850&&y<950)bn=15;
//** 设置操作标记
cs.SetFillMode (1);
cs.SetTextSize (20);
cs.SetColor(255,255,255,255);
//cs.DrawCircle (160,280,5); //L
// cs.DrawCircle (160,440,5);
if (x>120&&x<200&&y>240&&y<320)bn=1;
if (x>120&&x<200&&y>400&&y<480)bn=2;
cs.DrawText ("L1",150,290);
cs.DrawText ("L",150,450);
// cs.DrawCircle (320,370,2); //R
// cs.DrawCircle (320,520,2);
if (x>280&&x<360&&y>330&&y<410)bn=3;
if (x>280&&x<360&&y>480&&y<560)bn=4;
cs.DrawText ("R",310,370);
cs.DrawText ("R1",305,530);
// cs.DrawCircle (260,270,40); //U
//cs.DrawCircle (450,270,40);
if (x>220&&x<300&&y>230&&y<310)bn=5;
if (x>410&&x<490&&y>230&&y<310)bn=6;
cs.DrawText ("U",270,270);
cs.DrawText ("U1",430,270);
//cs.DrawCircle (400,370,2); //F
//cs.DrawCircle (400,520,2);
if (x>360&&x<440&&y>330&&y<410)bn=7;
if (x>360&&x<440&&y>480&&y<560)bn=8;
cs.DrawText ("F1",390,370);
cs.DrawText ("F",395,530);
//cs.DrawCircle (560,280,5); //B
//cs.DrawCircle (560,440,5);
if (x>520&&x<600&&y>240&&y<320)bn=10;
if (x>520&&x<600&&y>400&&y<480)bn=9;
cs.DrawText ("B",550,290);
cs.DrawText ("B1",550,450);
// cs.DrawCircle (230,490,4); //D
// cs.DrawCircle (480,490,4);
if (x>190&&x<270&&y>450&&y<530)bn=11;
if (x>440&&x<520&&y>450&&y<530)bn=12;
cs.DrawText ("D1",230,490);
cs.DrawText ("D",470,490);
cs.SetColor (255,0,0,250) ;
cs.DrawCircle (648,700, 21) ;
cs.DrawCircle (660,700, 21) ;
cs.SetColor (255,250,250,0) ;
cs.DrawText ("Fm", 640, 705 ) ;
//公式解法:
//顶层十字:至多三次即可
//公式 A:R1 U1 F1 U F R
// 顶面同色:顶面十字四角无色块,下角色块置左;
// 有一块,田置左下; 有二块,黄色置前左
//公式 B:R U R1 U R U U R1
//顶面同色:调整角块,两角块同色置前
//公式 C:R B1 R FF R1 B R FF RR
//六面同色:顶棱同色置后B,
//公式 D:R U1 R U R U R U1 R1 U1 RR
if (x>630&&x<720&&y>650&&y<720){
fma="A = R1 U1 F1 U F R ";
fmb="B = R U R1 U R U U R1 ";
fmc="C = R B1 R FF R1 B R FF RR ";
fmd="D = R U1 R U R U R U1 ";
fmd1=" R1 U1 RR"; }
else{ fma=" "; fmb=" "; fmc=" "; fmd=" "; fmd1=" "; }
cs.SetColor (255,80,80,80) ; //clear text
cs.DrawRect (485, 525, 710, 625) ;
cs.DrawRect (667, 210, 685, 325) ;
cs.DrawRect (667, 380, 685, 520) ;
cs.SetColor (255,250,250,250) ;
cs.SetTextSize (16);
cs.DrawText (fma,490,540);
cs.DrawText (fmb,490,560);
cs.DrawText (fmc,490,580);
cs.DrawText (fmd,490,600);
cs.DrawText (fmd1,490,620); //显示公式
cs.DrawCircle (675,220,9); //A
cs.DrawCircle (675,300,9); //B
cs.DrawCircle (675,400,9); //C
cs.DrawCircle (675,480,9); //D
cs.DrawText ("A",670,245);
cs.DrawText ("B",670,325);
cs.DrawText ("C",670,425);
cs.DrawText ("D",670,505);
cs.SetColor (255,0,250,0);
cs.DrawCircle (35,380,15); //BS1
cs.DrawCircle (35,460,15); //BS2
cs.DrawCircle (35,540,15); //BS test
cs.SetColor (255,250,0,0);
cs.DrawText ("Step1",30,385);
cs.DrawText ("Step2",30,465);
cs.DrawText ("Solve",30,545); //test
cs.Update ();
if (x>660&&x<720&&y>180&&y<260){
ms=41; Formula (); } //A
if (x>660&&x<720&&y>260&&y<340){
ms=51; Formula (); } //B
if (x>660&&x<720&&y>380&&y<460){
ms=53; Formula (); } //C
if (x>660&&x<720&&y>460&&y<540){
ms=61; Formula (); } //D
//****
if (x>10&&x<90&&y>365&&y<395){
Bstep1 (); } //底层十字
if (x>10&&x<90&&y>445&&y<475){
Bstep2 (); } //底层四棱
if (x>10&&x<90&&y>525&&y<555){
Autorun (); } //test auto play
// solve (); } //test seek solve
// cs.SetFillMode (1);
cs.Update ();
//********* get button run step
//bx=(int)(x);
//by=(int)(y);
if (bn==1){
s3="走步: 左上 L ' ";
Leftup (); }
if (bn==2){
s3="走步: 左下 L ";
Leftdown (); }
if (bn==3){
s3="走步: 右上 R ";
Rightup (); }
if (bn==4){
s3="走步: 右下 R ' ";
Rightdown (); }
if (bn==5){
s3="走步: 上左 U ";
Upleft (); }
if (bn==6){
s3="走步: 上右 U ' ";
Upright (); }
if (bn==7){
s3="走步: 前左 F ' ";
Frontleft (); }
if (bn==8){
s3="走步: 前右 F ";
Frontright (); }
if (bn==9){
s3="走步: 后左 B ' ";
Backleft (); }
if (bn==10){
s3="走步: 后右 B ";
Backright (); }
if (bn==11){
s3="走步: 下左 D ' ";
Downleft (); }
if (bn==12){
s3="走步: 下右 D ";
Downright (); }
if (bn==13){
s3="走步: 左旋转 ";
Turnleft (); }
if (bn==14){
s3="走步: 右旋转 ";
Turnright (); }
if (bn==15){
s3="走步: 翻转 ";
Turnup (); }
//screen touch & select button ********
cs.SetFillMode (1);
cs.SetColor(255,250,250,250);
cs.DrawRect (80,3,700,30); // clear print x y
s=intToString(bn);
s4="按钮(bn) > "+s;
s=intToString(bx);
s1="X= "+s;
s=intToString(by);
s2="Y= "+s;
cs.SetColor (255,250,0,0);
cs.SetTextSize (26);
// cs.DrawText (s1,25,25);
// cs.DrawText (s2,120,25);
cs.DrawText (s4,220,25);
cs.DrawText (s3,445,25);
cs.SetColor (255,90,90,90); //clear
cs.DrawRect (10,30,710,730);
drawbox ();
checkfinished ();
} //status=0 游戏模式
//****************************
//**** status 求解模式 ******
if (status==1) { //求解模式
drawblock (); //Show block
if (x>20&&x<700&&y>60&&y<720){
seekpad (); } //draw seek pad
//** select color
cs.SetTextSize (22) ;
if (x>20&&x<590&&y>600&&y<680){ //colorpad
bx=(int)(x/80)*80; //取整数
scolor1=bx/80+1 ;
cs.DrawText ("select >", 22, 505);
cs.Update ();
} //colorpad
//**** U40 ****
if (x>170&&x<320&&y>50&&y<200){ //U40
bx=(int)((x-20)/50)*50; //取整数
by=(int)(y/50)*50; //取整数
sbx=(bx-150)/50+1 ;
sby=(by-50)/50 ;
cs.SetColor (255,250,0,0);
sn=sbx+sby*3+40; //U40
s="B"+intToString (sn) ;
cs.DrawText (s, 100, 130);
SB[sn]=scolor1 ;
cs.Update ();
} //U40
//** L10 F20 R30 B50
if (x>20&&x<620&&y>200&&y<350){
bx=(int)((x-20)/150)*150 ; //取整数
bx=bx/150 ;
if (bx==0) kn=10 ; //L10
if (bx==1) kn=20 ;
if (bx==2) kn=30 ;
if (bx==3) kn=50 ;
sbx=(int)(x-20-bx*150)/50+1 ; // *150 还原
by=(int)(y/50)*50; //取整数
sby=(by-200)/50 ;
sn=sbx+sby*3+kn;
cs.SetColor (255,250,0,0);
s="B"+intToString (sn) ;
cs.DrawText (s, 100, 435);
SB[sn]=scolor1 ;
cs.Update (); } //LFRB
//**** D60 ****
if (x>170&&x<320&&y>350&&y<500){ //U40
bx=(int)((x-20)/50)*50; //取整数
by=(int)(y/50)*50; //取整数
sbx=(bx-150)/50+1 ;
sby=(by-350)/50 ;
cs.SetColor (255,250,0,0);
sn=sbx+sby*3+60; //D60
s="B"+intToString (sn) ;
cs.DrawText (s, 355, 435);
SB[sn]=scolor1 ;
cs.Update ();
} //D60
//** 操作按钮设置
if (x>540&&x<660&&y>520&&y<580){ //解魔方
for (i=0; i<70; i++){ B[i]=SB[i] ; } //传数据
status=0 ; //游戏模式
for (j=1; j<=6; j++){
for (i=1; i<=9; i++){
kn=j*10+i ;
if (SB[kn]==0) {
disMsg (0, "缺数据,重置 > ") ;
goto reset ; } //跳出
} } //若有一块未设置则返回补设置
solve () ; } //解魔方
if (x>540&&x<660&&y>620&&y<680){ //重置
for (i=0; i<70; i++){ SB[i]=0 ; }
drawblock (); //Show empty
} //重置
reset:
drawblock (); //draw out block
} //求解模式
} //screen touch & select button ********
}//mycanvasProc ()
solve (){
//** 魔方自动求解
clearOutput (); //清除记录
print "User select >>> 魔方自动求解";
for (i=0; i<70; i++){ B[i]=SB[i] ; } //传数据
ts=-1 ; //init calculate steps, 数据计数0开始
St=0; //不作动画显示
Bstep1 (); //底层四棱
Bstep2 (); //底层四角
Astep3 (); //二层四棱
Astep4 (); //顶层十字
Astep5 (); //顶面同色
Astep6 (); //六面同色
drawbox ();
}//solve ()
seekpad (){
//** 求解:画颜色设置板
//draw pad
cs.SetFillMode (1);//0不填色,1填色
cs.SetColor (255,250,250,250); //backcolor
cs.DrawRect (0,5,720,740);
cs.SetColor (255,90,90,90);
cs.DrawRect (10,30,710,730);
cs.SetColor (255,100,100,100); //seek backcolor
cs.DrawRect (169,49,320,200); //U
cs.DrawRect (19,199,620,350); //LFRB
cs.DrawRect (169,349,320,500); //D
//**** draw cube grid
int d, x1, y1;
cs.SetFillMode (1);//0不填色,1填色
d=50;
x1=20 ; y1=200 ;
for (j=0; j<3; j++){ //draw LFRB
for (i=0; i<12; i++){
cs.SetColor (255,250,250,250);
cs.DrawRect (i*d+x1,j*d+y1,i*d+d-2+x1,j*d+d-2+y1);
} }
for (j=0; j<3; j++){ //draw UD
for (i=0; i<3; i++){
cs.SetColor (255,250,250,250);
x1=170 ; y1=50;
cs.DrawRect (i*d+x1,j*d+y1,i*d+d-2+x1,j*d+d-2+y1);
y1=350;
cs.DrawRect (i*d+x1,j*d+y1,i*d+d-2+x1,j*d+d-2+y1);
} }
d=80 ; x1=20 ; y1=600 ;
for (i=0; i<6; i++){ //draw color pad
scolor=i+1 ;
switchcolor (); //界面块颜色设置
cs.SetColor(255,cr1,cg1,cb1); //color
cs.DrawRect (i*d+x1,j+y1,i*d+d-2+x1,j+d-2+y1);
} // draw colorpad
//** draw select color
scolor=scolor1;
switchcolor (); //界面块颜色设置
cs.SetColor(255,cr1,cg1,cb1); //select color
cs.DrawRect (20,510,100,590);
s=intToString (scolor) ;
cs.SetColor (255,200,200,200);
// cs.DrawText (s, 100, 505);
cs.DrawText ("select >", 22, 505);
//** draw button
cs.SetColor (255,50,50,50);
cs.DrawRect (540,520,660,580);
cs.DrawRect (540,620,660,680);
cs.SetColor (255,250,250,250);
cs.DrawRect (541,521,657,577);
cs.DrawRect (541,621,657,677);
cs.SetColor (255,100,100,100);
cs.DrawRect (544,524,657,577);
cs.DrawRect (544,624,657,677);
cs.SetColor (255,200,200,200);
cs.DrawRect (544,524,655,575);
cs.DrawRect (544,624,655,675);
cs.SetTextSize (28) ;
cs.SetColor (255,250,250,250);
cs.DrawText ("解魔方" , 561, 559);
cs.DrawText ("重 置" , 561, 659);
cs.SetColor (255,0,0,150);
cs.DrawText ("解魔方" , 560, 557);
cs.DrawText ("重 置" , 560, 657);
drawblock ();
cs.Update ();
}//seekpad ()
drawblock (){
//** 依颜色设置,即时更新面和块颜色
//**** Up blocks
scolor=SB[41];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u1
cs.DrawRect (170,50,218,98);
scolor=SB[42];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u2
cs.DrawRect (220,50,268,98);
scolor=SB[43];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u3
cs.DrawRect (270,50,318,98);
scolor=SB[44];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u4
cs.DrawRect (170,100,218,148);
scolor=SB[45];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u5
cs.DrawRect (220,100,268,148);
scolor=SB[46];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u6
cs.DrawRect (270,100,318,148);
scolor=SB[47];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u7
cs.DrawRect (170,150,218,198);
scolor=SB[48];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u8
cs.DrawRect (220,150,268,198);
scolor=SB[49];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u9
cs.DrawRect (270,150,318,198);
//**********
//**** Down blocks
scolor=SB[61];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //1
cs.DrawRect (170,350,218,398);
scolor=SB[62];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //2
cs.DrawRect (220,350,268,398);
scolor=SB[63];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //3
cs.DrawRect (270,350,318,398);
scolor=SB[64];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //4
cs.DrawRect (170,400,218,448);
scolor=SB[65];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //5
cs.DrawRect (220,400,268,448);
scolor=SB[66];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //6
cs.DrawRect (270,400,318,448);
scolor=SB[67];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //7
cs.DrawRect (170,450,218,498);
scolor=SB[68];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //8
cs.DrawRect (220,450,268,498);
scolor=SB[69];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //9
cs.DrawRect (270,450,318,498);
//**********
//**** Left blocks
scolor=SB[11];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //1
cs.DrawRect (20,200,68,248);
scolor=SB[12];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //2
cs.DrawRect (70,200,118,248);
scolor=SB[13];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //3
cs.DrawRect (120,200,168,248);
scolor=SB[14];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //4
cs.DrawRect (20,250,68,298);
scolor=SB[15];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //5
cs.DrawRect (70,250,118,298);
scolor=SB[16];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //6
cs.DrawRect (120,250,168,298);
scolor=SB[17];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //7
cs.DrawRect (20,300,68,348);
scolor=SB[18];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //8
cs.DrawRect (70,300,118,348);
scolor=SB[19];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //9
cs.DrawRect (120,300,168,348);
//**********
//**** Front blocks
scolor=SB[21];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //1
cs.DrawRect (170,200,218,248);
scolor=SB[22];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //2
cs.DrawRect (220,200,268,248);
scolor=SB[23];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //3
cs.DrawRect (270,200,318,248);
scolor=SB[24];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //4
cs.DrawRect (170,250,218,298);
scolor=SB[25];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //5
cs.DrawRect (220,250,268,298);
scolor=SB[26];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //6
cs.DrawRect (270,250,318,298);
scolor=SB[27];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //7
cs.DrawRect (170,300,218,348);
scolor=SB[28];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //8
cs.DrawRect (220,300,268,348);
scolor=SB[29];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //9
cs.DrawRect (270,300,318,348);
//**********
//**** Right blocks
scolor=SB[31];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //1
cs.DrawRect (320,200,368,248);
scolor=SB[32];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //2
cs.DrawRect (370,200,418,248);
scolor=SB[33];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //3
cs.DrawRect (420,200,468,248);
scolor=SB[34];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //4
cs.DrawRect (320,250,368,298);
scolor=SB[35];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //5
cs.DrawRect (370,250,418,298);
scolor=SB[36];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //6
cs.DrawRect (420,250,468,298);
scolor=SB[37];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //7
cs.DrawRect (320,300,368,348);
scolor=SB[38];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //8
cs.DrawRect (370,300,418,348);
scolor=SB[39];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //9
cs.DrawRect (420,300,468,348);
//**********
//**** Back blocks
scolor=SB[51];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //1
cs.DrawRect (470,200,518,248);
scolor=SB[52];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //2
cs.DrawRect (520,200,568,248);
scolor=SB[53];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //3
cs.DrawRect (570,200,618,248);
scolor=SB[54];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //4
cs.DrawRect (470,250,518,298);
scolor=SB[55];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //5
cs.DrawRect (520,250,568,298);
scolor=SB[56];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //6
cs.DrawRect (570,250,618,298);
scolor=SB[57];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //7
cs.DrawRect (470,300,518,348);
scolor=SB[58];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //8
cs.DrawRect (520,300,568,348);
scolor=SB[59];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //9
cs.DrawRect (570,300,618,348);
//**********
//** 标记面
cs.SetTextSize (28);
cs.SetColor(255,0,0,120);
cs.DrawText ("U", 235,132);
cs.DrawText ("L", 85,282);
cs.DrawText ("F", 235,282);
cs.DrawText ("R", 385,282);
cs.DrawText ("B", 535,282);
cs.DrawText ("D", 235,432);
cs.Update (); //show
}//drawblock ()
//***************************************
Autoplay (){
//** 第一式自动运行设置(白十字置上)
newgame ();
clearOutput ();
print "User select >>> 自动演示";
ts=-1 ; //init calculate steps, 数据计数0开始
St=0; //0 不演示,1 演示
Astep1 (); //上层四棱
//sleep (1000);
Astep2 (); //上层四角
//sleep (1000);
Turnup (); Turnup (); //上层白色置底层
//sleep (1000);
Astep3 (); //二层四棱
//sleep (1000);
Astep4 (); //顶层十字
//sleep (1000);
Astep5 (); //顶面同色
//sleep (1000);
Astep6 (); //六面同色
}//Autoplay ()
Autorun (){
//** 第二式自动运行设置(白十字置底)
newgame ();
Turnup (); Turnup (); //白置底层
clearOutput ();
print "User select >>> 自动演示";
ts=-1 ; //init calculate steps, 数据计数0开始
St=0;
Bstep1 (); //底层四棱
Bstep2 (); //底层四角
Astep3 (); //二层四棱
Astep4 (); //顶层十字
Astep5 (); //顶面同色
Astep6 (); //六面同色
}//Aoutorun ()
Formula (){
//** 界面设置四公式操作,可直接使用公式
if (ms==41){ goto ms41; } //公式 A
if (ms==51){ goto ms51; } //公式 B
if (ms==53){ goto ms53; } //公式 C
if (ms==61){ goto ms61; } //公式 D
ms41: //顶层十字
//fma= A:R1 U1 F1 U F R
print "公式 A ";
Rightdown (); Upright (); Frontleft ();
Upleft (); Frontright (); Rightup ();
s=" fma= A:R1 U1 F1 U F R ";
print s;
return; //************
ms51: //顶面同色:同色
//fmb= B:R U R1 U R U U R1
print "公式 B ";
Rightup (); Upleft (); Rightdown ();
Upleft (); Rightup ();
Upleft (); Upleft (); Rightdown ();
s=" fmb= B:R U R1 U R U U R1 " ;
print s;
return; //************
ms53: //顶面同色:调整角块
//fmc= C:R B1 R FF R1 B R FF RR
print "公式 C";
Rightup (); Backleft (); //R B1
Rightup (); Frontright (); Frontright (); //R FF
Rightdown (); Backright (); //R1 B
Rightup (); Frontright (); Frontright (); //R FF
Rightup (); Rightup (); //RR
s=" fmc= C:R B1 R FF R1 B R FF RR ";
print s;
return; //顶面同色 *************
ms61: //六面同色:完成
//fmd= D:R U1 R U R U R U1 R1 U1 RR
print "公式 D ";
Rightup (); Upright (); //R U1
Rightup (); Upleft (); //R U
Rightup (); Upleft (); //R U
Rightup (); Upright (); //R U1
Rightdown (); Upright (); //R1 U1
Rightup (); Rightup (); //RR
s=" fmd= D:R U1 R U R U R U1 R1 U1 RR ";
print s;
return; // 公式 D
}//Formula ()
checkfinished (){
//** 查看魔方是否已完成
//**** check finished ************
for (i=1;i<10;i++){
if (B[10+i]==B[15]){ }else{ goto f60; }
if (B[20+i]==B[25]){ }else{ goto f60; }
if (B[30+i]==B[35]){ }else{ goto f60; }
if (B[40+i]==B[45]){ }else{ goto f60; }
if (B[50+i]==B[55]){ }else{ goto f60; }
if (B[60+i]==B[65]){ }else{ goto f60; }
} //check >>>>>>
goto f66; //if finished then show score
f60:
ms=80 ; return; //if not finished then retry
f66: // **** finished & show score *******
drawbox ();
if (ms==99) return;
print "times = ", n ; //D 公式,次数
print "步数 steps = ", ts+1 ; //使用步数
getTime (tim);
newhh=tim[0];
newmm=tim[1];
newss=tim[2];
hhts=intToString (tim[0]);
mmts=intToString (tim[1]);
ssts=intToString (tim[2]);
if (newhh<10)hhts="0"+hhts;
if (newmm<10)mmts="0"+mmts;
if (newss<10)ssts="0"+ssts;
mms=((newhh-oldhh)*3600)+
((newmm-oldmm)*60)+((newss-oldss));
if (mms<0) mms=mms+864000;
hh=mms/3600;
mm=(mms-hh*2600)/60;
ss=mms-hh*3600-mm*60;
s=intToString (ss);
if (ss<10) s="0"+s ; //** 若 sec<10 补 0
ss1=intToString (mm)+" 分 "+s+" 秒";
ss2=hhts+" : "+mmts+" : "+ssts;
s7="用时:"+ss1;
print "结束时间 "+ss2;
print s7;
cs.SetColor (255,250,250,250);
cs.SetTextSize (20);
cs.DrawText (tim$, 20, 710);
cs.DrawText (ss2, 20, 690);
cs.DrawText (ss1, 20, 670);
oldhh=newhh;
oldmm=newmm;
oldss=newss;
//******************
cs.SetColor(255,250,250,250);
cs.DrawRect (80,3,720,30); // clear print
s3="《六面同色》 已完成 ";
print s3;
cs.SetColor (255,250,20,120);
cs.SetTextSize (26);
cs.DrawText (s3,380,25);
cs.DrawText (s7,100,25);
s="恭喜你完成了魔方游戏! ";
cs.SetTextSize (60);
cs.SetFillMode (1);
cs.SetStrokeWidth (2);
cs.SetColor (255,160,30,240);
cs.DrawText (s,63,313);
cs.SetColor (255,250,0,0);
cs.DrawText (s,60,310);
cs.SetFillMode (0);
cs.SetStrokeWidth (1);
cs.SetColor (255,250,250,0);
cs.DrawText (s,60,310);
cs.SetFillMode (1);
cs.SetTextSize (26);
cs.Update ();
//** 打印解步数据记录,类> R0=R , R1=R' ...
print " ";
print "**** 分段打印解步数据记录 ********";
for (t=0; t<15; t++){ //280
D$=" ";
for (i=t*20; i<t*20+20; i++){
D=D+dat[i]+" " ; }
print D$ ; }
ms=99; //if finished then cut 结束标志
}//checkfinished ()
Bstep1 (){
//** 底层十字:白色置底层,做十字
cs.SetColor(255,250,250,250);
cs.DrawRect (80,3,720,30); // clear print
s5="(1)《底层十字》 do >>>>>> ";
print s5;
cs.SetColor (255,250,20,120);
cs.SetTextSize (26);
cs.DrawText (s5,90,25);
cs.Update ();
n=0; goto B15; //check finished
B10: //底层四菱有白转上
if (B[18]==B[65]){
Leftup (); Leftup (); }
if (B[28]==B[65]){
Frontright (); Frontright (); }
if (B[38]==B[65]){
Rightup (); Rightup (); }
if (B[58]==B[65]){
Backright (); Backright (); }
B11:
//**** 底错位白转上 *******
if (B[62]==B[65]&&B[28] !=B[25]){
Frontright (); Frontright (); }
if (B[64]==B[65]&&B[18] !=B[15]){
Leftup (); Leftup (); }
if (B[66]==B[65]&&B[38] !=B[35]){
Rightup (); Rightup (); }
if (B[68]==B[65]&&B[58] !=B[55]){
Backright (); Backright (); }
//**** 后2中转上
if (B[56]==B[65]||B[14]==B[65]){
Leftdown (); Upright (); Leftup (); }
if (B[54]==B[65]||B[36]==B[65]){
Rightdown (); Upleft (); Rightup (); }
B13: //**** at front 4 edge put it to correct ****
//top 4 edge 有白 to correct
if (B[48]==B[65]&&B[22]==B[25]){ //FF
Frontright (); Frontright (); }
if (B[22]==B[65]&&B[48]==B[25]){ //U L F1
Upright(); Leftdown (); Frontleft (); }
if (B[48]==B[65]&&B[22]==B[15]){ //U L L
Upleft (); Leftdown (); Leftdown (); }
if (B[22]==B[65]&&B[48]==B[15]){ // F1 L F
Frontleft (); Leftdown (); Frontright (); }
if (B[48]==B[65]&&B[22]==B[35]){ //U R1 R1
Upright(); Rightdown (); Rightdown (); }
if (B[22]==B[65]&&B[48]==B[35]){ //F R1 F1
Frontright (); Rightdown (); Frontleft (); }
if (B[48]==B[65]&&B[22]==B[55]){ //U U B B
Upright(); Upright ();
Backright (); Backright (); }
if (B[22]==B[65]&&B[48]==B[55]){ //F RR B
Frontright (); Rightup (); Rightup ();
Backright (); }
if (B[46]==B[65]&&B[32]==B[25]){ //U FF
Upleft (); Frontright (); Frontright (); }
if (B[32]==B[65]&&B[46]==B[25]){ //R1 F R
Rightdown (); Frontright (); Rightup (); }
if (B[46]==B[65]&&B[32]==B[15]){ //UU L L
Upleft (); Upleft (); Leftdown (); Leftdown (); }
if (B[32]==B[65]&&B[46]==B[15]){ //U F1 L F
Upright (); Frontleft ();
Leftdown (); Frontright (); }
if (B[46]==B[65]&&B[32]==B[35]){ // R R
Rightup (); Rightup (); }
if (B[32]==B[65]&&B[46]==B[35]){//U F R1 F1
Upright (); Frontright ();
Rightdown (); Frontleft (); }
if (B[46]==B[65]&&B[32]==B[55]){ //U1 B B
Upleft (); Backright (); Backright (); }
if (B[32]==B[65]&&B[46]==B[55]){ //R B1 R1
Rightup (); Backleft (); Rightdown (); }
if (B[44]==B[65]&&B[12]==B[25]){ //U1 FF
Upright (); Frontright (); Frontright (); }
if (B[12]==B[65]&&B[44]==B[25]){ //L F1 L1
Leftdown (); Frontleft (); Leftup (); }
if (B[44]==B[65]&&B[12]==B[15]){ // L L
Leftdown (); Leftdown (); }
if (B[12]==B[65]&&B[44]==B[15]){ //U1 F1 L F
Upleft (); Frontright ();
Leftdown (); Frontleft (); }
if (B[44]==B[65]&&B[12]==B[35]){ //U1U1 R1R1
Upright (); Upright ();
Rightdown (); Rightdown (); }
if (B[12]==B[65]&&B[44]==B[35]){ //U1 F R1 F1
Upright (); Frontright ();
Rightdown (); Frontleft (); }
if (B[44]==B[65]&&B[12]==B[55]){ //U B B
Upright (); Backright (); Backright (); }
if (B[12]==B[65]&&B[44]==B[55]){ //L1 B L
Leftup (); Backright (); Leftdown (); }
if (B[42]==B[65]&&B[52]==B[25]){ //UU FF
Upright (); Upright ();
Frontright (); Frontright (); }
if (B[52]==B[65]&&B[42]==B[25]){ //U1 L F1 L1
Upleft (); Leftdown ();
Frontleft (); Leftup (); }
if (B[42]==B[65]&&B[52]==B[15]){ //U1 L
Upleft (); Leftdown (); Leftdown (); }
if (B[52]==B[65]&&B[42]==B[15]){ //B L1 B1
Backright (); Leftup (); Backleft (); }
if (B[42]==B[65]&&B[52]==B[35]){ //U R R
Upright (); Rightup (); Rightup (); }
if (B[52]==B[65]&&B[42]==B[35]){ //B1 R B
Backleft (); Rightup (); Backright (); }
if (B[42]==B[65]&&B[52]==B[55]){ //B B
Backright (); Backright (); }
if (B[52]==B[65]&&B[42]==B[55]){ //U R B1
Upright (); Rightup (); Backleft (); }
//**** front under edge white to correct
if (B[28] !=B[25]&&B[62]==B[65]){ //F F
Frontright (); Frontright (); }
if (B[28]==B[65]&&B[62]==B[15]){ //F L
Frontleft (); Leftdown (); }
if (B[28]==B[65]&&B[62]==B[25]){ //F1 L U L1 FF
Frontleft (); Leftup (); Upright (); Leftdown ();
Frontright (); Frontright (); }
if (B[28]==B[65]&&B[62]==B[35]){ //F1 R1
Frontright (); Rightdown (); }
if (B[28]==B[65]&&B[62]==B[55]){ //F L1 U L BB
Frontright (); Leftup(); Upright (); Leftdown ();
Backright (); Backright (); }
//2 layer front 2 edge white to correct
if (B[34]==B[65]&&B[26]==B[25]){ //F
Frontleft (); }
if (B[26]==B[65]&&B[34]==B[25]){ //R U R1 FF **
Rightup (); Upleft (); Rightdown ();
Frontright (); Frontright (); }
if (B[16]==B[65]&&B[24]==B[25]){ //F1
Frontright (); }
if (B[24]==B[65]&&B[16]==B[25]){ //L1 U1 L FF
Leftup(); Upright (); Leftdown ();
Frontleft (); Frontleft (); }
Turnleft ();
n=n+1;
// if (ts>40) goto B16;
B15: //**** check finished ************
if (B[62]==B[65]&&B[64]==B[65]&&
B[66]==B[65]&&B[68]==B[65]){
goto B16; } else { goto B10 ; }
B16: //**** under cross finished ******
cs.SetColor(255,250,250,250);
cs.DrawRect (80,3,720,30); // clear print
s3="《底层十字》 已完成 ";
print s3;
cs.SetColor (255,250,20,120);
cs.SetTextSize (26);
cs.DrawText (s3,380,25);
cs.Update ();
print "times = ",n;
print "步数 steps = ", ts+1 ; //使用步数
}//Bstep1 ()
Bstep2 (){
//** 底层四角:白色置底层 **
cs.SetColor(255,250,250,250);
cs.DrawRect (80,3,720,30); // clear print
s5="(2)《底层四角》 do >>>>>> ";
print s5;
cs.SetColor (255,250,20,120);
cs.SetTextSize (26);
cs.DrawText (s5,90,25);
cs.Update ();
n=0; goto B25; //check finished
B20: //** 底四角白翻上
if (B[29]==B[65]||B[37]==B[65]||B[63]==B[65]){
Rightup(); Upleft (); Rightdown (); }
if (B[19]==B[65]||B[27]==B[65]||B[61]==B[65]){
Frontright (); Upleft (); Frontleft (); }
if (B[59]==B[65]||B[17]==B[65]||B[67]==B[65]){
Leftdown (); Upleft (); Leftup (); }
if (B[39]==B[65]||B[57]==B[65]||B[69]==B[65]){
Backright (); Upleft (); Backleft (); }
B21:
//****adjust this right corner
if (B[29]==B[65]||B[37]==B[65]||B[63] !=B[65]){
Rightup (); Upleft ();
Rightdown (); } //Upright (); } //未就位
//** adjust 上四角 入巢
if (B[33]==B[65]||B[51]==B[65]||B[43]==B[65]){
if (B[33]==B[25]||B[51]==B[25]||B[43]==B[25]){
if (B[33]==B[35]||B[51]==B[35]||B[43]==B[35]){
Upright (); } } }
if (B[13]==B[65]||B[21]==B[65]||B[47]==B[65]){
if (B[13]==B[25]||B[21]==B[25]||B[47]==B[25]){
if (B[13]==B[35]||B[21]==B[35]||B[47]==B[35]){
Upleft (); } } }
if (B[53]==B[65]||B[11]==B[65]||B[41]==B[65]){
if (B[53]==B[25]||B[11]==B[25]||B[41]==B[25]){
if (B[53]==B[35]||B[11]==B[35]||B[41]==B[35]){
Upleft (); Upleft (); } } }
//**** do it to correct corner
//白上,U1 R1 U R R U1 R1
if (B[49]==B[65]&&B[23]==B[35]&&B[31]==B[25]){
Upright (); Rightdown (); Upleft ();
Rightup (); Rightup (); Upright (); Rightdown();
print "s2_21 : 白上 U1 R1 U R R U1 R1 "; }
//白左 U R U1 R1
if (B[23]==B[65]&&B[31]==B[35]&&B[49]==B[25]){
Upleft (); Rightup (); Upright (); Rightdown ();
print "s2_22 : 白左 U R U1 R1 "; }
//白右 R U R1
if (B[31]==B[65]&&B[23]==B[25]&&B[49]==B[35]){
Rightup (); Upleft (); Rightdown ();
print "s2_23 : 白右 R U R1 "; }
Turnleft ();
n=n+1;
B25: //**** check finished ************
if (B[61]==B[65]&&B[63]==B[65]&&
B[67]==B[65]&&B[69]==B[65]){
goto B26; } else { goto B21; }
return;
B26:
cs.SetColor(255,250,250,250);
cs.DrawRect (80,3,720,30); // clear print
s3="《底层四角》 已完成 ";
print s3;
cs.SetColor (255,250,20,120);
cs.SetTextSize (26);
cs.DrawText (s3,380,25);
cs.Update ();
print "times = ", n ;
print "步数 steps = ", ts+1 ; //使用步数
}//Bstep2 ()
Astep6 (){ //六面同色 ************
cs.SetColor(255,250,250,250);
cs.DrawRect (80,3,720,30); // clear print
s5="(6)《六面同色》 do >>>>>> ";
print s5;
cs.SetColor (255,250,20,120);
cs.SetTextSize (26);
cs.DrawText (s5,90,25);
cs.Update ();
n=0;
checkfinished (); // 可能 Astep5 () 已完成
if (ms==99) return; //已完成
s61:
//**** adjust status at first *********
if (B[12]==B[15]){ //same color edge to back
Turnleft (); }
if (B[22]==B[25]){ Turnleft (); Turnleft (); }
if (B[32]==B[35]){ Turnright (); }
//** new:using formula D to finished cube
//已同色棱置后,逆一次,顺二次就可完成
ms=61; Formula ();
n=n+1;
checkfinished ();
print "步数 steps = ", ts+1 ; //使用步数
if(ms<99){ goto s61 ; }
}//Astep6 ()
Astep5 (){ //顶面同色 ************
cs.SetColor(255,250,250,250);
cs.DrawRect (80,3,720,30); // clear print
s5="(5)《顶面同色》 do >>>>>> ";
print s5;
cs.SetColor (255,250,20,120);
cs.SetTextSize (26);
cs.DrawText (s5,90,25);
cs.Update ();
n=0;
//对齐前面同色棱,查看几块同色
if (B[12]==B[25]){ Upright (); }
if (B[32]==B[25]){ Upleft (); }
if (B[52]==B[25]){ Upleft (); Upleft (); }
s51:
k=0 ; n=n+1 ; //计算顶面有几角块同色
if (B[41]==B[45]) k=k+1 ;
if (B[43]==B[45]) k=k+1 ;
if (B[47]==B[45]) k=k+1 ;
if (B[49]==B[45]) k=k+1 ;
//state 1 > ** adjust status 顶面角块无同色
if (k==0){
if (B[23]==B[45]){ Turnleft (); }
if (B[33]==B[45]){ Turnleft (); Turnleft (); }
if (B[53]==B[45]){ Turnright (); }
if (B[13]==B[45]){ }
ms=51; Formula(); } //公式 B
//state 2 > ** adjust status
// 顶面一角块同色,小鱼置左
if (k==1) {
if (B[41]==B[45]){ Turnright (); }
if (B[43]==B[45]){ Turnleft (); Turnleft (); }
if (B[49]==B[45]){ Turnleft (); }
ms=51; Formula(); } //公式 B
//state 3 > ** adjust statue
// 顶面二以上角块同色,另角边色同顶色置前
if (k>1) {
if (B[11]==B[45]){ Turnright (); }
if (B[31]==B[45]){ Turnleft (); }
if (B[51]==B[45]){ Turnleft (); Turnleft (); }
ms=51; Formula(); //公式 B
} //若有2块以上同顶色,同色置前
//**** check finished ************
if (B[41]==B[45]&&B[42]==B[45]&&
B[43]==B[45]&&B[44]==B[45]&&
B[46]==B[45]&&B[47]==B[45]&&
B[48]==B[45]&&B[49]==B[45]) {
goto s53; } //to next execute
goto s51; //retry ******
return;
//*****************************
//**** sequence C *******
s53:
//**** state adjust
if (B[11]==B[25]){ Upright (); }
if (B[31]==B[25]){ Upleft (); }
if (B[51]==B[25]){ Upleft (); Upleft (); }
//**** 可能此步已完成
//**** check finished ************
if (B[41]==B[45]&&B[42]==B[45]&&
B[43]==B[45]&&B[44]==B[45]&&
B[46]==B[45]&&B[47]==B[45]&&
B[48]==B[45]&&B[49]==B[45]&&
B[11]==B[15]&&B[21]==B[25]&&
B[31]==B[35]&&B[51]==B[55]) {
goto s57; } //finished game
//完成顶面同色,再调整角块,二块同色置前
n=n+1 ;
if (B[11]==B[13]){ Turnright (); }
if (B[31]==B[33]){ Turnleft (); }
if (B[51]==B[53]){ Turnleft (); Turnleft (); }
ms=53; Formula(); //公式 C
//**** check finished ************
if (B[41]==B[45]&&B[42]==B[45]&&
B[43]==B[45]&&B[44]==B[45]&&
B[46]==B[45]&&B[47]==B[45]&&
B[48]==B[45]&&B[49]==B[45]&&
B[11]==B[15]&&B[21]==B[25]&&
B[31]==B[35]&&B[51]==B[55]) {
goto s57; } //finished game
else{ goto s53; } //if not finished then retry
return;
//**** finished ******
s57:
//**** check finished ************
if (B[11]==B[15]&&B[12]==B[15]&&B[13]==B[15]){
if (B[21]==B[25]&&B[22]==B[25]&&B[23]==B[25]){
if (B[31]==B[35]&&B[32]==B[35]&&B[33]==B[35]){
if (B[51]==B[55]&&B[52]==B[55]&&B[53]==B[55]){
goto s59; } } } } //六面同色已完成
cs.SetColor(255,250,250,250);
cs.DrawRect (80,3,720,30); // clear print
s3="《顶面同色》 已完成 ";
print s3;
cs.SetColor (255,250,20,120);
cs.SetTextSize (26);
cs.DrawText (s3,380,25);
cs.Update ();
print "times = ",n;
print "步数 steps = ", ts+1 ; //使用步数
return;
s59: //if finuished magic cube some times ****
checkfinished ();
print "Well done ! magic cube is finished. ";
ms=99 ;
}//Astep5 ()
Astep4 (){ //顶层十字 ************
cs.SetColor(255,250,250,250);
cs.DrawRect (80,3,720,30); // clear print
s5="(4)《顶层十字》 do >>>>>> ";
print s5;
cs.SetColor (255,250,20,120);
cs.SetTextSize (26);
cs.DrawText (s5,90,25);
cs.Update ();
n=0;
goto s45; //check finished 可能此步已完成
s41: //run 4 times when finished *******
//adjust status ***********
if (B[44]==B[45]&&B[48]==B[45]){
Upleft (); }
if (B[46]==B[45]&&B[48]==B[45]){
Upleft (); Upleft (); }
if (B[42]==B[45]&&B[46]==B[45]){
Upright (); }
if (B[44]==B[45]&&B[46]==B[45]){
Upleft (); }
//use formula execute R' U' F' U F R *****
print "公式 A ";
Rightdown (); Upright (); Frontleft ();
Upleft (); Frontright (); Rightup ();
n=n+1;
// if (n>10) goto s46;
s45: //**** check finished ************
if (B[42]==B[45]&&B[44]==B[45]&&
B[46]==B[45]&&B[48]==B[45]){
goto s46; } else { goto s41; }
return;
s46:
cs.SetColor(255,250,250,250);
cs.DrawRect (80,3,720,30); // clear print
s3="《顶层十字》 已完成 ";
print s3;
cs.SetColor (255,250,20,120);
cs.SetTextSize (26);
cs.DrawText (s3,380,25);
cs.Update ();
print "times = ",n;
print "步数 steps = ", ts+1 ; //使用步数
}//Astep4 ()
Astep3 (){ //二层四棱 *************
s30:
s3="Autoplay >> 二层四棱 ";
cs.SetColor(255,250,250,250);
cs.DrawRect (80,3,720,30); // clear print
s5="(3)《二层四棱》 do >>>>>> ";
print s5;
cs.SetColor (255,250,20,120);
cs.SetTextSize (26);
cs.DrawText (s5,90,25);
cs.Update ();
n=0 ; //计算次数
goto s35; //check finished
s31:
//****** adjust status ************
if (B[26]==B[35]||B[34]==B[25]){
if (B[26]==B[15]||B[34]==B[55]){
print "s3_31 "; // R' U' R' U' R' U R U R
Rightdown (); Upright (); Rightdown();
Upright (); Rightdown ();
Upleft (); Rightup (); Upleft ();
Rightup (); } } // s3_31
if (B[36]==B[25]||B[54]==B[35]){
if (B[36]==B[55]||B[54]==B[15]){
print "s3_32 "; // R U R U R U' R' U' R'
Rightup (); Upleft (); Rightup();
Upleft (); Rightup ();
Upright (); Rightdown (); Upright ();
Rightdown (); } } // s3_32
//**** adjust status *******************
if (B[44]==B[25]&&B[12]==B[35]){
Upright (); Upright (); }
if (B[44]==B[55]&&B[12]==B[35]){
Upright (); Upright (); }
if (B[42]==B[25]&&B[52]==B[35]){
Upleft (); }
if (B[42]==B[55]&&B[52]==B[35]){
Upleft (); }
if (B[48]==B[25]&&B[22]==B[35]){
Upright (); }
if (B[48]==B[55]&&B[22]==B[35]){
Upright (); }
s32: //do medium layer edges ******
if (B[46]==B[25]&&B[32]==B[35]){ //s3_31 left
print "s3_31 ";
Rightdown (); Upright (); Rightdown();
Upright (); Rightdown ();
Upleft (); Rightup (); Upleft ();
Rightup (); } //Turnleft (); }
if (B[46]==B[55]&&B[32]==B[35]){ //s3_32 right
print "s3_32 ";
Rightup (); Upleft (); Rightup();
Upleft (); Rightup ();
Upright (); Rightdown (); Upright ();
Rightdown (); }
Turnleft (); // adjust status ******
n=n+1;
if (n>10) goto s30 ; //若没成,重做
s35: //**** check finished ************
if (B[24]==B[25]&&B[26]==B[25]&&
B[34]==B[35]&&B[36]==B[35]&&
B[14]==B[15]&&B[16]==B[15]&&
B[54]==B[55]&&B[56]==B[55]) {
goto s36; }
//else { Upright(); goto s31; }
else { goto s31; }
return;
s36:
cs.SetColor(255,250,250,250);
cs.DrawRect (80,3,720,30); // clear print
s3="《二层四棱》 已完成 ";
print s3;
cs.SetColor (255,250,20,120);
cs.SetTextSize (26);
cs.DrawText (s3,380,25);
cs.Update ();
print "times = ",n ;
print "步数 steps = ", ts+1 ; //使用步数
}//Astep3 ()
Astep2 (){ //上层四角 *************
cs.SetColor(255,250,250,250);
cs.DrawRect (80,3,720,30); // clear print
s5="(2)《上层四角》 do >>>>>> ";
print s5;
cs.SetColor (255,250,20,120);
cs.SetTextSize (26);
cs.DrawText (s5,90,25);
cs.Update ();
n=0; goto s25; //check finished
s21:
//**** under 4 corner to top layer ** state adjust
if (B[23]==B[45]||B[31]==B[45]||B[49]==B[45]){
Downleft (); Rightdown ();
Downright (); Rightup (); } //adjust
if (B[39]==B[45]||B[57]==B[45]||B[69]==B[45]){
if (B[39]==B[25]||B[57]==B[25]||B[69]==B[25]){
if (B[39]==B[35]||B[57]==B[35]||B[69]==B[35]){
Downleft (); } } }
if (B[19]==B[45]||B[27]==B[45]||B[61]==B[45]){
if (B[19]==B[25]||B[27]==B[25]||B[61]==B[25]){
if (B[19]==B[35]||B[27]==B[35]||B[61]==B[35]){
Downright (); } } }
if (B[59]==B[45]||B[17]==B[45]||B[67]==B[45]){
if (B[59]==B[25]||B[17]==B[25]||B[67]==B[25]){
if (B[59]==B[35]||B[17]==B[35]||B[67]==B[35]){
Downleft (); Downleft (); } } }
//**** under 4 corner to top layer ********
if (B[29]==B[45]&&B[37]==B[35]&&B[63]==B[25]){
print "s2_21";
Downleft (); Rightdown ();
Downright (); Rightup (); } //s2_21
if (B[37]==B[45]&&B[29]==B[25]&&B[63]==B[35]){
print " s2_22 ";
Rightdown (); Downleft ();
Rightup (); } //s2_22
if (B[63]==B[45]&&B[29]==B[35]&&B[37]==B[25]){
print "s2_23 ";
Rightdown (); Downleft (); Downleft ();
Rightup (); Downright (); Rightdown ();
Downleft (); Rightup (); } //s2_23
Turnleft ();
Downleft ();
n=n+1;
s25: //**** check finished ************
if (B[41]==B[45]&&B[43]==B[45]&&
B[47]==B[45]&&B[49]==B[45]){
goto s26; } else { goto s21; }
return;
s26:
cs.SetColor(255,250,250,250);
cs.DrawRect (80,3,720,30); // clear print
s3="《上层四角》 已完成 ";
print s3;
cs.SetColor (255,250,20,120);
cs.SetTextSize (26);
cs.DrawText (s3,380,25);
cs.Update ();
print "times = ", n ;
print "步数 steps = ", ts+1 ; //使用步数
}//Astep2 ()
Astep1 (){ //上层四棱 ***********
cs.SetColor(255,250,250,250);
cs.DrawRect (80,3,720,30); // clear print
s5="(1)《上层四棱》 do >>>>>> ";
print s5;
cs.SetColor (255,250,20,120);
cs.SetTextSize (26);
cs.DrawText (s5,90,25);
cs.Update ();
n=0;
s11: //**** top 4 edge to under
if (B[12]==B[45]){
Leftdown(); Upright(); Frontleft(); }
if (B[22]==B[45]){
Frontleft() ; Upleft(); Leftdown(); }
if (B[32]==B[45]){
Rightdown(); Upleft(); Frontright(); }
if (B[52]==B[45]){
Backleft (); Upleft(); Rightup(); }
if (B[42]==B[45]){
Backleft (); Backleft (); }
if (B[44]==B[45]){
Leftdown (); Leftdown (); }
if (B[46]==B[45]){
Rightdown(); Rightdown (); }
if (B[48]==B[45]){
Frontleft(); Frontleft (); }
//return;
s12: //**** under layer 4 edges to top ****
if (B[66]==B[45]&&B[38]==B[35]){
Rightup(); Rightup (); }
if (B[68]==B[45]&&B[58]==B[55]){
Backleft(); Backleft (); }
if (B[64]==B[45]&&B[18]==B[15]){
Leftup (); Leftup (); }
if (B[62]==B[45]&&B[28]==B[25]){
Frontright (); Frontright (); }
s13: //就位
if (B[66]==B[45]&&B[38]==B[35]){
Rightup(); Rightup (); }
if (B[66]==B[45]&&B[38]==B[25]){
Downleft (); Frontleft (); Frontleft (); }
if (B[66]==B[45]&&B[38]==B[15]){
Downleft (); Downleft (); Leftup (); Leftup (); }
if (B[66]==B[45]&&B[38]==B[55]){
Downright (); Backright (); Backright (); }
Downleft ();
s14: //**** 2 layer 4 edges to under ****
for (i=0;i<4;i++){
if (B[26]==B[45]){
Rightdown (); Downleft (); Rightup (); }
if (B[34]==B[45]){
Frontright (); Downright (); Frontleft (); }
Turnleft (); }
//*** under 4 edges b45 color ****
if (B[38]==B[45]){
Downleft (); Frontleft (); Rightdown ();
Frontright (); }
if (B[58]==B[45]){
Downleft (); Downleft ();
Frontleft (); Rightdown (); Frontright (); }
if (B[28]==B[45]){
Frontleft (); Rightdown (); Frontright (); }
if (B[18]==B[45]){
Downright (); Frontleft (); Rightdown ();
Frontright (); }
if (B[32]==B[45]){
Rightdown (); Frontright (); Downright ();
Frontleft (); }
n=n+1;
if (n>20) goto s16;
s15: //**** check finished ************
if (B[42]==B[45]&&B[44]==B[45]&&
B[46]==B[45]&&B[48]==B[45]){
goto s16; } else { goto s12; }
return;
s16:
cs.SetColor(255,250,250,250);
cs.DrawRect (80,3,720,30); // clear print
s3="《上层四棱》 已完成 ";
print s3;
cs.SetColor (255,250,20,120);
cs.SetTextSize (26);
cs.DrawText (s3,380,25);
cs.Update ();
print "times = ",n;
print "步数 steps = ", ts+1 ; //使用步数
}//Astep1()
switchcolor (){
//颜色设置 set cube 1--6 color
//1. 中蓝 2. 深红 3. 中绿 4. 黄色 5. 橙色 6. 淡粉
//美官方配色:
//1. 橙色 2. 中蓝 3. 深红 4. 黄色 5. 中绿 6. 白色
if (scolor==0){cr1=240; cg1=250; cb1=250; }
if (scolor==1){cr1=250; cg1=150; cb1=0; }
if (scolor==2){cr1=0; cg1=120; cb1=250; }
if (scolor==3){cr1=200; cg1=0; cb1=0; }
if (scolor==4){cr1=250; cg1=220; cb1=0; }
if (scolor==5){cr1=0; cg1=220; cb1=0; }
if (scolor==6){cr1=250; cg1=240; cb1=250; }
//求解 > 加色 0,显示未置色点块
}//switchcolor ()
drawbox (){
//draw out & show user cube ****
setDisplay (1);
cs.SetStrokeWidth(1);
cs.SetColor(255,80,80,80);
cs.DrawRect (10,30,710,730); // box backcolor
cs.SetColor(255,150,150,150); //cross line
cs.DrawLine(360,50,360,700); //center
cs.DrawLine(20,340,700,340); //center
cs.SetStrokeWidth(2);
for (j=0;j<80;j++){ //draw up cube ****
scolor=B[41];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u1
cs.DrawLine (280+j,140+j/2,360+j,100+j/2);
scolor=B[42];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u2
cs.DrawLine (360+j,180+j/2,440+j,140+j/2);
scolor=B[43];
switchcolor (); //界面块颜色设置
cs.SetColor(255,cr1,cg1,cb1); //u3
cs.DrawLine (440+j,220+j/2,520+j,180+j/2);
scolor=B[44];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u4
cs.DrawLine (200+j,180+j/2,280+j,140+j/2);
scolor=B[45];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u5
cs.DrawLine (280+j,220+j/2,360+j,180+j/2);
scolor=B[46];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u6
cs.DrawLine (360+j,260+j/2,440+j,220+j/2);
scolor=B[47];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u7
cs.DrawLine (120+j,220+j/2,200+j,180+j/2);
scolor=B[48];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u8
cs.DrawLine (200+j,260+j/2,280+j,220+j/2);
scolor=B[49];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u9
cs.DrawLine (280+j,300+j/2,360+j,260+j/2);
}
//draw right cube ******
for (j=0;j<80;j++){ //draw right cube ****
scolor=B[31];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //r1
cs.DrawLine (360+j,340-j/2,360+j,420-j/2);
scolor=B[32];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //r2
cs.DrawLine (440+j,300-j/2,440+j,380-j/2);
scolor=B[33];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //r3
cs.DrawLine (520+j,260-j/2,520+j,340-j/2);
scolor=B[34];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //r4
cs.DrawLine (360+j,420-j/2,360+j,500-j/2);
scolor=B[35];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //r5
cs.DrawLine (440+j,380-j/2,440+j,460-j/2);
scolor=B[36];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //r6
cs.DrawLine (520+j,340-j/2,520+j,420-j/2);
scolor=B[37];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //r7
cs.DrawLine (360+j,500-j/2,360+j,580-j/2);
scolor=B[38];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //r8
cs.DrawLine (440+j,460-j/2,440+j,540-j/2);
scolor=B[39];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //r9
cs.DrawLine (520+j,420-j/2,520+j,500-j/2);
}
//draw front cube ******
for (j=0;j<80;j++){ //draw front cube
scolor=B[21];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //f1
cs.DrawLine (120+j,220+j/2,120+j,300+j/2);
scolor=B[22];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //f2
cs.DrawLine (200+j,260+j/2,200+j,340+j/2);
scolor=B[23];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //f3
cs.DrawLine (280+j,300+j/2,280+j,380+j/2);
scolor=B[24];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //f4
cs.DrawLine (120+j,300+j/2,120+j,380+j/2);
scolor=B[25];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //f5
cs.DrawLine (200+j,340+j/2,200+j,420+j/2);
scolor=B[26];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //f6
cs.DrawLine (280+j,380+j/2,280+j,460+j/2);
scolor=B[27];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //f7
cs.DrawLine (120+j,380+j/2,120+j,460+j/2);
scolor=B[28];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //f8
cs.DrawLine (200+j,420+j/2,200+j,500+j/2);
scolor=B[29];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //f9
cs.DrawLine (280+j,460+j/2,280+j,540+j/2);
}
cs.SetStrokeWidth (9);
//square divide lines *********
cs.SetColor(255,240,240,240);
for (i=0;i<4;i++){
cs.DrawLine(360+i*80,339-i*40,360+i*80,581-i*40);
cs.DrawLine(360-i*80,339-i*40,360-i*80,581-i*40);
cs.DrawLine(120+i*80,220+i*40,360+i*80,100+i*40);
cs.DrawLine(360-i*80,100+i*40,600-i*80,220+i*40);
cs.DrawLine(120,220+i*80,360,340+i*80);
cs.DrawLine(360,340+i*80,600,220+i*80);
}
cs.SetStrokeWidth (1);
//square divide lines *********
cs.SetColor(255,0,0,0);
for (i=1;i<3;i++){
cs.DrawLine(360+i*80,341-i*40,360+i*80,584-i*40);
cs.DrawLine(360-i*80,341-i*40,360-i*80,584-i*40);
cs.DrawLine(121+i*80,219+i*40,360+i*80,100+i*40);
cs.DrawLine(361-i*80,100+i*40,600-i*80,220+i*40);
cs.DrawLine(120,220+i*80,359,340+i*80);
cs.DrawLine(361,340+i*80,600,220+i*80);
}
cs.SetColor(255,240,240,240);
cs.DrawCircle (121,221,5);
cs.DrawCircle (121,460,5);
cs.DrawCircle (600,221,5);
cs.DrawCircle (600,459,5);
cs.DrawCircle (360,101,5);
cs.DrawCircle (360,579,5);
//draw left back down cube figuer ********
cs.SetTextSize (32);
cs.SetColor (255,250,250,20);
cs.DrawText ("Left ",185,150);
cs.DrawText ("Back ",470,150);
cs.DrawText ("Down ",175,555);
cs.DrawText ("Right ",612,350);
cs.DrawText ("Front ",30,350);
cs.DrawText ("Up ",340,80);
cs.SetColor (255,50,50,50); //left cube
cs.DrawRect (18,38,170,190);
scolor=B[11];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //L1
cs.DrawRect (20,40,68,88);
cs.DrawRect (349,630,362,643);
scolor=B[12];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //L2
cs.DrawRect (70,40,118,88);
cs.DrawRect (364,630,377,643);
scolor=B[13];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //L3
cs.DrawRect (120,40,168,88);
cs.DrawRect (379,630,392,643);
scolor=B[14];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //L4
cs.DrawRect (20,90,68,138);
cs.DrawRect (349,645,362,658);
scolor=B[15];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //L5
cs.DrawRect (70,90,118,138);
cs.DrawRect (364,645,377,658);
scolor=B[16];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //L6
cs.DrawRect (120,90,168,138);
cs.DrawRect (379,645,392,658);
scolor=B[17];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //L7
cs.DrawRect (20,140,68,188);
cs.DrawRect (349,660,362,673);
scolor=B[18];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //L8
cs.DrawRect (70,140,118,188);
cs.DrawRect (364,660,377,673);
scolor=B[19];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //L9
cs.DrawRect (120,140,168,188);
cs.DrawRect (379,660,392,673);
scolor=B[31]; //right cube
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //r1
cs.DrawRect (450,630,463,643);
scolor=B[32];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //r2
cs.DrawRect (465,630,478,643);
scolor=B[33];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //r3
cs.DrawRect (480,630,493,643);
scolor=B[34];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //r4
cs.DrawRect (450,645,463,658);
scolor=B[35];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //r5
cs.DrawRect (465,645,478,658);
scolor=B[36];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //r6
cs.DrawRect (480,645,493,658);
scolor=B[37];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //r7
cs.DrawRect (450,660,463,673);
scolor=B[38];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //r8
cs.DrawRect (465,660,478,673);
scolor=B[39];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //r9
cs.DrawRect (480,660,493,673);
cs.SetColor (255,50,50,50); //back cube
cs.DrawRect (548,38,700,190);
scolor=B[51];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //b1
cs.DrawRect (550,40,598,88);
cs.DrawRect (500,630,513,643);
scolor=B[52];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //b2
cs.DrawRect (600,40,648,88);
cs.DrawRect (515,630,528,643);
scolor=B[53];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //b3
cs.DrawRect (650,40,698,88);
cs.DrawRect (530,630,543,643);
scolor=B[54];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //b4
cs.DrawRect (550,90,598,138);
cs.DrawRect (500,645,513,658);
scolor=B[55];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //b5
cs.DrawRect (600,90,648,138);
cs.DrawRect (515,645,528,658);
scolor=B[56];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //b6
cs.DrawRect (650,90,698,138);
cs.DrawRect (530,645,543,658);
scolor=B[57];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //b7
cs.DrawRect (550,140,598,188);
cs.DrawRect (500,660,513,673);
scolor=B[58];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //b8
cs.DrawRect (600,140,648,188);
cs.DrawRect (515,660,528,673);
scolor=B[59];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //b9
cs.DrawRect (650,140,698,188);
cs.DrawRect (530,660,543,673);
cs.SetColor (255,50,50,50); //down cube
cs.DrawRect (138,563,290,715);
scolor=B[61];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //d1
cs.DrawRect (140,565,188,613);
cs.DrawRect (400,680,413,693);
scolor=B[62];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //d2
cs.DrawRect (190,565,238,613);
cs.DrawRect (415,680,428,693);
scolor=B[63];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //d3
cs.DrawRect (240,565,288,613);
cs.DrawRect (430,680,443,693);
scolor=B[64];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //d4
cs.DrawRect (140,615,188,663);
cs.DrawRect (400,695,413,708);
scolor=B[65];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //d5
cs.DrawRect (190,615,238,663);
cs.DrawRect (415,695,428,708);
scolor=B[66];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //d6
cs.DrawRect (240,615,288,663);
cs.DrawRect (430,695,443,708);
scolor=B[67];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //d7
cs.DrawRect (140,665,188,713);
cs.DrawRect (400,710,413,723);
scolor=B[68];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //d8
cs.DrawRect (190,665,238,713);
cs.DrawRect (415,710,428,723);
scolor=B[69];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //d9
cs.DrawRect (240,665,288,713);
cs.DrawRect (430,710,443,723);
scolor=B[21]; //**** front
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //f1
cs.DrawRect (400,630,412,643);
scolor=B[22];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //f2
cs.DrawRect (415,630,427,643);
scolor=B[23];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //f3
cs.DrawRect (430,630,443,643);
scolor=B[24];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //f4
cs.DrawRect (400,645,412,658);
scolor=B[25];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //f5
cs.DrawRect (415,645,427,658);
scolor=B[26];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //f6
cs.DrawRect (430,645,443,658);
scolor=B[27];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //f7
cs.DrawRect (400,660,412,673);
scolor=B[28];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //f8
cs.DrawRect (415,660,427,673);
scolor=B[29];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //f9
cs.DrawRect (430,660,443,673);
scolor=B[41]; //**** up cube
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u1
cs.DrawRect (400,580,412,593);
scolor=B[42];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u2
cs.DrawRect (415,580,427,593);
scolor=B[43];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u3
cs.DrawRect (430,580,443,593);
scolor=B[44];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u4
cs.DrawRect (400,595,412,608);
scolor=B[45];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u5
cs.DrawRect (415,595,427,608);
scolor=B[46];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u6
cs.DrawRect (430,595,443,608);
scolor=B[47];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u7
cs.DrawRect (400,610,412,623);
scolor=B[48];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u8
cs.DrawRect (415,610,427,623);
scolor=B[49];
switchcolor ();
cs.SetColor(255,cr1,cg1,cb1); //u9
cs.DrawRect (430,610,443,623);
//**********
s="S > "+intToString (ts+1);
cs.SetColor(255,250,250,250);
cs.DrawRect (3,3,80,30);
cs.SetColor(255,0,0,250);
cs.SetTextSize (20);
cs.DrawText (s, 10, 22);
cs.SetColor (255,250,250,250);
cs.SetTextSize (20);
cs.DrawText (tim$, 20, 710);
cs.SetColor (255,50,0,0);
cs.DrawCircle (35,380,15); //BStep1
cs.DrawCircle (35,460,15); //BStep2
//cs.DrawCircle (35,540,15); //BS3
cs.Update ();
}//drawbox () //draw & show cube box
drawButton (){
//** 画操作按钮
//setDisplay(1);
cs.SetStrokeWidth(2);
cs.SetFillMode (1);
cs.SetColor(255,250,250,250);
cs.DrawRect (0,2,720,30); // clear print x y
cs.SetColor(255,80,190,180);
cs.DrawRect (0,740,720,995); // btn backcolor
cs.SetColor(255,180,250,250);
cs.SetTextSize (28);
ss1="编译人:张纯叔 ( micelu@126.com ) ";
cs.DrawText (ss1,20,1020);
dy=800; //draw button bn1 - bn12
for (i=0;i<2;i++){
cs.SetColor(255,240,200,20); //big 2B
cs.DrawCircle (480+i*120,800,38);
cs.DrawCircle (518+i*120,800,38);
cs.SetColor(255,0,0,250);
cs.DrawCircle (482+i*120,800,35);
cs.DrawCircle (516+i*120,800,35); }
cs.SetColor(255,240,200,20); //big B
cs.DrawCircle (540,900,42);
cs.DrawCircle (574,900,42);
cs.SetColor(255,0,0,250);
cs.DrawCircle (542,900,38);
cs.DrawCircle (572,900,38);
dy=850;
cs.SetColor(255,240,200,20); //small B
cs.DrawCircle (50,dy-40,27);
cs.DrawRect (50,dy-68,105,dy-13);
cs.DrawCircle (50,dy+20,27);
cs.DrawRect (50,dy-7,105,dy+48);
cs.DrawCircle (370,dy-40,27);
cs.DrawRect (314,dy-68,370,dy-13);
cs.DrawCircle (370,dy+20,27);
cs.DrawRect (314,dy-7,370,dy+48);
cs.DrawCircle (50,dy+100,27);
cs.DrawRect (50,dy+73,105,dy+128);
cs.DrawCircle (370,dy+100,27);
cs.DrawRect (314,dy+73,370,dy+128);
cs.SetColor(255,0,0,250); //small B center
cs.DrawCircle (50,dy-40,25);
cs.DrawRect (48,dy-66,101,dy-15);
cs.DrawCircle (50,dy+20,25);
cs.DrawRect (48,dy-5,101,dy+46);
cs.DrawCircle (370,dy-40,25);
cs.DrawRect (318,dy-66,368,dy-15);
cs.DrawCircle (370,dy+20,25);
cs.DrawRect (318,dy-5,368,dy+46);
cs.DrawCircle (50,dy+100,25);
cs.DrawRect (50,dy+75,101,dy+126);
cs.DrawCircle (370,dy+100,25);
cs.DrawRect (318,dy+75,368,dy+126);
for (i=0;i<3;i++){ //small 6B
cs.SetColor(255,240,200,20); //small B
cs.DrawCircle (150,dy-70+i*70,27);
cs.DrawRect (150,dy-97+i*70,205,dy-42+i*70);
cs.DrawCircle (270,dy-70+i*70,27);
cs.DrawRect (214,dy-97+i*70,270,dy-42+i*70);
cs.SetColor(255,0,0,250); //small B
cs.DrawCircle (150,dy-70+i*70,25);
cs.DrawRect (148,dy-95+i*70,201,dy-44+i*70);
cs.DrawCircle (270,dy-70+i*70,25);
cs.DrawRect (218,dy-95+i*70,268,dy-44+i*70);
}
cs.SetColor (255,255,255,20);
cs.SetTextSize (22);
cs.DrawText ("左上 L' ",32,816);
cs.DrawText ("左下 L ",32,877);
cs.DrawText ("后左 B' ",32,958);
cs.DrawText ("右上 R ",325,816);
cs.DrawText ("右下 R' ",325,877);
cs.DrawText ("后右 B ",325,958);
cs.DrawText ("上左 U ",132,788);
cs.DrawText ("上右 U' ",224,788);
cs.DrawText ("前左 F' ",132,858);
cs.DrawText ("前右 F ",224,858);
cs.DrawText ("下左 D' ",132,928);
cs.DrawText ("下右 D ",224,928);
cs.SetTextSize (26);
cs.DrawText ("左旋转 ",460,808);
cs.DrawText ("右旋转 ",582,808);
cs.DrawText ("翻 转 ",526,908);
cs.Update ();
}//drawButton ()
Turnup (){ //向上翻转
sw[1]=B[21]; //temp
sw[2]=B[22];
sw[3]=B[23];
sw[4]=B[24];
sw[5]=B[25];
sw[6]=B[26];
sw[7]=B[27];
sw[8]=B[28];
sw[9]=B[29];
B[21]=B[61];
B[22]=B[62];
B[23]=B[63];
B[24]=B[64];
B[25]=B[65];
B[26]=B[66];
B[27]=B[67];
B[28]=B[68];
B[29]=B[69];
B[61]=B[59];
B[62]=B[58];
B[63]=B[57];
B[64]=B[56];
B[65]=B[55];
B[66]=B[54];
B[67]=B[53];
B[68]=B[52];
B[69]=B[51];
B[59]=B[41];
B[58]=B[42];
B[57]=B[43];
B[56]=B[44];
B[55]=B[45];
B[54]=B[46];
B[53]=B[47];
B[52]=B[48];
B[51]=B[49];
B[41]=sw[1];
B[42]=sw[2];
B[43]=sw[3];
B[44]=sw[4];
B[45]=sw[5];
B[46]=sw[6];
B[47]=sw[7];
B[48]=sw[8];
B[49]=sw[9];
sw[1]=B[11];
B[11]=B[13];
B[13]=B[19];
B[19]=B[17];
B[17]=sw[1];
sw[2]=B[12];
B[12]=B[16];
B[16]=B[18];
B[18]=B[14];
B[14]=sw[2];
sw[1]=B[31];
B[31]=B[37];
B[37]=B[39];
B[39]=B[33];
B[33]=sw[1];
sw[2]=B[32];
B[32]=B[34];
B[34]=B[38];
B[38]=B[36];
B[36]=sw[2];
ts=ts+1;
if (St==1) drawbox ();
dat[ts]="Tf";
print "do> Turn Up ";
}//Turnup ()
Turnright (){ //右旋转
sw[1]=B[21];
sw[2]=B[22];
sw[3]=B[23];
sw[4]=B[24];
sw[5]=B[25];
sw[6]=B[26];
sw[7]=B[27];
sw[8]=B[28];
sw[9]=B[29];
B[21]=B[11];
B[22]=B[12];
B[23]=B[13];
B[24]=B[14];
B[25]=B[15];
B[26]=B[16];
B[27]=B[17];
B[28]=B[18];
B[29]=B[19];
B[11]=B[51];
B[12]=B[52];
B[13]=B[53];
B[14]=B[54];
B[15]=B[55];
B[16]=B[56];
B[17]=B[57];
B[18]=B[58];
B[19]=B[59];
B[51]=B[31];
B[52]=B[32];
B[53]=B[33];
B[54]=B[34];
B[55]=B[35];
B[56]=B[36];
B[57]=B[37];
B[58]=B[38];
B[59]=B[39];
B[31]=sw[1];
B[32]=sw[2];
B[33]=sw[3];
B[34]=sw[4];
B[35]=sw[5];
B[36]=sw[6];
B[37]=sw[7];
B[38]=sw[8];
B[39]=sw[9];
sw[1]=B[41];
B[41]=B[43];
B[43]=B[49];
B[49]=B[47];
B[47]=sw[1];
sw[2]=B[42];
B[42]=B[46];
B[46]=B[48];
B[48]=B[44];
B[44]=sw[2];
sw[1]=B[61];
B[61]=B[67];
B[67]=B[69];
B[69]=B[63];
B[63]=sw[1];
sw[2]=B[62];
B[62]=B[64];
B[64]=B[68];
B[68]=B[66];
B[66]=sw[2];
ts=ts+1;
if (St==1) drawbox ();
dat[ts]="TR";
print "do> Turn right ";
}//Turnright ()
Turnleft (){ //左旋转
sw[1]=B[21];
sw[2]=B[22];
sw[3]=B[23];
sw[4]=B[24];
sw[5]=B[25];
sw[6]=B[26];
sw[7]=B[27];
sw[8]=B[28];
sw[9]=B[29];
B[21]=B[31];
B[22]=B[32];
B[23]=B[33];
B[24]=B[34];
B[25]=B[35];
B[26]=B[36];
B[27]=B[37];
B[28]=B[38];
B[29]=B[39];
B[31]=B[51];
B[32]=B[52];
B[33]=B[53];
B[34]=B[54];
B[35]=B[55];
B[36]=B[56];
B[37]=B[57];
B[38]=B[58];
B[39]=B[59];
B[51]=B[11];
B[52]=B[12];
B[53]=B[13];
B[54]=B[14];
B[55]=B[15];
B[56]=B[16];
B[57]=B[17];
B[58]=B[18];
B[59]=B[19];
B[11]=sw[1];
B[12]=sw[2];
B[13]=sw[3];
B[14]=sw[4];
B[15]=sw[5];
B[16]=sw[6];
B[17]=sw[7];
B[18]=sw[8];
B[19]=sw[9];
sw[1]=B[41];
B[41]=B[47];
B[47]=B[49];
B[49]=B[43];
B[43]=sw[1];
sw[2]=B[42];
B[42]=B[44];
B[44]=B[48];
B[48]=B[46];
B[46]=sw[2];
sw[1]=B[61];
B[61]=B[63];
B[63]=B[69];
B[69]=B[67];
B[67]=sw[1];
sw[2]=B[62];
B[62]=B[66];
B[66]=B[68];
B[68]=B[64];
B[64]=sw[2];
ts=ts+1;
if (St==1) drawbox ();
dat[ts]="TL";
print "do> Turn left ";
}//Turnleft ()
Downleft (){ //下左 D1
sw[1]=B[27];
sw[2]=B[28];
sw[3]=B[29];
B[27]=B[37];
B[28]=B[38];
B[29]=B[39];
B[37]=B[57];
B[38]=B[58];
B[39]=B[59];
B[57]=B[17];
B[58]=B[18];
B[59]=B[19];
B[17]=sw[1];
B[18]=sw[2];
B[19]=sw[3];
sw[1]=B[61];
B[61]=B[63];
B[63]=B[69];
B[69]=B[67];
B[67]=sw[1];
sw[2]=B[62];
B[62]=B[66];
B[66]=B[68];
B[68]=B[64];
B[64]=sw[2];
ts=ts+1;
if (St==1) drawbox ();
dat[ts]="D1";
print "do> D' Down left ";
}//Downleft()
Downright (){ //下右 D
sw[1]=B[27];
sw[2]=B[28];
sw[3]=B[29];
B[27]=B[17];
B[28]=B[18];
B[29]=B[19];
B[17]=B[57];
B[18]=B[58];
B[19]=B[59];
B[57]=B[37];
B[58]=B[38];
B[59]=B[39];
B[37]=sw[1];
B[38]=sw[2];
B[39]=sw[3];
sw[1]=B[61];
B[61]=B[67];
B[67]=B[69];
B[69]=B[63];
B[63]=sw[1];
sw[2]=B[62];
B[62]=B[64];
B[64]=B[68];
B[68]=B[66];
B[66]=sw[2];
ts=ts+1;
if (St==1) drawbox ();
dat[ts]="D0";
print "do> D Down right ";
}//Downright()
Backleft (){ //后左 B1
sw[1]=B[41];
sw[2]=B[42];
sw[3]=B[43];
B[41]=B[17];
B[42]=B[14];
B[43]=B[11];
B[17]=B[69];
B[14]=B[68];
B[11]=B[67];
B[69]=B[33];
B[68]=B[36];
B[67]=B[39];
B[33]=sw[1];
B[36]=sw[2];
B[39]=sw[3];
sw[1]=B[51];
B[51]=B[53];
B[53]=B[59];
B[59]=B[57];
B[57]=sw[1];
sw[2]=B[52];
B[52]=B[56];
B[56]=B[58];
B[58]=B[54];
B[54]=sw[2];
ts=ts+1;
if (St==1) drawbox ();
dat[ts]="B1";
print "do> B' Back left ";
}//Backleft()
Backright (){ //后右 B
sw[1]=B[41];
sw[2]=B[42];
sw[3]=B[43];
B[41]=B[33];
B[42]=B[36];
B[43]=B[39];
B[33]=B[69];
B[36]=B[68];
B[39]=B[67];
B[69]=B[17];
B[68]=B[14];
B[67]=B[11];
B[17]=sw[1];
B[14]=sw[2];
B[11]=sw[3];
sw[1]=B[51];
B[51]=B[57];
B[57]=B[59];
B[59]=B[53];
B[53]=sw[1];
sw[2]=B[52];
B[52]=B[54];
B[54]=B[58];
B[58]=B[56];
B[56]=sw[2];
ts=ts+1;
if (St==1) drawbox ();
dat[ts]="B0";
print "do> B Back right ";
}//Backright()
Frontleft (){ //前左 F1
sw[1]=B[47];
sw[2]=B[48];
sw[3]=B[49];
B[47]=B[31];
B[48]=B[34];
B[49]=B[37];
B[31]=B[63];
B[34]=B[62];
B[37]=B[61];
B[63]=B[19];
B[62]=B[16];
B[61]=B[13];
B[19]=sw[1];
B[16]=sw[2];
B[13]=sw[3];
sw[1]=B[21];
B[21]=B[23];
B[23]=B[29];
B[29]=B[27];
B[27]=sw[1];
sw[2]=B[22];
B[22]=B[26];
B[26]=B[28];
B[28]=B[24];
B[24]=sw[2];
ts=ts+1;
if (St==1) drawbox ();
dat[ts]="F1";
print "do> F' Front left ";
}//Frontleft()
Frontright (){ //前右 F
sw[1]=B[47];
sw[2]=B[48];
sw[3]=B[49];
B[47]=B[19];
B[48]=B[16];
B[49]=B[13];
B[19]=B[63];
B[16]=B[62];
B[13]=B[61];
B[63]=B[31];
B[62]=B[34];
B[61]=B[37];
B[31]=sw[1];
B[34]=sw[2];
B[37]=sw[3];
sw[1]=B[21];
B[21]=B[27];
B[27]=B[29];
B[29]=B[23];
B[23]=sw[1];
sw[2]=B[22];
B[22]=B[24];
B[24]=B[28];
B[28]=B[26];
B[26]=sw[2];
ts=ts+1;
// if (St==1)
// drawbox ();
dat[ts]="F0";
print "do> F Front right ";
}//Frontright()
Upleft (){ //上左 U
sw[1]=B[21];
sw[2]=B[22];
sw[3]=B[23];
B[21]=B[31];
B[22]=B[32];
B[23]=B[33];
B[31]=B[51];
B[32]=B[52];
B[33]=B[53];
B[51]=B[11];
B[52]=B[12];
B[53]=B[13];
B[11]=sw[1];
B[12]=sw[2];
B[13]=sw[3];
sw[1]=B[41];
B[41]=B[47];
B[47]=B[49];
B[49]=B[43];
B[43]=sw[1];
sw[2]=B[42];
B[42]=B[44];
B[44]=B[48];
B[48]=B[46];
B[46]=sw[2];
ts=ts+1;
if (St==1) drawbox ();
dat[ts]="U0";
print "do> U Up left ";
}//Upleft()
Upright (){ //上右 U1
sw[1]=B[21];
sw[2]=B[22];
sw[3]=B[23];
B[21]=B[11];
B[22]=B[12];
B[23]=B[13];
B[11]=B[51];
B[12]=B[52];
B[13]=B[53];
B[51]=B[31];
B[52]=B[32];
B[53]=B[33];
B[31]=sw[1];
B[32]=sw[2];
B[33]=sw[3];
sw[1]=B[41];
B[41]=B[43];
B[43]=B[49];
B[49]=B[47];
B[47]=sw[1];
sw[2]=B[42];
B[42]=B[46];
B[46]=B[48];
B[48]=B[44];
B[44]=sw[2];
ts=ts+1;
if (St==1) drawbox ();
dat[ts]="U1";
print "do> U' Up right ";
}//Upright ()
Rightdown (){ //右下 R1
sw[1]=B[23];
sw[2]=B[26];
sw[3]=B[29];
B[23]=B[43];
B[26]=B[46];
B[29]=B[49];
B[43]=B[57];
B[46]=B[54];
B[49]=B[51];
B[57]=B[63];
B[54]=B[66];
B[51]=B[69];
B[63]=sw[1];
B[66]=sw[2];
B[69]=sw[3];
sw[1]=B[31];
B[31]=B[33];
B[33]=B[39];
B[39]=B[37];
B[37]=sw[1];
sw[2]=B[32];
B[32]=B[36];
B[36]=B[38];
B[38]=B[34];
B[34]=sw[2];
ts=ts+1;
if (St==1) drawbox ();
dat[ts]="R1";
print "do> R' Right down ";
}//Rightdown()
Rightup (){ //右上 R
sw[1]=B[23];
sw[2]=B[26];
sw[3]=B[29];
B[23]=B[63];
B[26]=B[66];
B[29]=B[69];
B[63]=B[57];
B[66]=B[54];
B[69]=B[51];
B[57]=B[43];
B[54]=B[46];
B[51]=B[49];
B[43]=sw[1];
B[46]=sw[2];
B[49]=sw[3];
sw[1]=B[31];
B[31]=B[37];
B[37]=B[39];
B[39]=B[33];
B[33]=sw[1];
sw[2]=B[32];
B[32]=B[34];
B[34]=B[38];
B[38]=B[36];
B[36]=sw[2];
ts=ts+1;
if (St==1) drawbox ();
dat[ts]="R0";
print "do> R Right up ";
}//Rightup()
Leftdown (){ //左下 L
sw[1]=B[21];
sw[2]=B[24];
sw[3]=B[27];
B[21]=B[41];
B[24]=B[44];
B[27]=B[47];
B[41]=B[59];
B[44]=B[56];
B[47]=B[53];
B[59]=B[61];
B[56]=B[64];
B[53]=B[67];
B[61]=sw[1];
B[64]=sw[2];
B[67]=sw[3];
sw[1]=B[11];
B[11]=B[17];
B[17]=B[19];
B[19]=B[13];
B[13]=sw[1];
sw[2]=B[12];
B[12]=B[14];
B[14]=B[18];
B[18]=B[16];
B[16]=sw[2];
ts=ts+1;
if (St==1) drawbox ();
dat[ts]="L0";
print "do> L Left down ";
}//Leftdown()
Leftup (){ //左上 L1
sw[1]=B[21];
sw[2]=B[24];
sw[3]=B[27];
B[21]=B[61];
B[24]=B[64];
B[27]=B[67];
B[61]=B[59];
B[64]=B[56];
B[67]=B[53];
B[59]=B[41];
B[56]=B[44];
B[53]=B[47];
B[41]=sw[1];
B[44]=sw[2];
B[47]=sw[3];
sw[1]=B[11];
B[11]=B[13];
B[13]=B[19];
B[19]=B[17];
B[17]=sw[1];
sw[2]=B[12];
B[12]=B[16];
B[16]=B[18];
B[18]=B[14];
B[14]=sw[2];
ts=ts+1;
if (St==1) drawbox ();
dat[ts]="L1";
print "do> L' Left up ";
}//Leftup()
newgame (){
//打乱魔方,可依机器速度增加次数
restore(); //restore cube & draw button
Rn=(int)(random ()*5+1) ;
for (t=0; t<Rn+8; t++){
for (i=0; i<4; i++){
Rn=(int)(random()*11+1); //打乱 random bn
if (Rn==1){Leftup (); }
if (Rn==2){Leftdown (); }
if (Rn==3){Rightup (); }
if (Rn==4){Rightdown (); }
if (Rn==5){Upleft (); }
if (Rn==6){Upright (); }
if (Rn==7){Frontleft (); }
if (Rn==8){Frontright (); }
if (Rn==9){Backleft (); }
if (Rn==10){Backright (); }
if (Rn==11){Downleft (); }
if (Rn==12){Downright (); }
} }
Turnup (); //起首白色置上
Turnup ();
drawbox (); //draw out user cube
clearOutput (); //去除打乱魔方的走步记录
//********
s3="开始游戏 ";
getTime (tim);
newhh=tim[0];
newmm=tim[1];
newss=tim[2];
oldhh=newhh;
oldmm=newmm;
oldss=newss;
hhts=intToString (tim[0]);
mmts=intToString (tim[1]);
ssts=intToString (tim[2]);
if (newhh<10)hhts="0"+hhts;
if (newmm<10)mmts="0"+mmts;
if (newss<10)ssts="0"+ssts;
ss2=hhts+" : "+mmts+" : "+ssts;
print "开始时间:"+ss2;
tim$=ss2; //界面打印开始时间
kn=2; //set canvasProc
ts=-1 ; //init step number 记录数据0起
}//newgame ()
restore (){ ///还原为 初始状态
//initlize cube color
for (i=1;i<10;i++){
B[10+i]=1;
B[20+i]=2;
B[30+i]=3;
B[40+i]=4;
B[50+i]=5;
B[60+i]=6; }
drawButton (); //draw button pad
ts=0 ; //init step number
drawbox ();
for (i=0; i<300; i++){ dat[i]=" "; } //init data
}//restore ()
drawcover (){
restore (); //initlize cube
cs.SetTextStyle (1); //正常 粗体 斜体字
cs.SetStrokeWidth (2);
cs.SetTextSize (78);
s="魔方 Magic Cube ";
cs.SetColor (255,250,20,20);
cs.DrawText (s,74,454);
cs.SetTextSize (76);
cs.SetColor (255,160,30,240);
cs.DrawText (s,80,450);
cs.SetFillMode (0);//0不填色,1填色
cs.SetColor (255,250,250,0);
cs.DrawText (s,80,450);
cs.SetTextSize (26);
cs.SetFillMode (1);//0不填色,1填色
cs.SetTextStyle (0); //正常 粗体 斜体字
s="@Copyright version 3.6.1 ";
cs.SetColor (255,250,50,50);
cs.DrawText (s,212,490);
cs.SetTextStyle (0);
cs.Update ();
}//drawcover()
myMenuProc(int nMen,int nContext){
if(nMen==200){
print "开始游戏";
clearOutput ();
newgame(); }
if(nMen==201){
print "上层四棱";
Astep1 (); }
if(nMen==202){
print "上层四角";
Astep2 (); }
if (nMen==203){//
print "二层四棱";
Astep3 (); }
if (nMen==204){//选项
print "顶层十字";
Astep4 (); }
if(nMen==205){//close canvas
print "顶面同色";
Astep5 (); }
if(nMen==206){//show canvas
print "六面同色";
Astep6 (); }
if (nMen==207){//
clearOutput ();
//print "自动演示";
Autoplay (); }
if (nMen==208){//show step data
setDisplay (0); }
if (nMen==209){//show canvas
setDisplay (1); }
if (nMen==210){//exit
clearOutput();
cs.ClearDraw (0,src);
setDisplay (0);
exit (0); }
}//myMenu()
myToolBarProc(int nBtn,int nContext){
if(nBtn==100){//Newgame
clearOutput ();
newgame (); }
if(nBtn==101){//restore cube box
clearOutput ();
restore (); }
if(nBtn==102){//AutoPlay
clearOutput ();
//print "自动演示";
Autoplay (); }
if(nBtn==103){ //显示图板
status=status+1;
if (status>1 ) status=0 ;
if (status==0 ) drawbox () ;
if (status==1 ) seekpad () ;
setDisplay (1); }
if(nBtn==104){//退出程序
clearOutput();
cs.ClearDraw (0,src);
setDisplay (0);
exit (0); }
if(nBtn==105){//版本信息> 切换
mode=mode+1 ;
if (mode>2) mode=0 ;
if (mode==0) drawcover () ; //version
if (mode==1) {status=1; seekpad () ; } // seek
if (mode==2) setDisplay (0) ; } //查看走步
}//my toolbar()
savepic (){ //** 保存图片
filebox.SetTitle("保存图片(*.bmp;*.jpg;*.png)");
filebox.SetFilter(".bmp;.jpg;.png");
filebox.SetMode(1);
filebox.Show();
if(filebox.GetCount()==1){
fname=filebox.GetFileName(0);
cs.SaveBitmap(fname); }
} //savepic ( )
//****