可自动求解的魔法游戏程序(C语言)

我心血来潮在手机上编写了一个玩魔方的游戏程序,前些时在本站发布了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 sBarDes10;

int nBarId10;

string sMenu50;

int nMenu50;

float pi=3.1415926535;

float src4; //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 B70; //1 left 2 front 3 right 4 up 5 back 6 down

int SB70; //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 sw9; //switch Block color

//int donum; //calculate do step number

int n, sn,kn,cando;

double Rn; //random number

int tim3; //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 dat300; //存储解步数据,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

sBarDes0="开始游戏";

nBarId0=100;

sBarDes1="还原魔方";

nBarId1=101;

sBarDes2="自动演示";

nBarId2=102;

sBarDes3="模式切换";

nBarId3=103;

sBarDes4="退出程序";

nBarId4=104;

sBarDes5="AV";

nBarId5=105;

setToolBarHeight(6);

setButtonTextSize(13);

setButtonColor(255,240,240,240);

setButtonTextColor(255,0,0,250);

setToolBar(100,myToolBarProc,sBarDes,nBarId,6);

sMenu0="开始游戏";

nMenu0=200;

sMenu1="第一步:上层四棱";

nMenu1=201;

sMenu2="第二步:上层四角";

nMenu2=202;

sMenu3="第三步:二层四棱";

nMenu3=203;

sMenu4="第四步:顶层十字";

nMenu4=204;

sMenu5="第五步:顶面同色";

nMenu5=205;

sMenu6="第六步:六面同色";

nMenu6=206;

sMenu7="自动演示";

nMenu7=207;

sMenu8="查看走步记录";

nMenu8=208;

sMenu9="显示游戏图板";

nMenu9=209;

sMenu10="退出";

nMenu10=210;

setMenu(200,myMenuProc,sMenu,nMenu,11);

setTitle("魔方 Magic Cube ");

//*****************************

getTime (tim);

oldhh=tim0;

oldmm=tim1;

oldss=tim2;

kn=2;

drawcover (); //版本信息

St=1; // 0 不显示动画,1 显示

for (i=0; i<70; i++){ SBi=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);

SBsn=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);

SBsn=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);

SBsn=scolor1 ;

cs.Update ();

} //D60

//** 操作按钮设置

if (x>540&&x<660&&y>520&&y<580){ //解魔方

for (i=0; i<70; i++){ Bi=SBi ; } //传数据

status=0 ; //游戏模式

for (j=1; j<=6; j++){

for (i=1; i<=9; i++){

kn=j*10+i ;

if (SBkn==0) {

disMsg (0, "缺数据,重置 > ") ;

goto reset ; } //跳出

} } //若有一块未设置则返回补设置

solve () ; } //解魔方

if (x>540&&x<660&&y>620&&y<680){ //重置

for (i=0; i<70; i++){ SBi=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++){ Bi=SBi ; } //传数据

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=SB41;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //u1

cs.DrawRect (170,50,218,98);

scolor=SB42;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //u2

cs.DrawRect (220,50,268,98);

scolor=SB43;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //u3

cs.DrawRect (270,50,318,98);

scolor=SB44;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //u4

cs.DrawRect (170,100,218,148);

scolor=SB45;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //u5

cs.DrawRect (220,100,268,148);

scolor=SB46;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //u6

cs.DrawRect (270,100,318,148);

scolor=SB47;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //u7

cs.DrawRect (170,150,218,198);

scolor=SB48;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //u8

cs.DrawRect (220,150,268,198);

scolor=SB49;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //u9

cs.DrawRect (270,150,318,198);

//**********

//**** Down blocks

scolor=SB61;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //1

cs.DrawRect (170,350,218,398);

scolor=SB62;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //2

cs.DrawRect (220,350,268,398);

scolor=SB63;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //3

cs.DrawRect (270,350,318,398);

scolor=SB64;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //4

cs.DrawRect (170,400,218,448);

scolor=SB65;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //5

cs.DrawRect (220,400,268,448);

scolor=SB66;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //6

cs.DrawRect (270,400,318,448);

scolor=SB67;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //7

cs.DrawRect (170,450,218,498);

scolor=SB68;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //8

cs.DrawRect (220,450,268,498);

scolor=SB69;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //9

cs.DrawRect (270,450,318,498);

//**********

//**** Left blocks

scolor=SB11;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //1

cs.DrawRect (20,200,68,248);

scolor=SB12;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //2

cs.DrawRect (70,200,118,248);

scolor=SB13;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //3

cs.DrawRect (120,200,168,248);

scolor=SB14;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //4

cs.DrawRect (20,250,68,298);

scolor=SB15;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //5

cs.DrawRect (70,250,118,298);

scolor=SB16;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //6

cs.DrawRect (120,250,168,298);

scolor=SB17;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //7

cs.DrawRect (20,300,68,348);

scolor=SB18;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //8

cs.DrawRect (70,300,118,348);

scolor=SB19;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //9

cs.DrawRect (120,300,168,348);

//**********

//**** Front blocks

scolor=SB21;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //1

cs.DrawRect (170,200,218,248);

scolor=SB22;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //2

cs.DrawRect (220,200,268,248);

scolor=SB23;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //3

cs.DrawRect (270,200,318,248);

scolor=SB24;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //4

cs.DrawRect (170,250,218,298);

scolor=SB25;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //5

cs.DrawRect (220,250,268,298);

scolor=SB26;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //6

cs.DrawRect (270,250,318,298);

scolor=SB27;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //7

cs.DrawRect (170,300,218,348);

scolor=SB28;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //8

cs.DrawRect (220,300,268,348);

scolor=SB29;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //9

cs.DrawRect (270,300,318,348);

//**********

//**** Right blocks

scolor=SB31;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //1

cs.DrawRect (320,200,368,248);

scolor=SB32;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //2

cs.DrawRect (370,200,418,248);

scolor=SB33;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //3

cs.DrawRect (420,200,468,248);

scolor=SB34;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //4

cs.DrawRect (320,250,368,298);

scolor=SB35;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //5

cs.DrawRect (370,250,418,298);

scolor=SB36;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //6

cs.DrawRect (420,250,468,298);

scolor=SB37;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //7

cs.DrawRect (320,300,368,348);

scolor=SB38;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //8

cs.DrawRect (370,300,418,348);

scolor=SB39;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //9

cs.DrawRect (420,300,468,348);

//**********

//**** Back blocks

scolor=SB51;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //1

cs.DrawRect (470,200,518,248);

scolor=SB52;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //2

cs.DrawRect (520,200,568,248);

scolor=SB53;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //3

cs.DrawRect (570,200,618,248);

scolor=SB54;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //4

cs.DrawRect (470,250,518,298);

scolor=SB55;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //5

cs.DrawRect (520,250,568,298);

scolor=SB56;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //6

cs.DrawRect (570,250,618,298);

scolor=SB57;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //7

cs.DrawRect (470,300,518,348);

scolor=SB58;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //8

cs.DrawRect (520,300,568,348);

scolor=SB59;

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 (B10+i==B15){ }else{ goto f60; }

if (B20+i==B25){ }else{ goto f60; }

if (B30+i==B35){ }else{ goto f60; }

if (B40+i==B45){ }else{ goto f60; }

if (B50+i==B55){ }else{ goto f60; }

if (B60+i==B65){ }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=tim0;

newmm=tim1;

newss=tim2;

hhts=intToString (tim0);

mmts=intToString (tim1);

ssts=intToString (tim2);

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+dati+" " ; }

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 (B18==B65){

Leftup (); Leftup (); }

if (B28==B65){

Frontright (); Frontright (); }

if (B38==B65){

Rightup (); Rightup (); }

if (B58==B65){

Backright (); Backright (); }

B11:

//**** 底错位白转上 *******

if (B62==B65&&B28 !=B25){

Frontright (); Frontright (); }

if (B64==B65&&B18 !=B15){

Leftup (); Leftup (); }

if (B66==B65&&B38 !=B35){

Rightup (); Rightup (); }

if (B68==B65&&B58 !=B55){

Backright (); Backright (); }

//**** 后2中转上

if (B56==B65||B14==B65){

Leftdown (); Upright (); Leftup (); }

if (B54==B65||B36==B65){

Rightdown (); Upleft (); Rightup (); }

B13: //**** at front 4 edge put it to correct ****

//top 4 edge 有白 to correct

if (B48==B65&&B22==B25){ //FF

Frontright (); Frontright (); }

if (B22==B65&&B48==B25){ //U L F1

Upright(); Leftdown (); Frontleft (); }

if (B48==B65&&B22==B15){ //U L L

Upleft (); Leftdown (); Leftdown (); }

if (B22==B65&&B48==B15){ // F1 L F

Frontleft (); Leftdown (); Frontright (); }

if (B48==B65&&B22==B35){ //U R1 R1

Upright(); Rightdown (); Rightdown (); }

if (B22==B65&&B48==B35){ //F R1 F1

Frontright (); Rightdown (); Frontleft (); }

if (B48==B65&&B22==B55){ //U U B B

Upright(); Upright ();

Backright (); Backright (); }

if (B22==B65&&B48==B55){ //F RR B

Frontright (); Rightup (); Rightup ();

Backright (); }

if (B46==B65&&B32==B25){ //U FF

Upleft (); Frontright (); Frontright (); }

if (B32==B65&&B46==B25){ //R1 F R

Rightdown (); Frontright (); Rightup (); }

if (B46==B65&&B32==B15){ //UU L L

Upleft (); Upleft (); Leftdown (); Leftdown (); }

if (B32==B65&&B46==B15){ //U F1 L F

Upright (); Frontleft ();

Leftdown (); Frontright (); }

if (B46==B65&&B32==B35){ // R R

Rightup (); Rightup (); }

if (B32==B65&&B46==B35){//U F R1 F1

Upright (); Frontright ();

Rightdown (); Frontleft (); }

if (B46==B65&&B32==B55){ //U1 B B

Upleft (); Backright (); Backright (); }

if (B32==B65&&B46==B55){ //R B1 R1

Rightup (); Backleft (); Rightdown (); }

if (B44==B65&&B12==B25){ //U1 FF

Upright (); Frontright (); Frontright (); }

if (B12==B65&&B44==B25){ //L F1 L1

Leftdown (); Frontleft (); Leftup (); }

if (B44==B65&&B12==B15){ // L L

Leftdown (); Leftdown (); }

if (B12==B65&&B44==B15){ //U1 F1 L F

Upleft (); Frontright ();

Leftdown (); Frontleft (); }

if (B44==B65&&B12==B35){ //U1U1 R1R1

Upright (); Upright ();

Rightdown (); Rightdown (); }

if (B12==B65&&B44==B35){ //U1 F R1 F1

Upright (); Frontright ();

Rightdown (); Frontleft (); }

if (B44==B65&&B12==B55){ //U B B

Upright (); Backright (); Backright (); }

if (B12==B65&&B44==B55){ //L1 B L

Leftup (); Backright (); Leftdown (); }

if (B42==B65&&B52==B25){ //UU FF

Upright (); Upright ();

Frontright (); Frontright (); }

if (B52==B65&&B42==B25){ //U1 L F1 L1

Upleft (); Leftdown ();

Frontleft (); Leftup (); }

if (B42==B65&&B52==B15){ //U1 L

Upleft (); Leftdown (); Leftdown (); }

if (B52==B65&&B42==B15){ //B L1 B1

Backright (); Leftup (); Backleft (); }

if (B42==B65&&B52==B35){ //U R R

Upright (); Rightup (); Rightup (); }

if (B52==B65&&B42==B35){ //B1 R B

Backleft (); Rightup (); Backright (); }

if (B42==B65&&B52==B55){ //B B

Backright (); Backright (); }

if (B52==B65&&B42==B55){ //U R B1

Upright (); Rightup (); Backleft (); }

//**** front under edge white to correct

if (B28 !=B25&&B62==B65){ //F F

Frontright (); Frontright (); }

if (B28==B65&&B62==B15){ //F L

Frontleft (); Leftdown (); }

if (B28==B65&&B62==B25){ //F1 L U L1 FF

Frontleft (); Leftup (); Upright (); Leftdown ();

Frontright (); Frontright (); }

if (B28==B65&&B62==B35){ //F1 R1

Frontright (); Rightdown (); }

if (B28==B65&&B62==B55){ //F L1 U L BB

Frontright (); Leftup(); Upright (); Leftdown ();

Backright (); Backright (); }

//2 layer front 2 edge white to correct

if (B34==B65&&B26==B25){ //F

Frontleft (); }

if (B26==B65&&B34==B25){ //R U R1 FF **

Rightup (); Upleft (); Rightdown ();

Frontright (); Frontright (); }

if (B16==B65&&B24==B25){ //F1

Frontright (); }

if (B24==B65&&B16==B25){ //L1 U1 L FF

Leftup(); Upright (); Leftdown ();

Frontleft (); Frontleft (); }

Turnleft ();

n=n+1;

// if (ts>40) goto B16;

B15: //**** check finished ************

if (B62==B65&&B64==B65&&

B66==B65&&B68==B65){

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 (B29==B65||B37==B65||B63==B65){

Rightup(); Upleft (); Rightdown (); }

if (B19==B65||B27==B65||B61==B65){

Frontright (); Upleft (); Frontleft (); }

if (B59==B65||B17==B65||B67==B65){

Leftdown (); Upleft (); Leftup (); }

if (B39==B65||B57==B65||B69==B65){

Backright (); Upleft (); Backleft (); }

B21:

//****adjust this right corner

if (B29==B65||B37==B65||B63 !=B65){

Rightup (); Upleft ();

Rightdown (); } //Upright (); } //未就位

//** adjust 上四角 入巢

if (B33==B65||B51==B65||B43==B65){

if (B33==B25||B51==B25||B43==B25){

if (B33==B35||B51==B35||B43==B35){

Upright (); } } }

if (B13==B65||B21==B65||B47==B65){

if (B13==B25||B21==B25||B47==B25){

if (B13==B35||B21==B35||B47==B35){

Upleft (); } } }

if (B53==B65||B11==B65||B41==B65){

if (B53==B25||B11==B25||B41==B25){

if (B53==B35||B11==B35||B41==B35){

Upleft (); Upleft (); } } }

//**** do it to correct corner

//白上,U1 R1 U R R U1 R1

if (B49==B65&&B23==B35&&B31==B25){

Upright (); Rightdown (); Upleft ();

Rightup (); Rightup (); Upright (); Rightdown();

print "s2_21 : 白上 U1 R1 U R R U1 R1 "; }

//白左 U R U1 R1

if (B23==B65&&B31==B35&&B49==B25){

Upleft (); Rightup (); Upright (); Rightdown ();

print "s2_22 : 白左 U R U1 R1 "; }

//白右 R U R1

if (B31==B65&&B23==B25&&B49==B35){

Rightup (); Upleft (); Rightdown ();

print "s2_23 : 白右 R U R1 "; }

Turnleft ();

n=n+1;

B25: //**** check finished ************

if (B61==B65&&B63==B65&&

B67==B65&&B69==B65){

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 (B12==B15){ //same color edge to back

Turnleft (); }

if (B22==B25){ Turnleft (); Turnleft (); }

if (B32==B35){ 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 (B12==B25){ Upright (); }

if (B32==B25){ Upleft (); }

if (B52==B25){ Upleft (); Upleft (); }

s51:

k=0 ; n=n+1 ; //计算顶面有几角块同色

if (B41==B45) k=k+1 ;

if (B43==B45) k=k+1 ;

if (B47==B45) k=k+1 ;

if (B49==B45) k=k+1 ;

//state 1 > ** adjust status 顶面角块无同色

if (k==0){

if (B23==B45){ Turnleft (); }

if (B33==B45){ Turnleft (); Turnleft (); }

if (B53==B45){ Turnright (); }

if (B13==B45){ }

ms=51; Formula(); } //公式 B

//state 2 > ** adjust status

// 顶面一角块同色,小鱼置左

if (k==1) {

if (B41==B45){ Turnright (); }

if (B43==B45){ Turnleft (); Turnleft (); }

if (B49==B45){ Turnleft (); }

ms=51; Formula(); } //公式 B

//state 3 > ** adjust statue

// 顶面二以上角块同色,另角边色同顶色置前

if (k>1) {

if (B11==B45){ Turnright (); }

if (B31==B45){ Turnleft (); }

if (B51==B45){ Turnleft (); Turnleft (); }

ms=51; Formula(); //公式 B

} //若有2块以上同顶色,同色置前

//**** check finished ************

if (B41==B45&&B42==B45&&

B43==B45&&B44==B45&&

B46==B45&&B47==B45&&

B48==B45&&B49==B45) {

goto s53; } //to next execute

goto s51; //retry ******

return;

//*****************************

//**** sequence C *******

s53:

//**** state adjust

if (B11==B25){ Upright (); }

if (B31==B25){ Upleft (); }

if (B51==B25){ Upleft (); Upleft (); }

//**** 可能此步已完成

//**** check finished ************

if (B41==B45&&B42==B45&&

B43==B45&&B44==B45&&

B46==B45&&B47==B45&&

B48==B45&&B49==B45&&

B11==B15&&B21==B25&&

B31==B35&&B51==B55) {

goto s57; } //finished game

//完成顶面同色,再调整角块,二块同色置前

n=n+1 ;

if (B11==B13){ Turnright (); }

if (B31==B33){ Turnleft (); }

if (B51==B53){ Turnleft (); Turnleft (); }

ms=53; Formula(); //公式 C

//**** check finished ************

if (B41==B45&&B42==B45&&

B43==B45&&B44==B45&&

B46==B45&&B47==B45&&

B48==B45&&B49==B45&&

B11==B15&&B21==B25&&

B31==B35&&B51==B55) {

goto s57; } //finished game

else{ goto s53; } //if not finished then retry

return;

//**** finished ******

s57:

//**** check finished ************

if (B11==B15&&B12==B15&&B13==B15){

if (B21==B25&&B22==B25&&B23==B25){

if (B31==B35&&B32==B35&&B33==B35){

if (B51==B55&&B52==B55&&B53==B55){

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 (B44==B45&&B48==B45){

Upleft (); }

if (B46==B45&&B48==B45){

Upleft (); Upleft (); }

if (B42==B45&&B46==B45){

Upright (); }

if (B44==B45&&B46==B45){

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 (B42==B45&&B44==B45&&

B46==B45&&B48==B45){

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 (B26==B35||B34==B25){

if (B26==B15||B34==B55){

print "s3_31 "; // R' U' R' U' R' U R U R

Rightdown (); Upright (); Rightdown();

Upright (); Rightdown ();

Upleft (); Rightup (); Upleft ();

Rightup (); } } // s3_31

if (B36==B25||B54==B35){

if (B36==B55||B54==B15){

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 (B44==B25&&B12==B35){

Upright (); Upright (); }

if (B44==B55&&B12==B35){

Upright (); Upright (); }

if (B42==B25&&B52==B35){

Upleft (); }

if (B42==B55&&B52==B35){

Upleft (); }

if (B48==B25&&B22==B35){

Upright (); }

if (B48==B55&&B22==B35){

Upright (); }

s32: //do medium layer edges ******

if (B46==B25&&B32==B35){ //s3_31 left

print "s3_31 ";

Rightdown (); Upright (); Rightdown();

Upright (); Rightdown ();

Upleft (); Rightup (); Upleft ();

Rightup (); } //Turnleft (); }

if (B46==B55&&B32==B35){ //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 (B24==B25&&B26==B25&&

B34==B35&&B36==B35&&

B14==B15&&B16==B15&&

B54==B55&&B56==B55) {

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 (B23==B45||B31==B45||B49==B45){

Downleft (); Rightdown ();

Downright (); Rightup (); } //adjust

if (B39==B45||B57==B45||B69==B45){

if (B39==B25||B57==B25||B69==B25){

if (B39==B35||B57==B35||B69==B35){

Downleft (); } } }

if (B19==B45||B27==B45||B61==B45){

if (B19==B25||B27==B25||B61==B25){

if (B19==B35||B27==B35||B61==B35){

Downright (); } } }

if (B59==B45||B17==B45||B67==B45){

if (B59==B25||B17==B25||B67==B25){

if (B59==B35||B17==B35||B67==B35){

Downleft (); Downleft (); } } }

//**** under 4 corner to top layer ********

if (B29==B45&&B37==B35&&B63==B25){

print "s2_21";

Downleft (); Rightdown ();

Downright (); Rightup (); } //s2_21

if (B37==B45&&B29==B25&&B63==B35){

print " s2_22 ";

Rightdown (); Downleft ();

Rightup (); } //s2_22

if (B63==B45&&B29==B35&&B37==B25){

print "s2_23 ";

Rightdown (); Downleft (); Downleft ();

Rightup (); Downright (); Rightdown ();

Downleft (); Rightup (); } //s2_23

Turnleft ();

Downleft ();

n=n+1;

s25: //**** check finished ************

if (B41==B45&&B43==B45&&

B47==B45&&B49==B45){

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 (B12==B45){

Leftdown(); Upright(); Frontleft(); }

if (B22==B45){

Frontleft() ; Upleft(); Leftdown(); }

if (B32==B45){

Rightdown(); Upleft(); Frontright(); }

if (B52==B45){

Backleft (); Upleft(); Rightup(); }

if (B42==B45){

Backleft (); Backleft (); }

if (B44==B45){

Leftdown (); Leftdown (); }

if (B46==B45){

Rightdown(); Rightdown (); }

if (B48==B45){

Frontleft(); Frontleft (); }

//return;

s12: //**** under layer 4 edges to top ****

if (B66==B45&&B38==B35){

Rightup(); Rightup (); }

if (B68==B45&&B58==B55){

Backleft(); Backleft (); }

if (B64==B45&&B18==B15){

Leftup (); Leftup (); }

if (B62==B45&&B28==B25){

Frontright (); Frontright (); }

s13: //就位

if (B66==B45&&B38==B35){

Rightup(); Rightup (); }

if (B66==B45&&B38==B25){

Downleft (); Frontleft (); Frontleft (); }

if (B66==B45&&B38==B15){

Downleft (); Downleft (); Leftup (); Leftup (); }

if (B66==B45&&B38==B55){

Downright (); Backright (); Backright (); }

Downleft ();

s14: //**** 2 layer 4 edges to under ****

for (i=0;i<4;i++){

if (B26==B45){

Rightdown (); Downleft (); Rightup (); }

if (B34==B45){

Frontright (); Downright (); Frontleft (); }

Turnleft (); }

//*** under 4 edges b45 color ****

if (B38==B45){

Downleft (); Frontleft (); Rightdown ();

Frontright (); }

if (B58==B45){

Downleft (); Downleft ();

Frontleft (); Rightdown (); Frontright (); }

if (B28==B45){

Frontleft (); Rightdown (); Frontright (); }

if (B18==B45){

Downright (); Frontleft (); Rightdown ();

Frontright (); }

if (B32==B45){

Rightdown (); Frontright (); Downright ();

Frontleft (); }

n=n+1;

if (n>20) goto s16;

s15: //**** check finished ************

if (B42==B45&&B44==B45&&

B46==B45&&B48==B45){

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=B41;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //u1

cs.DrawLine (280+j,140+j/2,360+j,100+j/2);

scolor=B42;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //u2

cs.DrawLine (360+j,180+j/2,440+j,140+j/2);

scolor=B43;

switchcolor (); //界面块颜色设置

cs.SetColor(255,cr1,cg1,cb1); //u3

cs.DrawLine (440+j,220+j/2,520+j,180+j/2);

scolor=B44;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //u4

cs.DrawLine (200+j,180+j/2,280+j,140+j/2);

scolor=B45;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //u5

cs.DrawLine (280+j,220+j/2,360+j,180+j/2);

scolor=B46;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //u6

cs.DrawLine (360+j,260+j/2,440+j,220+j/2);

scolor=B47;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //u7

cs.DrawLine (120+j,220+j/2,200+j,180+j/2);

scolor=B48;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //u8

cs.DrawLine (200+j,260+j/2,280+j,220+j/2);

scolor=B49;

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=B31;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //r1

cs.DrawLine (360+j,340-j/2,360+j,420-j/2);

scolor=B32;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //r2

cs.DrawLine (440+j,300-j/2,440+j,380-j/2);

scolor=B33;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //r3

cs.DrawLine (520+j,260-j/2,520+j,340-j/2);

scolor=B34;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //r4

cs.DrawLine (360+j,420-j/2,360+j,500-j/2);

scolor=B35;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //r5

cs.DrawLine (440+j,380-j/2,440+j,460-j/2);

scolor=B36;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //r6

cs.DrawLine (520+j,340-j/2,520+j,420-j/2);

scolor=B37;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //r7

cs.DrawLine (360+j,500-j/2,360+j,580-j/2);

scolor=B38;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //r8

cs.DrawLine (440+j,460-j/2,440+j,540-j/2);

scolor=B39;

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=B21;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //f1

cs.DrawLine (120+j,220+j/2,120+j,300+j/2);

scolor=B22;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //f2

cs.DrawLine (200+j,260+j/2,200+j,340+j/2);

scolor=B23;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //f3

cs.DrawLine (280+j,300+j/2,280+j,380+j/2);

scolor=B24;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //f4

cs.DrawLine (120+j,300+j/2,120+j,380+j/2);

scolor=B25;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //f5

cs.DrawLine (200+j,340+j/2,200+j,420+j/2);

scolor=B26;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //f6

cs.DrawLine (280+j,380+j/2,280+j,460+j/2);

scolor=B27;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //f7

cs.DrawLine (120+j,380+j/2,120+j,460+j/2);

scolor=B28;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //f8

cs.DrawLine (200+j,420+j/2,200+j,500+j/2);

scolor=B29;

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=B11;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //L1

cs.DrawRect (20,40,68,88);

cs.DrawRect (349,630,362,643);

scolor=B12;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //L2

cs.DrawRect (70,40,118,88);

cs.DrawRect (364,630,377,643);

scolor=B13;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //L3

cs.DrawRect (120,40,168,88);

cs.DrawRect (379,630,392,643);

scolor=B14;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //L4

cs.DrawRect (20,90,68,138);

cs.DrawRect (349,645,362,658);

scolor=B15;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //L5

cs.DrawRect (70,90,118,138);

cs.DrawRect (364,645,377,658);

scolor=B16;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //L6

cs.DrawRect (120,90,168,138);

cs.DrawRect (379,645,392,658);

scolor=B17;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //L7

cs.DrawRect (20,140,68,188);

cs.DrawRect (349,660,362,673);

scolor=B18;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //L8

cs.DrawRect (70,140,118,188);

cs.DrawRect (364,660,377,673);

scolor=B19;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //L9

cs.DrawRect (120,140,168,188);

cs.DrawRect (379,660,392,673);

scolor=B31; //right cube

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //r1

cs.DrawRect (450,630,463,643);

scolor=B32;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //r2

cs.DrawRect (465,630,478,643);

scolor=B33;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //r3

cs.DrawRect (480,630,493,643);

scolor=B34;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //r4

cs.DrawRect (450,645,463,658);

scolor=B35;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //r5

cs.DrawRect (465,645,478,658);

scolor=B36;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //r6

cs.DrawRect (480,645,493,658);

scolor=B37;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //r7

cs.DrawRect (450,660,463,673);

scolor=B38;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //r8

cs.DrawRect (465,660,478,673);

scolor=B39;

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=B51;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //b1

cs.DrawRect (550,40,598,88);

cs.DrawRect (500,630,513,643);

scolor=B52;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //b2

cs.DrawRect (600,40,648,88);

cs.DrawRect (515,630,528,643);

scolor=B53;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //b3

cs.DrawRect (650,40,698,88);

cs.DrawRect (530,630,543,643);

scolor=B54;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //b4

cs.DrawRect (550,90,598,138);

cs.DrawRect (500,645,513,658);

scolor=B55;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //b5

cs.DrawRect (600,90,648,138);

cs.DrawRect (515,645,528,658);

scolor=B56;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //b6

cs.DrawRect (650,90,698,138);

cs.DrawRect (530,645,543,658);

scolor=B57;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //b7

cs.DrawRect (550,140,598,188);

cs.DrawRect (500,660,513,673);

scolor=B58;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //b8

cs.DrawRect (600,140,648,188);

cs.DrawRect (515,660,528,673);

scolor=B59;

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=B61;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //d1

cs.DrawRect (140,565,188,613);

cs.DrawRect (400,680,413,693);

scolor=B62;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //d2

cs.DrawRect (190,565,238,613);

cs.DrawRect (415,680,428,693);

scolor=B63;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //d3

cs.DrawRect (240,565,288,613);

cs.DrawRect (430,680,443,693);

scolor=B64;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //d4

cs.DrawRect (140,615,188,663);

cs.DrawRect (400,695,413,708);

scolor=B65;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //d5

cs.DrawRect (190,615,238,663);

cs.DrawRect (415,695,428,708);

scolor=B66;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //d6

cs.DrawRect (240,615,288,663);

cs.DrawRect (430,695,443,708);

scolor=B67;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //d7

cs.DrawRect (140,665,188,713);

cs.DrawRect (400,710,413,723);

scolor=B68;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //d8

cs.DrawRect (190,665,238,713);

cs.DrawRect (415,710,428,723);

scolor=B69;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //d9

cs.DrawRect (240,665,288,713);

cs.DrawRect (430,710,443,723);

scolor=B21; //**** front

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //f1

cs.DrawRect (400,630,412,643);

scolor=B22;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //f2

cs.DrawRect (415,630,427,643);

scolor=B23;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //f3

cs.DrawRect (430,630,443,643);

scolor=B24;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //f4

cs.DrawRect (400,645,412,658);

scolor=B25;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //f5

cs.DrawRect (415,645,427,658);

scolor=B26;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //f6

cs.DrawRect (430,645,443,658);

scolor=B27;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //f7

cs.DrawRect (400,660,412,673);

scolor=B28;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //f8

cs.DrawRect (415,660,427,673);

scolor=B29;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //f9

cs.DrawRect (430,660,443,673);

scolor=B41; //**** up cube

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //u1

cs.DrawRect (400,580,412,593);

scolor=B42;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //u2

cs.DrawRect (415,580,427,593);

scolor=B43;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //u3

cs.DrawRect (430,580,443,593);

scolor=B44;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //u4

cs.DrawRect (400,595,412,608);

scolor=B45;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //u5

cs.DrawRect (415,595,427,608);

scolor=B46;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //u6

cs.DrawRect (430,595,443,608);

scolor=B47;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //u7

cs.DrawRect (400,610,412,623);

scolor=B48;

switchcolor ();

cs.SetColor(255,cr1,cg1,cb1); //u8

cs.DrawRect (415,610,427,623);

scolor=B49;

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 (){ //向上翻转

sw1=B21; //temp

sw2=B22;

sw3=B23;

sw4=B24;

sw5=B25;

sw6=B26;

sw7=B27;

sw8=B28;

sw9=B29;

B21=B61;

B22=B62;

B23=B63;

B24=B64;

B25=B65;

B26=B66;

B27=B67;

B28=B68;

B29=B69;

B61=B59;

B62=B58;

B63=B57;

B64=B56;

B65=B55;

B66=B54;

B67=B53;

B68=B52;

B69=B51;

B59=B41;

B58=B42;

B57=B43;

B56=B44;

B55=B45;

B54=B46;

B53=B47;

B52=B48;

B51=B49;

B41=sw1;

B42=sw2;

B43=sw3;

B44=sw4;

B45=sw5;

B46=sw6;

B47=sw7;

B48=sw8;

B49=sw9;

sw1=B11;

B11=B13;

B13=B19;

B19=B17;

B17=sw1;

sw2=B12;

B12=B16;

B16=B18;

B18=B14;

B14=sw2;

sw1=B31;

B31=B37;

B37=B39;

B39=B33;

B33=sw1;

sw2=B32;

B32=B34;

B34=B38;

B38=B36;

B36=sw2;

ts=ts+1;

if (St==1) drawbox ();

datts="Tf";

print "do> Turn Up ";

}//Turnup ()

Turnright (){ //右旋转

sw1=B21;

sw2=B22;

sw3=B23;

sw4=B24;

sw5=B25;

sw6=B26;

sw7=B27;

sw8=B28;

sw9=B29;

B21=B11;

B22=B12;

B23=B13;

B24=B14;

B25=B15;

B26=B16;

B27=B17;

B28=B18;

B29=B19;

B11=B51;

B12=B52;

B13=B53;

B14=B54;

B15=B55;

B16=B56;

B17=B57;

B18=B58;

B19=B59;

B51=B31;

B52=B32;

B53=B33;

B54=B34;

B55=B35;

B56=B36;

B57=B37;

B58=B38;

B59=B39;

B31=sw1;

B32=sw2;

B33=sw3;

B34=sw4;

B35=sw5;

B36=sw6;

B37=sw7;

B38=sw8;

B39=sw9;

sw1=B41;

B41=B43;

B43=B49;

B49=B47;

B47=sw1;

sw2=B42;

B42=B46;

B46=B48;

B48=B44;

B44=sw2;

sw1=B61;

B61=B67;

B67=B69;

B69=B63;

B63=sw1;

sw2=B62;

B62=B64;

B64=B68;

B68=B66;

B66=sw2;

ts=ts+1;

if (St==1) drawbox ();

datts="TR";

print "do> Turn right ";

}//Turnright ()

Turnleft (){ //左旋转

sw1=B21;

sw2=B22;

sw3=B23;

sw4=B24;

sw5=B25;

sw6=B26;

sw7=B27;

sw8=B28;

sw9=B29;

B21=B31;

B22=B32;

B23=B33;

B24=B34;

B25=B35;

B26=B36;

B27=B37;

B28=B38;

B29=B39;

B31=B51;

B32=B52;

B33=B53;

B34=B54;

B35=B55;

B36=B56;

B37=B57;

B38=B58;

B39=B59;

B51=B11;

B52=B12;

B53=B13;

B54=B14;

B55=B15;

B56=B16;

B57=B17;

B58=B18;

B59=B19;

B11=sw1;

B12=sw2;

B13=sw3;

B14=sw4;

B15=sw5;

B16=sw6;

B17=sw7;

B18=sw8;

B19=sw9;

sw1=B41;

B41=B47;

B47=B49;

B49=B43;

B43=sw1;

sw2=B42;

B42=B44;

B44=B48;

B48=B46;

B46=sw2;

sw1=B61;

B61=B63;

B63=B69;

B69=B67;

B67=sw1;

sw2=B62;

B62=B66;

B66=B68;

B68=B64;

B64=sw2;

ts=ts+1;

if (St==1) drawbox ();

datts="TL";

print "do> Turn left ";

}//Turnleft ()

Downleft (){ //下左 D1

sw1=B27;

sw2=B28;

sw3=B29;

B27=B37;

B28=B38;

B29=B39;

B37=B57;

B38=B58;

B39=B59;

B57=B17;

B58=B18;

B59=B19;

B17=sw1;

B18=sw2;

B19=sw3;

sw1=B61;

B61=B63;

B63=B69;

B69=B67;

B67=sw1;

sw2=B62;

B62=B66;

B66=B68;

B68=B64;

B64=sw2;

ts=ts+1;

if (St==1) drawbox ();

datts="D1";

print "do> D' Down left ";

}//Downleft()

Downright (){ //下右 D

sw1=B27;

sw2=B28;

sw3=B29;

B27=B17;

B28=B18;

B29=B19;

B17=B57;

B18=B58;

B19=B59;

B57=B37;

B58=B38;

B59=B39;

B37=sw1;

B38=sw2;

B39=sw3;

sw1=B61;

B61=B67;

B67=B69;

B69=B63;

B63=sw1;

sw2=B62;

B62=B64;

B64=B68;

B68=B66;

B66=sw2;

ts=ts+1;

if (St==1) drawbox ();

datts="D0";

print "do> D Down right ";

}//Downright()

Backleft (){ //后左 B1

sw1=B41;

sw2=B42;

sw3=B43;

B41=B17;

B42=B14;

B43=B11;

B17=B69;

B14=B68;

B11=B67;

B69=B33;

B68=B36;

B67=B39;

B33=sw1;

B36=sw2;

B39=sw3;

sw1=B51;

B51=B53;

B53=B59;

B59=B57;

B57=sw1;

sw2=B52;

B52=B56;

B56=B58;

B58=B54;

B54=sw2;

ts=ts+1;

if (St==1) drawbox ();

datts="B1";

print "do> B' Back left ";

}//Backleft()

Backright (){ //后右 B

sw1=B41;

sw2=B42;

sw3=B43;

B41=B33;

B42=B36;

B43=B39;

B33=B69;

B36=B68;

B39=B67;

B69=B17;

B68=B14;

B67=B11;

B17=sw1;

B14=sw2;

B11=sw3;

sw1=B51;

B51=B57;

B57=B59;

B59=B53;

B53=sw1;

sw2=B52;

B52=B54;

B54=B58;

B58=B56;

B56=sw2;

ts=ts+1;

if (St==1) drawbox ();

datts="B0";

print "do> B Back right ";

}//Backright()

Frontleft (){ //前左 F1

sw1=B47;

sw2=B48;

sw3=B49;

B47=B31;

B48=B34;

B49=B37;

B31=B63;

B34=B62;

B37=B61;

B63=B19;

B62=B16;

B61=B13;

B19=sw1;

B16=sw2;

B13=sw3;

sw1=B21;

B21=B23;

B23=B29;

B29=B27;

B27=sw1;

sw2=B22;

B22=B26;

B26=B28;

B28=B24;

B24=sw2;

ts=ts+1;

if (St==1) drawbox ();

datts="F1";

print "do> F' Front left ";

}//Frontleft()

Frontright (){ //前右 F

sw1=B47;

sw2=B48;

sw3=B49;

B47=B19;

B48=B16;

B49=B13;

B19=B63;

B16=B62;

B13=B61;

B63=B31;

B62=B34;

B61=B37;

B31=sw1;

B34=sw2;

B37=sw3;

sw1=B21;

B21=B27;

B27=B29;

B29=B23;

B23=sw1;

sw2=B22;

B22=B24;

B24=B28;

B28=B26;

B26=sw2;

ts=ts+1;

// if (St==1)

// drawbox ();

datts="F0";

print "do> F Front right ";

}//Frontright()

Upleft (){ //上左 U

sw1=B21;

sw2=B22;

sw3=B23;

B21=B31;

B22=B32;

B23=B33;

B31=B51;

B32=B52;

B33=B53;

B51=B11;

B52=B12;

B53=B13;

B11=sw1;

B12=sw2;

B13=sw3;

sw1=B41;

B41=B47;

B47=B49;

B49=B43;

B43=sw1;

sw2=B42;

B42=B44;

B44=B48;

B48=B46;

B46=sw2;

ts=ts+1;

if (St==1) drawbox ();

datts="U0";

print "do> U Up left ";

}//Upleft()

Upright (){ //上右 U1

sw1=B21;

sw2=B22;

sw3=B23;

B21=B11;

B22=B12;

B23=B13;

B11=B51;

B12=B52;

B13=B53;

B51=B31;

B52=B32;

B53=B33;

B31=sw1;

B32=sw2;

B33=sw3;

sw1=B41;

B41=B43;

B43=B49;

B49=B47;

B47=sw1;

sw2=B42;

B42=B46;

B46=B48;

B48=B44;

B44=sw2;

ts=ts+1;

if (St==1) drawbox ();

datts="U1";

print "do> U' Up right ";

}//Upright ()

Rightdown (){ //右下 R1

sw1=B23;

sw2=B26;

sw3=B29;

B23=B43;

B26=B46;

B29=B49;

B43=B57;

B46=B54;

B49=B51;

B57=B63;

B54=B66;

B51=B69;

B63=sw1;

B66=sw2;

B69=sw3;

sw1=B31;

B31=B33;

B33=B39;

B39=B37;

B37=sw1;

sw2=B32;

B32=B36;

B36=B38;

B38=B34;

B34=sw2;

ts=ts+1;

if (St==1) drawbox ();

datts="R1";

print "do> R' Right down ";

}//Rightdown()

Rightup (){ //右上 R

sw1=B23;

sw2=B26;

sw3=B29;

B23=B63;

B26=B66;

B29=B69;

B63=B57;

B66=B54;

B69=B51;

B57=B43;

B54=B46;

B51=B49;

B43=sw1;

B46=sw2;

B49=sw3;

sw1=B31;

B31=B37;

B37=B39;

B39=B33;

B33=sw1;

sw2=B32;

B32=B34;

B34=B38;

B38=B36;

B36=sw2;

ts=ts+1;

if (St==1) drawbox ();

datts="R0";

print "do> R Right up ";

}//Rightup()

Leftdown (){ //左下 L

sw1=B21;

sw2=B24;

sw3=B27;

B21=B41;

B24=B44;

B27=B47;

B41=B59;

B44=B56;

B47=B53;

B59=B61;

B56=B64;

B53=B67;

B61=sw1;

B64=sw2;

B67=sw3;

sw1=B11;

B11=B17;

B17=B19;

B19=B13;

B13=sw1;

sw2=B12;

B12=B14;

B14=B18;

B18=B16;

B16=sw2;

ts=ts+1;

if (St==1) drawbox ();

datts="L0";

print "do> L Left down ";

}//Leftdown()

Leftup (){ //左上 L1

sw1=B21;

sw2=B24;

sw3=B27;

B21=B61;

B24=B64;

B27=B67;

B61=B59;

B64=B56;

B67=B53;

B59=B41;

B56=B44;

B53=B47;

B41=sw1;

B44=sw2;

B47=sw3;

sw1=B11;

B11=B13;

B13=B19;

B19=B17;

B17=sw1;

sw2=B12;

B12=B16;

B16=B18;

B18=B14;

B14=sw2;

ts=ts+1;

if (St==1) drawbox ();

datts="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=tim0;

newmm=tim1;

newss=tim2;

oldhh=newhh;

oldmm=newmm;

oldss=newss;

hhts=intToString (tim0);

mmts=intToString (tim1);

ssts=intToString (tim2);

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++){

B10+i=1;

B20+i=2;

B30+i=3;

B40+i=4;

B50+i=5;

B60+i=6; }

drawButton (); //draw button pad

ts=0 ; //init step number

drawbox ();

for (i=0; i<300; i++){ dati=" "; } //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 ( )

//****

相关推荐
小白舒_SC3 小时前
多个VS版本的Qt VS Tools的QtMsBuild不兼容问题
经验分享·qt
2601_951643777 小时前
Python第一,Java跌出前三,C语言杀回来了
java·c语言·python·编程语言排行·技术趋势
AI科技星7 小时前
数术工坊 · 第四卷 橡皮泥江湖(拓扑学)【完整定稿】
c语言·开发语言·汇编·electron·概率论·拓扑学
BomanGe910 小时前
NSK紧凑型精密滚珠丝杠技术手册
经验分享·规格说明书
AI科技星10 小时前
数术工坊第八卷:算力革命
c语言·开发语言·网络·量子计算·agi
卡梅德生物科技小能手11 小时前
卡美德生物科普CD136(RON受体):从基础特性到实验应用
经验分享·深度学习·生活
sweetone11 小时前
SONY老式磁带随身听wm-fx193 之摩机过程(提升重低音音效,改耳放)
经验分享·音视频
.道阻且长.12 小时前
C++ string 操作指南:接口解析
java·c语言·开发语言·c++
上海观智网络12 小时前
上海小程序定制开发合同怎么签?需要注意什么?
经验分享·笔记·小程序
2601_9516457812 小时前
如何优雅地使用c语言编写爬虫
c语言·爬虫·网络请求·字符串处理·cspider