【无标题】用Javascript编写魔方程序(详解)2023-7-4

news2024/11/25 2:37:12

 第一步,先初始化魔方,如上图,可以很直观的看到魔方的6个面。直接贴代码

<!doctype html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
	<meta name="renderer" content="webkit">
	<!-- 引入jquey -->
	<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>


	<style>
		* {
			margin: 0;
			padding: 0;
			list-style: none;
			box-sizing: border-box;
		}

		.container {

			width: 100%;
			height: 380px;
			margin: 10px auto;
		}

		.box {
			left: 10%;
			top: 110px;
			width: 320px;
			perspective: 500px;
			position: relative;
			margin: 0 auto;
		}

		.boxmin {
			left: 25%;
			top: -40%;
			width: 320px;
			perspective: 500px;
			position: relative;
			margin: 0 auto;
			zoom: 51%;
		}


		.content {
			width: 180px;
			height: 180px;
			transform-style: preserve-3d;
			animation: run 10s infinite;
		}

		.face {
			width: 180px;
			height: 180px;
			position: absolute;
			text-align: center;
			line-height: 180px;

		}  

		.minibox {
			width: 54px;
			height: 54px;
			border-radius: 4px;
			float: left;
			border: 3px solid #000;
		}

		.divbuttons {
			height: 60px;
			margin: 10px auto;
			text-align: center;
		}

		.button {
			font-size: xx-large;
			width: 100px;
			padding: 3px;
			margin: 3px;
		}
	</style>
	<script type="text/javascript"> 

		//把数据对应到格子上
		function fillcolor2box(colordata,sidenames) {
			console.log('开始给魔方着色');
			sidenames.map(function (v) {
				var k = sidenames.indexOf(v);
				for (var i = 0; i < 9; i++) {
					// 填充大魔方
					$(".box ." + v + " div").eq(i).css("background", colordata[k][i]);

					// 填充小魔方,便于观察
					if ("aside,bside,fside".split(",").indexOf(v) >= 0) {
						// 小魔方正面透明
						$(".boxmin ." + v + " div").eq(i).css("background", "fixed");
						$(".boxmin .minibox").css("border", "1px solid rgb(138, 135, 135)");
					} else {
						// 背面涂色
						$(".boxmin ." + v + " div").eq(i).css("background", colordata[k][i]);
					} 
				}
			});
		}


		$(function (argument) {

			var colors = ["green", "yellow", "red", "blue", "white", "pink"];
			var sidenames = ["aside", "bside", "cside", "dside", "eside", "fside"];
			var colordata = []; 
			
			for (var i = 0; i < colors.length; i++) {
				// 面
				var tmp = [];
				for (var j = 0; j < 9; j++) {
					// 一面9块
					tmp.push(colors[i]);
				}
				// 往魔方上贴一面的颜色
				colordata.push(tmp);
			}
			console.log('初始化魔方数据',colordata);
			
			fillcolor2box(colordata,sidenames);

			//整体有个旋转角度可以让我们看到3面    
			$(".box .content").css("transform", "rotateX(-35deg) rotateY(54deg) rotateZ(9deg)");
			$(".boxmin .content").css("transform", "rotateX(-35deg) rotateY(67deg) rotateZ(14deg)");
			// 各面旋转拼凑正方体
			$(".bside").css("transform", "rotateY(-90deg) translateX(-71px) translateZ(90px)");
			$(".cside").css("transform", "rotateY(90deg) translateX(90px) translateZ(71px)");
			$(".dside").css("transform", "rotateY(180deg) translateX(17px)   translateZ(161px)");
			$(".eside").css("transform", "rotateX(269deg)  translateY(90px) translateZ(71px) ");
			$(".fside").css("transform", "rotateX(90deg) translateY(-71px) translateZ(90px)");
		});
	</script>
</head>

<body>
	<div class="divbuttons">
		<input type="button" class="button" value="U'" onclick="U1()">
		<input type="button" class="button" value="U" onclick="U()">

	</div>
	<div class="container">
		<!-- 左边两个按钮 -->
		<div class="divbuttons" style="float: left;height: 100%;width: 100px;line-height: 161px;padding: 32px;">
			<input type="button" class="button" value="F'" onclick="F1()">
			<input type="button" class="button" value="F" onclick="F()">
		</div>

		<!-- 正方体 -->
		<div class="box">
			<div class="content">
				<div class="aside face"> <!--魔方第一个面,类名aside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="bside face"> <!--魔方第2个面,类名bside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="cside face"> <!--魔方第3个面,类名cside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="dside face"> <!--魔方第一4个面,类名dside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="eside face"> <!--魔方第5个面,类名eside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="fside face"> <!--魔方第6个面,类名fside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
			</div>
		</div>

		<div class="boxmin">
			<div class="content">
				<div class="aside face"> <!--魔方第一个面,类名aside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="bside face"> <!--魔方第2个面,类名bside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="cside face"> <!--魔方第3个面,类名cside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="dside face"> <!--魔方第一4个面,类名dside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="eside face"> <!--魔方第5个面,类名eside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="fside face"> <!--魔方第6个面,类名fside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
			</div>
		</div>

	</div>
	 

</body>

</html>

接下来,我们需要将魔方打乱,然后完成一些操作的方法。下面都是完整的代码,可以直接用。

你可以尝试点击各个按钮看是否可以正常使用,并核对颜色快。这里最难看的就是旋转的代码块。认真看能看懂。

 

<!doctype html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
	<meta name="renderer" content="webkit">
	<!-- 引入jquey -->
	<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>


	<style>
		* {
			margin: 0;
			padding: 0;
			list-style: none;
			box-sizing: border-box;
		}

		.container {

			width: 100%;
			height: 380px;
			margin: 10px auto;
		}

		.box {
			left: 10%;
			top: 110px;
			width: 320px;
			perspective: 500px;
			position: relative;
			margin: 0 auto;
		}

		.boxmin {
			left: 25%;
			top: -40%;
			width: 320px;
			perspective: 500px;
			position: relative;
			margin: 0 auto;
			zoom: 51%;
		}


		.content {
			width: 180px;
			height: 180px;
			transform-style: preserve-3d;
			animation: run 10s infinite;
		}

		.face {
			width: 180px;
			height: 180px;
			position: absolute;
			text-align: center;
			line-height: 180px;

		}

		.minibox {
			width: 54px;
			height: 54px;
			border-radius: 4px;
			float: left;
			border: 3px solid #000;
		}

		.divbuttons {
			height: 60px;
			margin: 10px auto;
			text-align: center;
		}

		.button {
			font-size: xx-large;
			width: 100px;
			padding: 3px;
			margin: 3px;
		}
	</style>
	<script type="text/javascript">
		var colors = ["green", "yellow", "red", "blue", "white", "pink"];
		var sidenames = ["aside", "bside", "cside", "dside", "eside", "fside"];
		var colordata = [];

		//把数据对应到格子上
		function fillcolor2box() {
			console.log('开始给魔方着色');
			sidenames.map(function (v) {
				var k = sidenames.indexOf(v);
				for (var i = 0; i < 9; i++) {
					// 填充大魔方
					$(".box ." + v + " div").eq(i).css("background", colordata[k][i]);

					// 填充小魔方,便于观察
					if ("aside,bside,fside".split(",").indexOf(v) >= 0) {
						// 小魔方正面透明
						$(".boxmin ." + v + " div").eq(i).css("background", "fixed");
						$(".boxmin .minibox").css("border", "1px solid rgb(138, 135, 135)");
					} else {
						// 背面涂色
						$(".boxmin ." + v + " div").eq(i).css("background", colordata[k][i]);
					}
				}
			});
		}

		function roteall(rotefaces, rotepos, movefave, bno) {
			// 	var rotefaces=['fside','cside','eside','bside','fside']; //本次操作的4个相关面,一个顶面 
			// var rotepos=[[8,7,6],[6,3,0],[0,1,2],[2,5,8],[8,7,6]]; //本次操作的块
			// var movefave = "aside";  //本次操作的4个相关面,一个顶面		
			// var bno = "36785210"; //01258763 36785210


			//为复制先存一个a面的顶上3个块颜色
			var tmpcolordata = [];
			for (var i = 0; i < colordata.length; i++) {
				tmpcolordata.push(colordata[i].concat()); //保存第一个数据
			}

			for (var i = 0; i < rotefaces.length; i++) {  //4个面轮流复制,最后一个面的时候使用保存的数据
				for (var j = 0; j < rotepos[i].length; j++) {
					if (i < 4) {
						colordata[sidenames.indexOf(rotefaces[i + 1])][rotepos[i + 1][j]] =
							tmpcolordata[sidenames.indexOf(rotefaces[i])][rotepos[i][j]];
					}
				}
			}
			tmpcolordata = [];

			//顶面旋转
			for (var k = 0; k < movefave.length; k++) {
				var ci = sidenames.indexOf(movefave[k]);
				var bn = bno[k].split("");// 顶面的操作是这8个格子依次右进3次 "01258763"顺时针
				for (var i = 0; i < 2; i++) {
					var tmp = colordata[ci][bn[0]]; //保存第一个数据
					for (var j = 0; j < bn.length; j++) {
						if (j >= bn.length - 1) {
							colordata[ci][bn[j]] = tmp;
						} else {
							colordata[ci][bn[j]] = colordata[ci][bn[j + 1]];
						}
					}
				}
			}

		}

		// 顶逆
		function U1() {
			var rotefaces = ['aside', 'cside', 'dside', 'bside', 'aside']; //本次操作的4个相关面,一个顶面 
			var rotepos = [[0, 1, 2], [0, 1, 2], [0, 1, 2], [0, 1, 2], [0, 1, 2]]; //本次操作的块
			var movefave = ["fside"];  //本次操作的4个相关面,一个顶面		
			var bno = ["01258763"]; //01258763 36785210
			roteall(rotefaces, rotepos, movefave, bno);

		}
		function U() {
			var rotefaces = ['aside', 'bside', 'dside', 'cside', 'aside']; //本次操作的4个相关面,一个顶面 
			var rotepos = [[0, 1, 2], [0, 1, 2], [0, 1, 2], [0, 1, 2], [0, 1, 2]]; //本次操作的块
			var movefave = ["fside"];  //本次操作的4个相关面,一个顶面		
			var bno = ["36785210"];
			roteall(rotefaces, rotepos, movefave, bno);

		}

		// 前逆
		function F1() {
			var rotefaces = ['aside', 'fside', 'dside', 'eside', 'aside']; //本次操作的4个相关面,一个顶面 
			var rotepos = [[6, 3, 0], [6, 3, 0], [2, 5, 8], [6, 3, 0], [6, 3, 0]]; //本次操作的块
			var movefave = ["bside"];  //本次操作的4个相关面,一个顶面		
			var bno = ["01258763"]; //01258763 36785210
			roteall(rotefaces, rotepos, movefave, bno);

		}
		function F() {
			var rotefaces = ['aside', 'eside', 'dside', 'fside', 'aside']; //本次操作的4个相关面,一个顶面 
			var rotepos = [[6, 3, 0], [6, 3, 0], [2, 5, 8], [6, 3, 0], [6, 3, 0]]; //本次操作的块
			var movefave = ["bside"];  //本次操作的4个相关面,一个顶面		
			var bno = ["36785210"]; //01258763 36785210
			roteall(rotefaces, rotepos, movefave, bno);

		}

		//右逆
		function R1() {
			var rotefaces = ['fside', 'bside', 'eside', 'cside', 'fside']; //本次操作的4个相关面,一个顶面 
			var rotepos = [[8, 7, 6], [2, 5, 8], [0, 1, 2], [6, 3, 0], [8, 7, 6]]; //本次操作的块
			var movefave = ["aside"];  //本次操作的4个相关面,一个顶面		
			var bno = ["01258763"]; //01258763 36785210
			roteall(rotefaces, rotepos, movefave, bno);

		}
		function R() {
			var rotefaces = ['fside', 'cside', 'eside', 'bside', 'fside']; //本次操作的4个相关面,一个顶面 
			var rotepos = [[8, 7, 6], [6, 3, 0], [0, 1, 2], [2, 5, 8], [8, 7, 6]]; //本次操作的块
			var movefave = ["aside"];  //本次操作的4个相关面,一个顶面		
			var bno = ["36785210"]; //01258763 36785210
			roteall(rotefaces, rotepos, movefave, bno);

		}
		// 后逆
		function B1() {
			var rotefaces = ['aside', 'fside', 'dside', 'eside', 'aside']; //本次操作的4个相关面,一个顶面 
			var rotepos = [[2, 5, 8], [2, 5, 8], [6, 3, 0], [2, 5, 8], [2, 5, 8]]; //本次操作的块
			var movefave = ["cside"];  //本次操作的4个相关面,一个顶面		
			var bno = ["36785210"]; //01258763 36785210
			roteall(rotefaces, rotepos, movefave, bno);

		}
		function B() {
			var rotefaces = ['aside', 'eside', 'dside', 'fside', 'aside']; //本次操作的4个相关面,一个顶面 
			var rotepos = [[2, 5, 8], [2, 5, 8], [6, 3, 0], [2, 5, 8], [2, 5, 8]]; //本次操作的块
			var movefave = ["cside"];  //本次操作的4个相关面,一个顶面		
			var bno = ["01258763"]; //01258763 36785210
			roteall(rotefaces, rotepos, movefave, bno);

		}

		// 整体顶逆
		function U1all() {
			var rotefaces = ['aside', 'cside', 'dside', 'bside', 'aside']; //本次操作的4个相关面,一个顶面 
			var rotepos = [[0, 1, 2, 3, 4, 5, 6, 7, 8], [0, 1, 2, 3, 4, 5, 6, 7, 8], [0, 1, 2, 3, 4, 5, 6, 7, 8], [0, 1, 2, 3, 4, 5, 6, 7, 8], [0, 1, 2, 3, 4, 5, 6, 7, 8]]; //本次操作的块
			var movefave = ['eside', 'fside'];  //本次操作的4个相关面,一个顶面		
			var bno = ['36785210', '01258763']; //01258763 36785210
			roteall(rotefaces, rotepos, movefave, bno);



		}
		// 整体顶顺
		function Uall() {
			var rotefaces = ['aside', 'bside', 'dside', 'cside', 'aside']; //本次操作的4个相关面,一个顶面 
			var rotepos = [[0, 1, 2, 3, 4, 5, 6, 7, 8], [0, 1, 2, 3, 4, 5, 6, 7, 8], [0, 1, 2, 3, 4, 5, 6, 7, 8], [0, 1, 2, 3, 4, 5, 6, 7, 8], [0, 1, 2, 3, 4, 5, 6, 7, 8]]; //本次操作的块
			var movefave = ['eside', 'fside'];  //本次操作的4个相关面,一个顶面		
			var bno = ['01258763', '36785210']; //01258763 36785210
			roteall(rotefaces, rotepos, movefave, bno);

		}


		$(function (argument) {



			for (var i = 0; i < colors.length; i++) {
				// 面
				var tmp = [];
				for (var j = 0; j < 9; j++) {
					// 一面9块
					tmp.push(colors[i]);
				}
				// 往魔方上贴一面的颜色
				colordata.push(tmp);
			}
			console.log('初始化魔方数据', colordata);

			fillcolor2box(colordata, sidenames);

			//整体有个旋转角度可以让我们看到3面    
			$(".box .content").css("transform", "rotateX(-35deg) rotateY(54deg) rotateZ(9deg)");
			$(".boxmin .content").css("transform", "rotateX(-35deg) rotateY(67deg) rotateZ(14deg)");
			// 各面旋转拼凑正方体
			$(".bside").css("transform", "rotateY(-90deg) translateX(-71px) translateZ(90px)");
			$(".cside").css("transform", "rotateY(90deg) translateX(90px) translateZ(71px)");
			$(".dside").css("transform", "rotateY(180deg) translateX(17px)   translateZ(161px)");
			$(".eside").css("transform", "rotateX(269deg)  translateY(90px) translateZ(71px) ");
			$(".fside").css("transform", "rotateX(90deg) translateY(-71px) translateZ(90px)");

			console.log('正在打乱魔方数据...');
			setTimeout(() => { Rndx(); }, 3000);



		});

		// 打乱---随机旋转100次
		function Rndx() {
			console.log('打乱魔方', colordata);
			for (var i = 0; i < 1000; i++) {
				var rand = Math.floor(Math.random() * 4 + 1);
				if (rand == 1) { R(); }
				if (rand == 2) { U(); }
				if (rand == 3) { F(); }
				if (rand == 4) { Uall(); }
			}
			fillcolor2box(colordata);
		}



		function F_End() { F(); fillcolor2box(colordata); }
		function F1_End() { F1(); fillcolor2box(colordata); }
		function R_End() { R(); fillcolor2box(colordata); }
		function R1_End() { R1(); fillcolor2box(colordata); }
		function B_End() { B(); fillcolor2box(colordata); }
		function B1_End() { B1(); fillcolor2box(colordata); }
		function U_End() { U(); fillcolor2box(colordata); }
		function U1_End() { U1(); fillcolor2box(colordata); }
		function Uall_End() { Uall(); fillcolor2box(colordata); }
		function U1all_End() { U1all(); fillcolor2box(colordata); }
	</script>
</head>

<body>
	<div class="divbuttons">
		<input type="button" class="button" value="U'" onclick="U1_End()">
		<input type="button" class="button" value="U" onclick="U_End()">

	</div>
	<div class="container">
		<!-- 左边两个按钮 -->
		<div class="divbuttons" style="float: left;height: 100%;width: 100px;line-height: 161px;padding: 32px;">
			<input type="button" class="button" value="F'" onclick="F1_End()">
			<input type="button" class="button" value="F" onclick="F_End()">
		</div>

		<!-- 正方体 -->
		<div class="box">
			<div class="content">
				<div class="aside face"> <!--魔方第一个面,类名aside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="bside face"> <!--魔方第2个面,类名bside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="cside face"> <!--魔方第3个面,类名cside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="dside face"> <!--魔方第一4个面,类名dside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="eside face"> <!--魔方第5个面,类名eside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="fside face"> <!--魔方第6个面,类名fside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
			</div>
		</div>

		<div class="boxmin">
			<div class="content">
				<div class="aside face"> <!--魔方第一个面,类名aside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="bside face"> <!--魔方第2个面,类名bside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="cside face"> <!--魔方第3个面,类名cside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="dside face"> <!--魔方第一4个面,类名dside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="eside face"> <!--魔方第5个面,类名eside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="fside face"> <!--魔方第6个面,类名fside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
			</div>
		</div>

	</div>
	<div class="divbuttons">

		<input type="button" class="button" value="R'" onclick="R1_End()">
		<input type="button" class="button" value="R" onclick="R_End()">
		<input type="button" class="button" value="B'" onclick="B1_End()">
		<input type="button" class="button" value="B" onclick="B_End()"><br>

		<input type="button" class="button" value="<-all" onclick="Uall_End()">
		<input type="button" class="button" value="all'->" onclick="U1all_End()">
		<input type="button" class="button" value="打乱" onclick="Rndx()">
	 
	</div>

</body>

</html>

接下来, 我们将自动完成底层的魔方块,分2步,1是底层十字,然后底层全部。主要代码是6个。

 

<!doctype html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
	<meta name="renderer" content="webkit">
	<!-- 引入jquey -->
	<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>


	<style>
		* {
			margin: 0;
			padding: 0;
			list-style: none;
			box-sizing: border-box;
		}

		.container {

			width: 100%;
			height: 380px;
			margin: 10px auto;
		}

		.box {
			left: 10%;
			top: 110px;
			width: 320px;
			perspective: 500px;
			position: relative;
			margin: 0 auto;
		}

		.boxmin {
			left: 25%;
			top: -40%;
			width: 320px;
			perspective: 500px;
			position: relative;
			margin: 0 auto;
			zoom: 51%;
		}


		.content {
			width: 180px;
			height: 180px;
			transform-style: preserve-3d;
			animation: run 10s infinite;
		}

		.face {
			width: 180px;
			height: 180px;
			position: absolute;
			text-align: center;
			line-height: 180px;

		}

		.minibox {
			width: 54px;
			height: 54px;
			border-radius: 4px;
			float: left;
			border: 3px solid #000;
		}

		.divbuttons {
			height: 60px;
			margin: 10px auto;
			text-align: center;
		}

		.button {
			font-size: xx-large;
			width: 100px;
			padding: 3px;
			margin: 3px;
		}
	</style>
	<script type="text/javascript">
		var colors = ["green", "yellow", "red", "blue", "white", "pink"];
		var sidenames = ["aside", "bside", "cside", "dside", "eside", "fside"];
		var colordata = [];

		//把数据对应到格子上
		function fillcolor2box() {
			console.log('开始给魔方着色');
			sidenames.map(function (v) {
				var k = sidenames.indexOf(v);
				for (var i = 0; i < 9; i++) {
					// 填充大魔方
					$(".box ." + v + " div").eq(i).css("background", colordata[k][i]);

					// 填充小魔方,便于观察
					if ("aside,bside,fside".split(",").indexOf(v) >= 0) {
						// 小魔方正面透明
						$(".boxmin ." + v + " div").eq(i).css("background", "fixed");
						$(".boxmin .minibox").css("border", "1px solid rgb(138, 135, 135)");
					} else {
						// 背面涂色
						$(".boxmin ." + v + " div").eq(i).css("background", colordata[k][i]);
					}
				}
			});
		}

		function roteall(rotefaces, rotepos, movefave, bno) {
			// 	var rotefaces=['fside','cside','eside','bside','fside']; //本次操作的4个相关面,一个顶面 
			// var rotepos=[[8,7,6],[6,3,0],[0,1,2],[2,5,8],[8,7,6]]; //本次操作的块
			// var movefave = "aside";  //本次操作的4个相关面,一个顶面		
			// var bno = "36785210"; //01258763 36785210 

			//为复制先存一个a面的顶上3个块颜色
			var tmpcolordata = [];
			for (var i = 0; i < colordata.length; i++) {
				tmpcolordata.push(colordata[i].concat()); //保存第一个数据
			}

			for (var i = 0; i < rotefaces.length; i++) {  //4个面轮流复制,最后一个面的时候使用保存的数据
				for (var j = 0; j < rotepos[i].length; j++) {
					if (i < 4) {
						colordata[sidenames.indexOf(rotefaces[i + 1])][rotepos[i + 1][j]] =
							tmpcolordata[sidenames.indexOf(rotefaces[i])][rotepos[i][j]];
					}
				}
			}
			tmpcolordata = [];

			//顶面旋转
			for (var k = 0; k < movefave.length; k++) {
				var ci = sidenames.indexOf(movefave[k]);
				var bn = bno[k].split("");// 顶面的操作是这8个格子依次右进3次 "01258763"顺时针
				for (var i = 0; i < 2; i++) {
					var tmp = colordata[ci][bn[0]]; //保存第一个数据
					for (var j = 0; j < bn.length; j++) {
						if (j >= bn.length - 1) {
							colordata[ci][bn[j]] = tmp;
						} else {
							colordata[ci][bn[j]] = colordata[ci][bn[j + 1]];
						}
					}
				}
			}

		}

		// 顶逆
		function U1() {
			var rotefaces = ['aside', 'cside', 'dside', 'bside', 'aside']; //本次操作的4个相关面,一个顶面 
			var rotepos = [[0, 1, 2], [0, 1, 2], [0, 1, 2], [0, 1, 2], [0, 1, 2]]; //本次操作的块
			var movefave = ["fside"];  //本次操作的4个相关面,一个顶面		
			var bno = ["01258763"]; //01258763 36785210
			roteall(rotefaces, rotepos, movefave, bno);

		}
		function U() {
			var rotefaces = ['aside', 'bside', 'dside', 'cside', 'aside']; //本次操作的4个相关面,一个顶面 
			var rotepos = [[0, 1, 2], [0, 1, 2], [0, 1, 2], [0, 1, 2], [0, 1, 2]]; //本次操作的块
			var movefave = ["fside"];  //本次操作的4个相关面,一个顶面		
			var bno = ["36785210"];
			roteall(rotefaces, rotepos, movefave, bno);

		}

		// 前逆
		function F1() {
			var rotefaces = ['aside', 'fside', 'dside', 'eside', 'aside']; //本次操作的4个相关面,一个顶面 
			var rotepos = [[6, 3, 0], [6, 3, 0], [2, 5, 8], [6, 3, 0], [6, 3, 0]]; //本次操作的块
			var movefave = ["bside"];  //本次操作的4个相关面,一个顶面		
			var bno = ["01258763"]; //01258763 36785210
			roteall(rotefaces, rotepos, movefave, bno);

		}
		function F() {
			var rotefaces = ['aside', 'eside', 'dside', 'fside', 'aside']; //本次操作的4个相关面,一个顶面 
			var rotepos = [[6, 3, 0], [6, 3, 0], [2, 5, 8], [6, 3, 0], [6, 3, 0]]; //本次操作的块
			var movefave = ["bside"];  //本次操作的4个相关面,一个顶面		
			var bno = ["36785210"]; //01258763 36785210
			roteall(rotefaces, rotepos, movefave, bno);

		}

		//右逆
		function R1() {
			var rotefaces = ['fside', 'bside', 'eside', 'cside', 'fside']; //本次操作的4个相关面,一个顶面 
			var rotepos = [[8, 7, 6], [2, 5, 8], [0, 1, 2], [6, 3, 0], [8, 7, 6]]; //本次操作的块
			var movefave = ["aside"];  //本次操作的4个相关面,一个顶面		
			var bno = ["01258763"]; //01258763 36785210
			roteall(rotefaces, rotepos, movefave, bno);

		}
		function R() {
			var rotefaces = ['fside', 'cside', 'eside', 'bside', 'fside']; //本次操作的4个相关面,一个顶面 
			var rotepos = [[8, 7, 6], [6, 3, 0], [0, 1, 2], [2, 5, 8], [8, 7, 6]]; //本次操作的块
			var movefave = ["aside"];  //本次操作的4个相关面,一个顶面		
			var bno = ["36785210"]; //01258763 36785210
			roteall(rotefaces, rotepos, movefave, bno);

		}
		// 后逆
		function B1() {
			var rotefaces = ['aside', 'fside', 'dside', 'eside', 'aside']; //本次操作的4个相关面,一个顶面 
			var rotepos = [[2, 5, 8], [2, 5, 8], [6, 3, 0], [2, 5, 8], [2, 5, 8]]; //本次操作的块
			var movefave = ["cside"];  //本次操作的4个相关面,一个顶面		
			var bno = ["36785210"]; //01258763 36785210
			roteall(rotefaces, rotepos, movefave, bno);

		}
		function B() {
			var rotefaces = ['aside', 'eside', 'dside', 'fside', 'aside']; //本次操作的4个相关面,一个顶面 
			var rotepos = [[2, 5, 8], [2, 5, 8], [6, 3, 0], [2, 5, 8], [2, 5, 8]]; //本次操作的块
			var movefave = ["cside"];  //本次操作的4个相关面,一个顶面		
			var bno = ["01258763"]; //01258763 36785210
			roteall(rotefaces, rotepos, movefave, bno);

		}

		// 整体顶逆
		function U1all() {
			var rotefaces = ['aside', 'cside', 'dside', 'bside', 'aside']; //本次操作的4个相关面,一个顶面 
			var rotepos = [[0, 1, 2, 3, 4, 5, 6, 7, 8], [0, 1, 2, 3, 4, 5, 6, 7, 8], [0, 1, 2, 3, 4, 5, 6, 7, 8], [0, 1, 2, 3, 4, 5, 6, 7, 8], [0, 1, 2, 3, 4, 5, 6, 7, 8]]; //本次操作的块
			var movefave = ['eside', 'fside'];  //本次操作的4个相关面,一个顶面		
			var bno = ['36785210', '01258763']; //01258763 36785210
			roteall(rotefaces, rotepos, movefave, bno);



		}
		// 整体顶顺
		function Uall() {
			var rotefaces = ['aside', 'bside', 'dside', 'cside', 'aside']; //本次操作的4个相关面,一个顶面 
			var rotepos = [[0, 1, 2, 3, 4, 5, 6, 7, 8], [0, 1, 2, 3, 4, 5, 6, 7, 8], [0, 1, 2, 3, 4, 5, 6, 7, 8], [0, 1, 2, 3, 4, 5, 6, 7, 8], [0, 1, 2, 3, 4, 5, 6, 7, 8]]; //本次操作的块
			var movefave = ['eside', 'fside'];  //本次操作的4个相关面,一个顶面		
			var bno = ['01258763', '36785210']; //01258763 36785210
			roteall(rotefaces, rotepos, movefave, bno);

		}


		$(function (argument) {



			for (var i = 0; i < colors.length; i++) {
				// 面
				var tmp = [];
				for (var j = 0; j < 9; j++) {
					// 一面9块
					tmp.push(colors[i]);
				}
				// 往魔方上贴一面的颜色
				colordata.push(tmp);
			}
			console.log('初始化魔方数据', colordata);

			fillcolor2box(colordata, sidenames);

			//整体有个旋转角度可以让我们看到3面    
			$(".box .content").css("transform", "rotateX(-35deg) rotateY(54deg) rotateZ(9deg)");
			$(".boxmin .content").css("transform", "rotateX(-35deg) rotateY(67deg) rotateZ(14deg)");
			// 各面旋转拼凑正方体
			$(".bside").css("transform", "rotateY(-90deg) translateX(-71px) translateZ(90px)");
			$(".cside").css("transform", "rotateY(90deg) translateX(90px) translateZ(71px)");
			$(".dside").css("transform", "rotateY(180deg) translateX(17px)   translateZ(161px)");
			$(".eside").css("transform", "rotateX(269deg)  translateY(90px) translateZ(71px) ");
			$(".fside").css("transform", "rotateX(90deg) translateY(-71px) translateZ(90px)");

			console.log('正在打乱魔方数据...');
			setTimeout(() => { Rndx(); }, 3000);



		});

		// 打乱---随机旋转100次
		function Rndx() {
			console.log('打乱魔方', colordata);
			for (var i = 0; i < 1000; i++) {
				var rand = Math.floor(Math.random() * 4 + 1);
				if (rand == 1) { R(); }
				if (rand == 2) { U(); }
				if (rand == 3) { F(); }
				if (rand == 4) { Uall(); }
			}
			fillcolor2box(colordata);
		}



		function F_End() { F(); fillcolor2box(colordata); }
		function F1_End() { F1(); fillcolor2box(colordata); }
		function R_End() { R(); fillcolor2box(colordata); }
		function R1_End() { R1(); fillcolor2box(colordata); }
		function B_End() { B(); fillcolor2box(colordata); }
		function B1_End() { B1(); fillcolor2box(colordata); }
		function U_End() { U(); fillcolor2box(colordata); }
		function U1_End() { U1(); fillcolor2box(colordata); }
		function Uall_End() { Uall(); fillcolor2box(colordata); }
		function U1all_End() { U1all(); fillcolor2box(colordata); }



		// 1 底层小白
		function s1_xiaobai() {
			for (var i = 0; i < 100; i++) {
				step1();
				if (checkokstep1()) { break; }
			}
			fillcolor2box(colordata);
		}

		function s2_dicheng() {
			for (var i = 0; i < 100; i++) {
				step2();
				if (checkokstep2()) { break; }
			}
			fillcolor2box(colordata);
		}

		function step1(step1_times) {
			// 找到底层白色做成底层十字,俗称小白花
			// 分析:白色共8个动快 0123 5678 

			var w_index = "";
			var w_len_index = "";
			var w_len_indexa = "";
			var w_len_indexacolor = "";
			var checkeeee = "";
			var faces = "abcdef".split("");
			var lenwei = "1357"; //棱位 
			var jiaowei = "0268"; //角位
			var colorseq = ["green", "red", "blue", "yellow"];
			var map_lenwei = ["a1", "a3", "a5", "a7", "b1", "b3", "b5", "b7", "c1", "c3", "c5", "c7", "d1", "d3", "d5", "d7", "e1", "e3", "e5", "e7", "f1", "f3", "f5", "f7"];
			var map_lenweia = ["f7", "b5", "c3", "e1", "f3", "d5", "a3", "e3", "f5", "a5", "d3", "e5", "f1", "c5", "b3", "e7", "a7", "b7", "c7", "d7", "d1", "b1", "c1", "a1"];
			for (var i = 0; i < colordata.length; i++) {
				for (var j = 0; j < colordata[i].length; j++) {
					if ('white' == colordata[i][j]) {
						w_index += "," + faces[i] + "" + j;
						if (lenwei.indexOf(j) >= 0) {  //var lenwei="1357"; //棱位 
							checkeeee += faces[i];
							var this_w_len_index = "" + faces[i] + "" + j
							w_len_index += "," + this_w_len_index;
							var this_w_len_indexa = map_lenweia[map_lenwei.indexOf(this_w_len_index)]
							w_len_indexa += "," + this_w_len_indexa;
							var ff = this_w_len_indexa.split("")[0];
							var ffi = this_w_len_indexa.split("")[1];
							w_len_indexacolor += "," + colordata[faces.indexOf(ff)][ffi];
						}
					}
				}
			}

			var hasa = (checkeeee.indexOf("a") >= 0)
			// console.log("白色9块分布于:"+w_index);		
			// console.log("白色棱位:"+w_len_index);	 //a3,a5,e5,e7
			// console.log("白色棱位对位置:"+w_len_indexa);	 //a3,a5,e5,e7
			// console.log("白色棱位对颜色:"+w_len_indexacolor);	 //a3,a5,e5,e7
			// console.log("A面的颜色是:"+ colordata[0][4]);
			// 	console.log("B面的颜色是:"+ colordata[1][4]);
			// 	console.log("C面的颜色是:"+ colordata[2][4]);
			// 	console.log("D面的颜色是:"+ colordata[3][4]);
			// 	console.log("E面的颜色是:"+ colordata[4][4]);
			// 	console.log("F面的颜色是:"+ colordata[5][4]);
			// 	console.log("checkeeee是:"+ checkeeee+",其中是否有a:" + hasa);

			var needmove = false;

			if (1 <= 100) {
				if (checkeeee.indexOf("a") < 0) {
					if (checkeeee.indexOf("b") >= 0) {
						U1all();
						step1();
					} else if (checkeeee.indexOf("c") >= 0) {
						Uall();
						step1();
					} else if (checkeeee.indexOf("d") >= 0) {
						Uall(); Uall();
						step1();
					} else if (checkeeee.indexOf("f") >= 0) {
						var fn = w_len_index.substr(w_len_index.indexOf("f") + 1, 1);
						var aindex = (w_len_index.indexOf("f" + fn) - 1) / 3;
						var ducolor = w_len_indexacolor.split(",")[aindex + 1];
						var bcolor = colordata[1][4];
						var N = 4 + colorseq.indexOf(bcolor) - colorseq.indexOf(ducolor);
						if (fn == 1) { U1(); }
						if (fn == 3) { }
						if (fn == 5) { U(); U(); }
						if (fn == 7) { U(); }

						for (var i = 0; i < N; i++) {
							U1all(); U();
						}
						F(); F();
						step1();
					} else {
						//这里已经是eeee.如果颜色不对是需要拧上去的。
						var fn = w_len_index.substr(w_len_index.indexOf("e") + 1, 1);
						var aindex = (w_len_index.indexOf("e" + fn) - 1) / 3;
						var ducolor = w_len_indexacolor.split(",")[aindex + 1];

						var errcolor = false;
						if (fn == 1) { errcolor = (ducolor != colordata[0][4]); }
						if (fn == 3) { errcolor = (ducolor != colordata[1][4]); }
						if (fn == 5) { errcolor = (ducolor != colordata[2][4]); }
						if (fn == 7) { errcolor = (ducolor != colordata[3][4]); }
						if (fn == 1 && errcolor) { R(); }
						if (fn == 3 && errcolor) { F(); }
						if (fn == 5 && errcolor) { B(); }
						if (fn == 7 && errcolor) { U1all(); F(); }
						// 	colorseq.indexOf(colordata[5][fn])-  colorseq.indexOf(ducolor)
						// console.log("ducolor:"+ ducolor+",colordata[0][4]" + colordata[0][4]);
					}
				} else {
					//has a
					// console.log("has a and :a"+   w_len_index.substr(w_len_index.indexOf("a")+1,1) );
					var fn = w_len_index.substr(w_len_index.indexOf("a") + 1, 1);
					var aindex = (w_len_index.indexOf("a" + fn) - 1) / 3;
					var ducolor = w_len_indexacolor.split(",")[aindex + 1];


					// var colorseq=["green","red","blue","yellow"];   green
					//B_color w_len_indexacolor.split(",")[aindex+1]
					// a面有白。a->a1->color->weizhi 

					if (fn == 1) { }
					if (fn == 3) { R(); }
					if (fn == 5) { R1(); }
					if (fn == 7) { R(); R(); }
					var bcolor = colordata[1][4];
					var N = 4 + colorseq.indexOf(bcolor) - colorseq.indexOf(ducolor);
					for (var i = 0; i < N; i++) {
						U1all(); U();
					}
					R1(); F(); R();

				}
			}





			//计算棱位对应色		
			// for (var j = 0; j < faces.length; j++) {
			// 	for (var i = 0; i < arr_lenwei.length; i++) {
			// 		map_lenwei.push(""+faces[j]+""+arr_lenwei[i]);
			// 	}
			// }
			// console.log(map_lenwei); 
			// ["a1", "a3", "a5", "a7", "b1", "b3", "b5", "b7", "c1", "c3", "c5", "c7", "d1", "d3", "d5", "d7", "e1", "e3", "e5", "e7", "f1", "f3", "f5", "f7"]

		}
		// 2找到底层角块,并归位
		function step2() {

			var w_index = "";
			var w_len_index = "";
			var w_len_indexa = "";
			var w_len_indexacolor = "";
			var checkeeee = "";
			var faces = "abcdef".split("");
			var lenwei = "1357"; //棱位 
			var jiaowei = "0268"; //角位
			var colorseq = ["green", "red", "blue", "yellow"];

			for (var i = 0; i < colordata.length; i++) {
				for (var j = 0; j < colordata[i].length; j++) {
					if ('white' == colordata[i][j]) {
						w_index += "," + faces[i] + "" + j;
						if (jiaowei.indexOf(j) >= 0) {  //var  jiaowei="0268"; 
							checkeeee += faces[i];
							var this_w_len_index = "" + faces[i] + "" + j
							w_len_index += "," + this_w_len_index;


						}
					}
				}
			}

			// 白色9块分布于:,b0,c2,e1,e3,e4,e5,e6,e7,f6
			// index_mofang.html:622 白色角位:,b0,c2,e6,f6
			// index_mofang.html:631 checkeeee是:bcef,其中是否有a:false
			// 同理也是先将1个白色角块转至A面。然后定位于A0,然后对应相应颜色。共3个步骤
			var hasa = (checkeeee.indexOf("a") >= 0)
			// console.log("白色9块分布于:"+w_index);	 	
			// console.log("白色角位:"+w_len_index);	 //a3,a5,e5,e7 
			// 	console.log("checkeeee是:"+ checkeeee+",其中是否有a:" + hasa);



			if (1 <= 100) {
				if (checkeeee.indexOf("a") < 0) {
					if (checkeeee.indexOf("b") >= 0) {
						U1all();
						step2();
					} else if (checkeeee.indexOf("c") >= 0) {
						Uall();
						step2();
					} else if (checkeeee.indexOf("d") >= 0) {
						Uall(); Uall();
						step2();
					} else if (checkeeee.indexOf("f") >= 0) {
						// 白角块在F面时有2个路线。
						var fn = w_len_index.substr(w_len_index.indexOf("f") + 1, 1);
						if (fn == 0) { U(); F1(); U1(); F() }
						if (fn == 2) { F1(); U1(); F() }
						if (fn == 6) { U1(); F1(); U(); F(); }
						if (fn == 8) { F1(); U(); F(); }
						step2();
					} else {
						//eeee就不拧了,先检查再拧。
					}
				} else {
					// console.log("has a and :a"+   w_len_index.substr(w_len_index.indexOf("a")+1,1) );
					var fn = w_len_index.substr(w_len_index.indexOf("a") + 1, 1);
					var aindex = (w_len_index.indexOf("a" + fn) - 1) / 3;

					if (fn == 0) { }
					if (fn == 2) { U1(); R(); U(); R1(); }
					if (fn == 6) { R(); U(); R1(); U1(); }
					if (fn == 8) { R1(); U1(); R(); U(); }
					//A0已经有一个白角块了。到时间看下是什么颜色了。
					var colorB = colordata[1][2];
					var bcolor = colordata[1][4];
					var N = 4 + colorseq.indexOf(bcolor) - colorseq.indexOf(colorB);
					for (var i = 0; i < N; i++) {
						U1all(); U();
					}
					U1(); F1(); U(); F();

				}
			}
			// console.log(" step2执行了" +  step2_times + "次" );

		}
  
		var checkokstep1 = function () {
			if (colordata[4][1] === colordata[4][4] &&
				colordata[4][3] === colordata[4][4] &&
				colordata[4][5] === colordata[4][4] &&
				colordata[4][7] === colordata[4][4]) {
				if (colordata[0][7] === colordata[0][4] &&
					colordata[1][7] === colordata[1][4] &&
					colordata[2][7] === colordata[2][4] &&
					colordata[3][7] === colordata[3][4]) {
					// console.log("底部小白花");
					return true;
				}
			}
			return false;
		}
 
		var checkokstep2 = function () { //底层ok
			if (colordata[4][1] === colordata[4][4] &&
				colordata[4][3] === colordata[4][4] &&
				colordata[4][5] === colordata[4][4] &&
				colordata[4][7] === colordata[4][4] &&
				colordata[4][0] === colordata[4][4] &&
				colordata[4][2] === colordata[4][4] &&
				colordata[4][4] === colordata[4][4] &&
				colordata[4][8] === colordata[4][4]) {
				if (colordata[0][6] === colordata[0][4] && colordata[0][7] === colordata[0][4] && colordata[0][8] === colordata[0][4] &&
					colordata[1][6] === colordata[1][4] && colordata[1][7] === colordata[1][4] && colordata[1][8] === colordata[1][4] &&
					colordata[2][6] === colordata[2][4] && colordata[2][7] === colordata[2][4] && colordata[2][8] === colordata[2][4] &&
					colordata[3][6] === colordata[3][4] && colordata[2][7] === colordata[2][4] && colordata[2][8] === colordata[2][4]) {
					// console.log("底层");
					return true;
				}
			}
			return false;
		}


	</script>
</head>

<body>
	<div class="divbuttons">
		<input type="button" class="button" value="U'" onclick="U1_End()">
		<input type="button" class="button" value="U" onclick="U_End()">

	</div>
	<div class="container">
		<!-- 左边两个按钮 -->
		<div class="divbuttons" style="float: left;height: 100%;width: 100px;line-height: 161px;padding: 32px;">
			<input type="button" class="button" value="F'" onclick="F1_End()">
			<input type="button" class="button" value="F" onclick="F_End()">
		</div>

		<!-- 正方体 -->
		<div class="box">
			<div class="content">
				<div class="aside face"> <!--魔方第一个面,类名aside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="bside face"> <!--魔方第2个面,类名bside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="cside face"> <!--魔方第3个面,类名cside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="dside face"> <!--魔方第一4个面,类名dside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="eside face"> <!--魔方第5个面,类名eside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="fside face"> <!--魔方第6个面,类名fside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
			</div>
		</div>

		<div class="boxmin">
			<div class="content">
				<div class="aside face"> <!--魔方第一个面,类名aside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="bside face"> <!--魔方第2个面,类名bside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="cside face"> <!--魔方第3个面,类名cside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="dside face"> <!--魔方第一4个面,类名dside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="eside face"> <!--魔方第5个面,类名eside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="fside face"> <!--魔方第6个面,类名fside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
			</div>
		</div>

	</div>
	<div class="divbuttons">

		<input type="button" class="button" value="R'" onclick="R1_End()">
		<input type="button" class="button" value="R" onclick="R_End()">
		<input type="button" class="button" value="B'" onclick="B1_End()">
		<input type="button" class="button" value="B" onclick="B_End()"><br>

		<input type="button" class="button" value="<-all" onclick="Uall_End()">
		<input type="button" class="button" value="all'->" onclick="U1all_End()">
		<input type="button" class="button" value="打乱" onclick="Rndx()">
		<br>
		<input type="button" class="button" value="1底层小白花" onclick="s1_xiaobai()">
		<input type="button" class="button" value="2底层归位" onclick="s2_dicheng()">
 
	</div>

</body>

</html>

 接下来, 我们将自动完成中间层。代码如下可直接运行

 

<!doctype html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
	<meta name="renderer" content="webkit">
	<!-- 引入jquey -->
	<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>


	<style>
		* {
			margin: 0;
			padding: 0;
			list-style: none;
			box-sizing: border-box;
		}

		.container {

			width: 100%;
			height: 380px;
			margin: 10px auto;
		}

		.box {
			left: 10%;
			top: 110px;
			width: 320px;
			perspective: 500px;
			position: relative;
			margin: 0 auto;
		}

		.boxmin {
			left: 25%;
			top: -40%;
			width: 320px;
			perspective: 500px;
			position: relative;
			margin: 0 auto;
			zoom: 51%;
		}


		.content {
			width: 180px;
			height: 180px;
			transform-style: preserve-3d;
			animation: run 10s infinite;
		}

		.face {
			width: 180px;
			height: 180px;
			position: absolute;
			text-align: center;
			line-height: 180px;

		}

		.minibox {
			width: 54px;
			height: 54px;
			border-radius: 4px;
			float: left;
			border: 3px solid #000;
		}

		.divbuttons {
			height: 60px;
			margin: 10px auto;
			text-align: center;
		}

		.button {
			font-size: xx-large;
			width: 100px;
			padding: 3px;
			margin: 3px;
		}
	</style>
	<script type="text/javascript">
		var colors = ["green", "yellow", "red", "blue", "white", "pink"];
		var sidenames = ["aside", "bside", "cside", "dside", "eside", "fside"];
		var colordata = [];

		//把数据对应到格子上
		function fillcolor2box() {
			console.log('开始给魔方着色');
			sidenames.map(function (v) {
				var k = sidenames.indexOf(v);
				for (var i = 0; i < 9; i++) {
					// 填充大魔方
					$(".box ." + v + " div").eq(i).css("background", colordata[k][i]);

					// 填充小魔方,便于观察
					if ("aside,bside,fside".split(",").indexOf(v) >= 0) {
						// 小魔方正面透明
						$(".boxmin ." + v + " div").eq(i).css("background", "fixed");
						$(".boxmin .minibox").css("border", "1px solid rgb(138, 135, 135)");
					} else {
						// 背面涂色
						$(".boxmin ." + v + " div").eq(i).css("background", colordata[k][i]);
					}
				}
			});
		}

		function roteall(rotefaces, rotepos, movefave, bno) {
			// 	var rotefaces=['fside','cside','eside','bside','fside']; //本次操作的4个相关面,一个顶面 
			// var rotepos=[[8,7,6],[6,3,0],[0,1,2],[2,5,8],[8,7,6]]; //本次操作的块
			// var movefave = "aside";  //本次操作的4个相关面,一个顶面		
			// var bno = "36785210"; //01258763 36785210 

			//为复制先存一个a面的顶上3个块颜色
			var tmpcolordata = [];
			for (var i = 0; i < colordata.length; i++) {
				tmpcolordata.push(colordata[i].concat()); //保存第一个数据
			}

			for (var i = 0; i < rotefaces.length; i++) {  //4个面轮流复制,最后一个面的时候使用保存的数据
				for (var j = 0; j < rotepos[i].length; j++) {
					if (i < 4) {
						colordata[sidenames.indexOf(rotefaces[i + 1])][rotepos[i + 1][j]] =
							tmpcolordata[sidenames.indexOf(rotefaces[i])][rotepos[i][j]];
					}
				}
			}
			tmpcolordata = [];

			//顶面旋转
			for (var k = 0; k < movefave.length; k++) {
				var ci = sidenames.indexOf(movefave[k]);
				var bn = bno[k].split("");// 顶面的操作是这8个格子依次右进3次 "01258763"顺时针
				for (var i = 0; i < 2; i++) {
					var tmp = colordata[ci][bn[0]]; //保存第一个数据
					for (var j = 0; j < bn.length; j++) {
						if (j >= bn.length - 1) {
							colordata[ci][bn[j]] = tmp;
						} else {
							colordata[ci][bn[j]] = colordata[ci][bn[j + 1]];
						}
					}
				}
			}

		}

		// 顶逆
		function U1() {
			var rotefaces = ['aside', 'cside', 'dside', 'bside', 'aside']; //本次操作的4个相关面,一个顶面 
			var rotepos = [[0, 1, 2], [0, 1, 2], [0, 1, 2], [0, 1, 2], [0, 1, 2]]; //本次操作的块
			var movefave = ["fside"];  //本次操作的4个相关面,一个顶面		
			var bno = ["01258763"]; //01258763 36785210
			roteall(rotefaces, rotepos, movefave, bno);

		}
		function U() {
			var rotefaces = ['aside', 'bside', 'dside', 'cside', 'aside']; //本次操作的4个相关面,一个顶面 
			var rotepos = [[0, 1, 2], [0, 1, 2], [0, 1, 2], [0, 1, 2], [0, 1, 2]]; //本次操作的块
			var movefave = ["fside"];  //本次操作的4个相关面,一个顶面		
			var bno = ["36785210"];
			roteall(rotefaces, rotepos, movefave, bno);

		}

		// 前逆
		function F1() {
			var rotefaces = ['aside', 'fside', 'dside', 'eside', 'aside']; //本次操作的4个相关面,一个顶面 
			var rotepos = [[6, 3, 0], [6, 3, 0], [2, 5, 8], [6, 3, 0], [6, 3, 0]]; //本次操作的块
			var movefave = ["bside"];  //本次操作的4个相关面,一个顶面		
			var bno = ["01258763"]; //01258763 36785210
			roteall(rotefaces, rotepos, movefave, bno);

		}
		function F() {
			var rotefaces = ['aside', 'eside', 'dside', 'fside', 'aside']; //本次操作的4个相关面,一个顶面 
			var rotepos = [[6, 3, 0], [6, 3, 0], [2, 5, 8], [6, 3, 0], [6, 3, 0]]; //本次操作的块
			var movefave = ["bside"];  //本次操作的4个相关面,一个顶面		
			var bno = ["36785210"]; //01258763 36785210
			roteall(rotefaces, rotepos, movefave, bno);

		}

		//右逆
		function R1() {
			var rotefaces = ['fside', 'bside', 'eside', 'cside', 'fside']; //本次操作的4个相关面,一个顶面 
			var rotepos = [[8, 7, 6], [2, 5, 8], [0, 1, 2], [6, 3, 0], [8, 7, 6]]; //本次操作的块
			var movefave = ["aside"];  //本次操作的4个相关面,一个顶面		
			var bno = ["01258763"]; //01258763 36785210
			roteall(rotefaces, rotepos, movefave, bno);

		}
		function R() {
			var rotefaces = ['fside', 'cside', 'eside', 'bside', 'fside']; //本次操作的4个相关面,一个顶面 
			var rotepos = [[8, 7, 6], [6, 3, 0], [0, 1, 2], [2, 5, 8], [8, 7, 6]]; //本次操作的块
			var movefave = ["aside"];  //本次操作的4个相关面,一个顶面		
			var bno = ["36785210"]; //01258763 36785210
			roteall(rotefaces, rotepos, movefave, bno);

		}
		// 后逆
		function B1() {
			var rotefaces = ['aside', 'fside', 'dside', 'eside', 'aside']; //本次操作的4个相关面,一个顶面 
			var rotepos = [[2, 5, 8], [2, 5, 8], [6, 3, 0], [2, 5, 8], [2, 5, 8]]; //本次操作的块
			var movefave = ["cside"];  //本次操作的4个相关面,一个顶面		
			var bno = ["36785210"]; //01258763 36785210
			roteall(rotefaces, rotepos, movefave, bno);

		}
		function B() {
			var rotefaces = ['aside', 'eside', 'dside', 'fside', 'aside']; //本次操作的4个相关面,一个顶面 
			var rotepos = [[2, 5, 8], [2, 5, 8], [6, 3, 0], [2, 5, 8], [2, 5, 8]]; //本次操作的块
			var movefave = ["cside"];  //本次操作的4个相关面,一个顶面		
			var bno = ["01258763"]; //01258763 36785210
			roteall(rotefaces, rotepos, movefave, bno);

		}

		// 整体顶逆
		function U1all() {
			var rotefaces = ['aside', 'cside', 'dside', 'bside', 'aside']; //本次操作的4个相关面,一个顶面 
			var rotepos = [[0, 1, 2, 3, 4, 5, 6, 7, 8], [0, 1, 2, 3, 4, 5, 6, 7, 8], [0, 1, 2, 3, 4, 5, 6, 7, 8], [0, 1, 2, 3, 4, 5, 6, 7, 8], [0, 1, 2, 3, 4, 5, 6, 7, 8]]; //本次操作的块
			var movefave = ['eside', 'fside'];  //本次操作的4个相关面,一个顶面		
			var bno = ['36785210', '01258763']; //01258763 36785210
			roteall(rotefaces, rotepos, movefave, bno);



		}
		// 整体顶顺
		function Uall() {
			var rotefaces = ['aside', 'bside', 'dside', 'cside', 'aside']; //本次操作的4个相关面,一个顶面 
			var rotepos = [[0, 1, 2, 3, 4, 5, 6, 7, 8], [0, 1, 2, 3, 4, 5, 6, 7, 8], [0, 1, 2, 3, 4, 5, 6, 7, 8], [0, 1, 2, 3, 4, 5, 6, 7, 8], [0, 1, 2, 3, 4, 5, 6, 7, 8]]; //本次操作的块
			var movefave = ['eside', 'fside'];  //本次操作的4个相关面,一个顶面		
			var bno = ['01258763', '36785210']; //01258763 36785210
			roteall(rotefaces, rotepos, movefave, bno);

		}


		$(function (argument) {



			for (var i = 0; i < colors.length; i++) {
				// 面
				var tmp = [];
				for (var j = 0; j < 9; j++) {
					// 一面9块
					tmp.push(colors[i]);
				}
				// 往魔方上贴一面的颜色
				colordata.push(tmp);
			}
			console.log('初始化魔方数据', colordata);

			fillcolor2box(colordata, sidenames);

			//整体有个旋转角度可以让我们看到3面    
			$(".box .content").css("transform", "rotateX(-35deg) rotateY(54deg) rotateZ(9deg)");
			$(".boxmin .content").css("transform", "rotateX(-35deg) rotateY(67deg) rotateZ(14deg)");
			// 各面旋转拼凑正方体
			$(".bside").css("transform", "rotateY(-90deg) translateX(-71px) translateZ(90px)");
			$(".cside").css("transform", "rotateY(90deg) translateX(90px) translateZ(71px)");
			$(".dside").css("transform", "rotateY(180deg) translateX(17px)   translateZ(161px)");
			$(".eside").css("transform", "rotateX(269deg)  translateY(90px) translateZ(71px) ");
			$(".fside").css("transform", "rotateX(90deg) translateY(-71px) translateZ(90px)");

			console.log('正在打乱魔方数据...');
			setTimeout(() => { Rndx(); }, 3000);



		});

		// 打乱---随机旋转100次
		function Rndx() {
			console.log('打乱魔方', colordata);
			for (var i = 0; i < 1000; i++) {
				var rand = Math.floor(Math.random() * 4 + 1);
				if (rand == 1) { R(); }
				if (rand == 2) { U(); }
				if (rand == 3) { F(); }
				if (rand == 4) { Uall(); }
			}
			fillcolor2box(colordata);
		}



		function F_End() { F(); fillcolor2box(colordata); }
		function F1_End() { F1(); fillcolor2box(colordata); }
		function R_End() { R(); fillcolor2box(colordata); }
		function R1_End() { R1(); fillcolor2box(colordata); }
		function B_End() { B(); fillcolor2box(colordata); }
		function B1_End() { B1(); fillcolor2box(colordata); }
		function U_End() { U(); fillcolor2box(colordata); }
		function U1_End() { U1(); fillcolor2box(colordata); }
		function Uall_End() { Uall(); fillcolor2box(colordata); }
		function U1all_End() { U1all(); fillcolor2box(colordata); }



		// 1 底层小白
		function s1_xiaobai() {
			for (var i = 0; i < 100; i++) {
				step1();
				if (checkokstep1()) { break; }
			}
			fillcolor2box(colordata);
			
			console.log('1底层十字完成');
		}

		function s2_dicheng() {
			for (var i = 0; i < 100; i++) {
				step2();
				if (checkokstep2()) { break; }
			}
			fillcolor2box(colordata);
			
			console.log('2底层完成');
		}

		function step1(step1_times) {
			// 找到底层白色做成底层十字,俗称小白花
			// 分析:白色共8个动快 0123 5678 

			var w_index = "";
			var w_len_index = "";
			var w_len_indexa = "";
			var w_len_indexacolor = "";
			var checkeeee = "";
			var faces = "abcdef".split("");
			var lenwei = "1357"; //棱位 
			var jiaowei = "0268"; //角位
			var colorseq = ["green", "red", "blue", "yellow"];
			var map_lenwei = ["a1", "a3", "a5", "a7", "b1", "b3", "b5", "b7", "c1", "c3", "c5", "c7", "d1", "d3", "d5", "d7", "e1", "e3", "e5", "e7", "f1", "f3", "f5", "f7"];
			var map_lenweia = ["f7", "b5", "c3", "e1", "f3", "d5", "a3", "e3", "f5", "a5", "d3", "e5", "f1", "c5", "b3", "e7", "a7", "b7", "c7", "d7", "d1", "b1", "c1", "a1"];
			for (var i = 0; i < colordata.length; i++) {
				for (var j = 0; j < colordata[i].length; j++) {
					if ('white' == colordata[i][j]) {
						w_index += "," + faces[i] + "" + j;
						if (lenwei.indexOf(j) >= 0) {  //var lenwei="1357"; //棱位 
							checkeeee += faces[i];
							var this_w_len_index = "" + faces[i] + "" + j
							w_len_index += "," + this_w_len_index;
							var this_w_len_indexa = map_lenweia[map_lenwei.indexOf(this_w_len_index)]
							w_len_indexa += "," + this_w_len_indexa;
							var ff = this_w_len_indexa.split("")[0];
							var ffi = this_w_len_indexa.split("")[1];
							w_len_indexacolor += "," + colordata[faces.indexOf(ff)][ffi];
						}
					}
				}
			}

			var hasa = (checkeeee.indexOf("a") >= 0)
			// console.log("白色9块分布于:"+w_index);		
			// console.log("白色棱位:"+w_len_index);	 //a3,a5,e5,e7
			// console.log("白色棱位对位置:"+w_len_indexa);	 //a3,a5,e5,e7
			// console.log("白色棱位对颜色:"+w_len_indexacolor);	 //a3,a5,e5,e7
			// console.log("A面的颜色是:"+ colordata[0][4]);
			// 	console.log("B面的颜色是:"+ colordata[1][4]);
			// 	console.log("C面的颜色是:"+ colordata[2][4]);
			// 	console.log("D面的颜色是:"+ colordata[3][4]);
			// 	console.log("E面的颜色是:"+ colordata[4][4]);
			// 	console.log("F面的颜色是:"+ colordata[5][4]);
			// 	console.log("checkeeee是:"+ checkeeee+",其中是否有a:" + hasa);

			var needmove = false;

			if (1 <= 100) {
				if (checkeeee.indexOf("a") < 0) {
					if (checkeeee.indexOf("b") >= 0) {
						U1all();
						step1();
					} else if (checkeeee.indexOf("c") >= 0) {
						Uall();
						step1();
					} else if (checkeeee.indexOf("d") >= 0) {
						Uall(); Uall();
						step1();
					} else if (checkeeee.indexOf("f") >= 0) {
						var fn = w_len_index.substr(w_len_index.indexOf("f") + 1, 1);
						var aindex = (w_len_index.indexOf("f" + fn) - 1) / 3;
						var ducolor = w_len_indexacolor.split(",")[aindex + 1];
						var bcolor = colordata[1][4];
						var N = 4 + colorseq.indexOf(bcolor) - colorseq.indexOf(ducolor);
						if (fn == 1) { U1(); }
						if (fn == 3) { }
						if (fn == 5) { U(); U(); }
						if (fn == 7) { U(); }

						for (var i = 0; i < N; i++) {
							U1all(); U();
						}
						F(); F();
						step1();
					} else {
						//这里已经是eeee.如果颜色不对是需要拧上去的。
						var fn = w_len_index.substr(w_len_index.indexOf("e") + 1, 1);
						var aindex = (w_len_index.indexOf("e" + fn) - 1) / 3;
						var ducolor = w_len_indexacolor.split(",")[aindex + 1];

						var errcolor = false;
						if (fn == 1) { errcolor = (ducolor != colordata[0][4]); }
						if (fn == 3) { errcolor = (ducolor != colordata[1][4]); }
						if (fn == 5) { errcolor = (ducolor != colordata[2][4]); }
						if (fn == 7) { errcolor = (ducolor != colordata[3][4]); }
						if (fn == 1 && errcolor) { R(); }
						if (fn == 3 && errcolor) { F(); }
						if (fn == 5 && errcolor) { B(); }
						if (fn == 7 && errcolor) { U1all(); F(); }
						// 	colorseq.indexOf(colordata[5][fn])-  colorseq.indexOf(ducolor)
						// console.log("ducolor:"+ ducolor+",colordata[0][4]" + colordata[0][4]);
					}
				} else {
					//has a
					// console.log("has a and :a"+   w_len_index.substr(w_len_index.indexOf("a")+1,1) );
					var fn = w_len_index.substr(w_len_index.indexOf("a") + 1, 1);
					var aindex = (w_len_index.indexOf("a" + fn) - 1) / 3;
					var ducolor = w_len_indexacolor.split(",")[aindex + 1];


					// var colorseq=["green","red","blue","yellow"];   green
					//B_color w_len_indexacolor.split(",")[aindex+1]
					// a面有白。a->a1->color->weizhi 

					if (fn == 1) { }
					if (fn == 3) { R(); }
					if (fn == 5) { R1(); }
					if (fn == 7) { R(); R(); }
					var bcolor = colordata[1][4];
					var N = 4 + colorseq.indexOf(bcolor) - colorseq.indexOf(ducolor);
					for (var i = 0; i < N; i++) {
						U1all(); U();
					}
					R1(); F(); R();

				}
			}





			//计算棱位对应色		
			// for (var j = 0; j < faces.length; j++) {
			// 	for (var i = 0; i < arr_lenwei.length; i++) {
			// 		map_lenwei.push(""+faces[j]+""+arr_lenwei[i]);
			// 	}
			// }
			// console.log(map_lenwei); 
			// ["a1", "a3", "a5", "a7", "b1", "b3", "b5", "b7", "c1", "c3", "c5", "c7", "d1", "d3", "d5", "d7", "e1", "e3", "e5", "e7", "f1", "f3", "f5", "f7"]

		}
		// 2找到底层角块,并归位
		function step2() {

			var w_index = "";
			var w_len_index = "";
			var w_len_indexa = "";
			var w_len_indexacolor = "";
			var checkeeee = "";
			var faces = "abcdef".split("");
			var lenwei = "1357"; //棱位 
			var jiaowei = "0268"; //角位
			var colorseq = ["green", "red", "blue", "yellow"];

			for (var i = 0; i < colordata.length; i++) {
				for (var j = 0; j < colordata[i].length; j++) {
					if ('white' == colordata[i][j]) {
						w_index += "," + faces[i] + "" + j;
						if (jiaowei.indexOf(j) >= 0) {  //var  jiaowei="0268"; 
							checkeeee += faces[i];
							var this_w_len_index = "" + faces[i] + "" + j
							w_len_index += "," + this_w_len_index;


						}
					}
				}
			}

			// 白色9块分布于:,b0,c2,e1,e3,e4,e5,e6,e7,f6
			// index_mofang.html:622 白色角位:,b0,c2,e6,f6
			// index_mofang.html:631 checkeeee是:bcef,其中是否有a:false
			// 同理也是先将1个白色角块转至A面。然后定位于A0,然后对应相应颜色。共3个步骤
			var hasa = (checkeeee.indexOf("a") >= 0)
			// console.log("白色9块分布于:"+w_index);	 	
			// console.log("白色角位:"+w_len_index);	 //a3,a5,e5,e7 
			// 	console.log("checkeeee是:"+ checkeeee+",其中是否有a:" + hasa);



			if (1 <= 100) {
				if (checkeeee.indexOf("a") < 0) {
					if (checkeeee.indexOf("b") >= 0) {
						U1all();
						step2();
					} else if (checkeeee.indexOf("c") >= 0) {
						Uall();
						step2();
					} else if (checkeeee.indexOf("d") >= 0) {
						Uall(); Uall();
						step2();
					} else if (checkeeee.indexOf("f") >= 0) {
						// 白角块在F面时有2个路线。
						var fn = w_len_index.substr(w_len_index.indexOf("f") + 1, 1);
						if (fn == 0) { U(); F1(); U1(); F() }
						if (fn == 2) { F1(); U1(); F() }
						if (fn == 6) { U1(); F1(); U(); F(); }
						if (fn == 8) { F1(); U(); F(); }
						step2();
					} else {
						//eeee就不拧了,先检查再拧。
					}
				} else {
					// console.log("has a and :a"+   w_len_index.substr(w_len_index.indexOf("a")+1,1) );
					var fn = w_len_index.substr(w_len_index.indexOf("a") + 1, 1);
					var aindex = (w_len_index.indexOf("a" + fn) - 1) / 3;

					if (fn == 0) { }
					if (fn == 2) { U1(); R(); U(); R1(); }
					if (fn == 6) { R(); U(); R1(); U1(); }
					if (fn == 8) { R1(); U1(); R(); U(); }
					//A0已经有一个白角块了。到时间看下是什么颜色了。
					var colorB = colordata[1][2];
					var bcolor = colordata[1][4];
					var N = 4 + colorseq.indexOf(bcolor) - colorseq.indexOf(colorB);
					for (var i = 0; i < N; i++) {
						U1all(); U();
					}
					U1(); F1(); U(); F();

				}
			}
			// console.log(" step2执行了" +  step2_times + "次" );

		}

		var checkokstep1 = function () {
			if (colordata[4][1] === colordata[4][4] &&
				colordata[4][3] === colordata[4][4] &&
				colordata[4][5] === colordata[4][4] &&
				colordata[4][7] === colordata[4][4]) {
				if (colordata[0][7] === colordata[0][4] &&
					colordata[1][7] === colordata[1][4] &&
					colordata[2][7] === colordata[2][4] &&
					colordata[3][7] === colordata[3][4]) {
					// console.log("底部小白花");
					return true;
				}
			}
			return false;
		}

		var checkokstep2 = function () { //底层ok
			if (colordata[4][1] === colordata[4][4] &&
				colordata[4][3] === colordata[4][4] &&
				colordata[4][5] === colordata[4][4] &&
				colordata[4][7] === colordata[4][4] &&
				colordata[4][0] === colordata[4][4] &&
				colordata[4][2] === colordata[4][4] &&
				colordata[4][4] === colordata[4][4] &&
				colordata[4][8] === colordata[4][4]) {
				if (colordata[0][6] === colordata[0][4] && colordata[0][7] === colordata[0][4] && colordata[0][8] === colordata[0][4] &&
					colordata[1][6] === colordata[1][4] && colordata[1][7] === colordata[1][4] && colordata[1][8] === colordata[1][4] &&
					colordata[2][6] === colordata[2][4] && colordata[2][7] === colordata[2][4] && colordata[2][8] === colordata[2][4] &&
					colordata[3][6] === colordata[3][4] && colordata[2][7] === colordata[2][4] && colordata[2][8] === colordata[2][4]) {
					// console.log("底层");
					return true;
				}
			}
			return false;
		}






		function s3_zhongcheng(argument) {
			var times = 30;
			step3_times = 0;
			for (var i = 0; i < times; i++) {
				step3();
				if (checkokstep3()) { break; }
			}
			fillcolor2box(colordata);
			console.log('3中间层完成');
		}

		function step3(argument) {
			// 思路也是把4个找出来。且把他们固定在A1位置。然后判定颜色,然后根据公式旋转。
			// 如何找?经过12步骤,中层块只有4个,且只可能在f1357,a35,d35,这8个位置。去掉有顶色的块,剩下就是

			var fcolro = colordata[5][4];
			var maybepos = ["f1", "f3", "f5", "f7", "a3", "a5", "d3", "d5"];
			var maybeposa = ["d1", "b1", "c1", "a1", "b5", "c3", "c5", "b3"];
			var maybecolor = [];
			var maybecolora = [];
			var pos = [];
			var posa = [];
			var color3 = [];
			var color3a = [];
			var checkeeee = "";
			var faces = "abcdef".split("");
			maybecolor = maybepos.map(function (v, i) {
				return colordata[faces.indexOf(v.substr(0, 1))][v.substr(1)];
			});
			maybecolora = maybeposa.map(function (v, i) {
				return colordata[faces.indexOf(v.substr(0, 1))][v.substr(1)];
			});

			for (var i = 0; i < maybecolor.length; i++) {
				if (maybecolor[i] != fcolro && maybecolora[i] != fcolro) {
					checkeeee += maybepos[i].substr(0, 1);
					pos.push(maybepos[i]);
					posa.push(maybeposa[i]);
					color3.push(maybecolor[i]);
					color3a.push(maybecolora[i]);
				}
			}
			// console.log(fcolro);
			// console.log(pos);
			// console.log(posa);		
			// console.log(color3);
			// console.log(color3a);
			// console.log(checkeeee);
			var colorseq = ["green", "red", "blue", "yellow"];
			step3_times++;
			if (step3_times <= 100) {
				if (checkeeee.indexOf("f") < 0) {
					if (checkeeee.indexOf("a") >= 0) {
						if (pos.indexOf("a3") >= 0 && checknotokstep3("a3")) {
							U1(); F1(); U(); F(); U(); R(); U1(); R1(); step3();
						} else if (pos.indexOf("a5") >= 0 && checknotokstep3("a5")) { // a5
							Uall(); step3();
						}
					} else if (checkeeee.indexOf("d") < 0) {
						if (pos.indexOf("d3") >= 0 && checknotokstep3("d3")) {
							U1all(); U1all(); step3();
						} else if (pos.indexOf("d5") >= 0 && checknotokstep3("d5")) { // a5
							Uall(); step3();
						}
					}
				} else {
					//公式f1357 
					var fn = 0;
					for (var i = 0; i < pos.length; i++) {
						if (pos[i].indexOf("f") >= 0) {
							fn = i;
						}
					}
					// console.log(pos[fn]);
					// console.log(color3[fn]);
					// console.log(color3a[fn]);
					// console.log(4+colorseq.indexOf(color3[fn])-colorseq.indexOf(color3a[fn]));
					// console.log(colorseq);
					if (colorseq.indexOf(color3[fn]) - colorseq.indexOf(color3a[fn]) == -1 || colorseq.indexOf(color3[fn]) - colorseq.indexOf(color3a[fn]) == 3) {
						// console.log("顺:" + color3[fn] + color3a[fn] ); 
						//顺就放到f7
						if (pos[fn] == "f1") { U(); U(); }
						if (pos[fn] == "f3") { U1(); }
						if (pos[fn] == "f5") { U(); }
						var N = 4 + colorseq.indexOf(colordata[0][4]) - colorseq.indexOf(color3a[fn]);
						for (var i = 0; i < N; i++) {
							U1all(); U();
						}
						//u1f1ufuru1r
						U1(); F1(); U(); F(); U(); R(); U1(); R1();
					} else {
						//反就放到f3
						if (pos[fn] == "f1") { U1(); }
						if (pos[fn] == "f5") { U(); U(); }
						if (pos[fn] == "f7") { U(); }
						// console.log("反:" + color3[fn] + color3a[fn] ); 
						var N = 4 + colorseq.indexOf(colordata[0][4]) - colorseq.indexOf(color3[fn]);
						for (var i = 0; i < N; i++) {
							U1all(); U();
						}
						U(); R(); U1(); R1(); U1(); F1(); U(); F();
					}
				}
			}


		}

		function checkokstep3() { //中层ok
			if (checkokstep2) {
				if (colordata[0][3] === colordata[0][4] && colordata[0][5] === colordata[0][4] &&
					colordata[1][3] === colordata[1][4] && colordata[1][5] === colordata[1][4] &&
					colordata[2][3] === colordata[2][4] && colordata[2][5] === colordata[2][4] &&
					colordata[3][3] === colordata[3][4] && colordata[2][5] === colordata[2][4]) {
					// console.log("中层");
					return true;
				}
			}
			return false;
		}

		function checknotokstep3(pos) {
			if (pos == "a3") {
				var a = colordata[0][3];
				var b = colordata[0][4];
				var c = colordata[1][5];
				var d = colordata[1][4];
				return (a != b) || (c != d);
			}
			if (pos == "a5") { return (colordata[0][5] != colordata[0][4]) || (colordata[2][3] != colordata[2][4]); }
			if (pos == "d3") { return (colordata[3][3] != colordata[3][4]) || (colordata[2][5] != colordata[2][4]); }
			if (pos == "d5") { return (colordata[3][5] != colordata[3][4]) || (colordata[1][3] != colordata[1][4]); }
		}

	</script>
</head>

<body>
	<div class="divbuttons">
		<input type="button" class="button" value="U'" onclick="U1_End()">
		<input type="button" class="button" value="U" onclick="U_End()">

	</div>
	<div class="container">
		<!-- 左边两个按钮 -->
		<div class="divbuttons" style="float: left;height: 100%;width: 100px;line-height: 161px;padding: 32px;">
			<input type="button" class="button" value="F'" onclick="F1_End()">
			<input type="button" class="button" value="F" onclick="F_End()">
		</div>

		<!-- 正方体 -->
		<div class="box">
			<div class="content">
				<div class="aside face"> <!--魔方第一个面,类名aside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="bside face"> <!--魔方第2个面,类名bside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="cside face"> <!--魔方第3个面,类名cside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="dside face"> <!--魔方第一4个面,类名dside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="eside face"> <!--魔方第5个面,类名eside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="fside face"> <!--魔方第6个面,类名fside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
			</div>
		</div>

		<div class="boxmin">
			<div class="content">
				<div class="aside face"> <!--魔方第一个面,类名aside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="bside face"> <!--魔方第2个面,类名bside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="cside face"> <!--魔方第3个面,类名cside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="dside face"> <!--魔方第一4个面,类名dside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="eside face"> <!--魔方第5个面,类名eside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
				<div class="fside face"> <!--魔方第6个面,类名fside-->
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
					<div class="minibox"></div>
				</div>
			</div>
		</div>

	</div>
	<div class="divbuttons">

		<input type="button" class="button" value="R'" onclick="R1_End()">
		<input type="button" class="button" value="R" onclick="R_End()">
		<input type="button" class="button" value="B'" onclick="B1_End()">
		<input type="button" class="button" value="B" onclick="B_End()"><br>

		<input type="button" class="button" value="<-all" onclick="Uall_End()">
		<input type="button" class="button" value="all'->" onclick="U1all_End()">
		<input type="button" class="button" value="打乱" onclick="Rndx()">
		<br>
		<input type="button" class="button" value="1底层小白花" onclick="s1_xiaobai()">
		<input type="button" class="button" value="2底层归位" onclick="s2_dicheng()">
		<input type="button" class="button" value="3中层归位" onclick="s3_zhongcheng()">
	 
	</div>

</body>

</html>

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/716426.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

微信小程序之Image那些事

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 前言一、使用场景二、使用方式1.动态读取image大小2.动态设置style3.动态赋值 总结 前言 小程序中 Image使用频率是非常高的 不同场景下 Image使用的属性也不一样 …

中级保育员专业知识卫生管理考试题库及答案

本题库是根据最新考试大纲要求&#xff0c;结合近年来考试真题的重难点进行汇编整理组成的全真模拟试题&#xff0c;考生们可以进行专项训练&#xff0c;查漏补缺巩固知识点。本题库对热点考题和重难点题目都进行了仔细的整理和编辑&#xff0c;相信考生在经过了针对性的刷题练…

【Redisson】Redisson--话题(订阅分发)

Redisson系列文章&#xff1a; 【Redisson】Redisson–基础入门【Redisson】Redisson–布隆(Bloom Filter)过滤器【Redisson】Redisson–分布式锁的使用&#xff08;推荐使用&#xff09;【分布式锁】Redisson分布式锁底层原理【Redisson】Redisson–限流器、【Redisson】Redi…

你知道ai绘画以图生图软件怎么使用吗?

小美&#xff1a;嗨&#xff0c;张华&#xff0c;你听说过这个令人难以置信的新技术“以图生图ai绘画”吗&#xff1f;它简直让人惊叹&#xff01; 张华&#xff1a;没有&#xff0c;我还没有听说过。什么是以图生图ai绘画&#xff1f; 小美&#xff1a;你看这些美丽的照片&a…

Apikit 自学日记:创建自动化测试项目

在API 自动化测试中&#xff0c;所有的测试用例都是以项目维度来进行管理&#xff0c;一个自动化测试项目可以从多个API文档项目中引用API信息来创建API测试用例。 点击左侧菜单栏&#xff0c;进入 API自动化测试 项目列表页&#xff0c;点击添加按钮&#xff1a; 在弹窗中输入…

六大排序——(插入、希尔、选择、交换、归并、计数)

目录 一、插入排序 二、希尔排序 三、选择排序 1&#xff09;直接选择排序&#xff1a; 2&#xff09;堆排序 四、交换排序 1&#xff09;冒泡排序 2&#xff09;快速排序 1、Hoare版 2、挖坑法 3、前后指针 快排优化 快速排序非递归来实现 快排总结 五、归并排…

Spring整合Junit单元测试

1.Spring整合Junit单元测试 1.1 原始Junit测试Spring的问题 在测试类中&#xff0c;每个测试方法都有以下两行代码&#xff1a; ApplicationContext ac new ClassPathXmlApplicationContext("application.xml");BookDao bookDao (BookDao)ac.getBean("bookDa…

环二肽试剂:Cyclo(D-Tyr-D-Phe),对A549细胞具有抗tumor活性

英文名称&#xff1a;Cyclo(D-Tyr-D-Phe)产品结构式&#xff1a; 产品规格&#xff1a; 1.CAS号&#xff1a;N/A 2.分子式&#xff1a;C18H18N2O3 3.分子量&#xff1a;310.35 4.包装规格&#xff1a;1g、5g、10g&#xff0c;包装灵活 5.外观颜色&#xff1a;固体/粉末 6.溶解条…

【⑩MySQL】:表管理,让数据管理不再困难

前言 ✨欢迎来到小K的MySQL专栏&#xff0c;本节将为大家带来MySQL表/数据库创建和管理的讲解✨ 目录 前言1. 基础知识2. 创建和管理数据库3.创建表4. 修改表5. 删除表6.总结 1. 基础知识 ✨1.1 表的基本概念 在MySQL数据库中&#xff0c;表是一种很重要的数据库对象&#xf…

酷炫音乐盒: 使用Python和Tkinter打造自己的音乐播放器

前言 Python的Tkinter&#xff08;Tk接口&#xff09;是一个用于创建图形用户界面&#xff08;GUI&#xff09;的标准库。它是Python的内置模块&#xff0c;无需额外安装即可使用。Tkinter提供了一组部件&#xff08;如按钮、标签、文本框等&#xff09;和布局管理器&#xff…

ROS学习——运行管理

ROS是多进程(节点)的分布式框架&#xff0c;一个完整的ROS系统实现&#xff1a; 可能包含多台主机&#xff1b; 每台主机上又有多个工作空间(workspace)&#xff1b; 每个的工作空间中又包含多个功能包(package)&#xff1b; 每个功能包又包含多个节点(Node)&#xff0c;不同的…

MyBatis—操作数据库

MyBatis &#x1f50e;前置铺垫创建数据库MyBatis 的执行流程创建对应流程 &#x1f50e;MyBatis—查询查询用户信息执行流程创建实体类创建 Interface 与 xml在 xml 中编写 SQL 语句模拟执行流程 &#x1f50e;单元测试定义优点执行单元测试引入依赖生成单元测试编写代码Asser…

优思学院|制造不良品是品质成本意识的问题吗?

制造的最大错误&#xff0c;就是制造出不良品或者不适合的物品。 谁都知道制造出这类“不良品”会使成本增加&#xff0c;但是到底会增加什么成本&#xff0c;可能就不是人人 都清楚。 若是不小心制造出不适合品&#xff0c;浪费的成本除了该物品的材料费、加工人力的费用、设…

VR电力安全警示教育:身临其境体验事故伤害

VR电力安全警示教育由广州华锐互动开发&#xff0c;是一种利用虚拟现实技术模拟电厂安全事故的应用程序。该应用程序通过模拟真实的场景和情境&#xff0c;让用户身临其境地体验VR电力安全警示教育的过程&#xff0c;从而提高用户的安全意识和应对能力。 在VR电力安全警示教育中…

Linux下获取另外一个程序的标准输出和标准错误输出的一种实现方式

问题&#xff1a;一个程序如何获取另外一个程序的标准输出和标准错误输出&#xff1f; 标准输入&#xff0c;标准输出&#xff0c;标准错误输出是一个程序的基本组成&#xff0c;在Linux下一个程序调用另外一个程序&#xff0c;如何获取其标准输出和错误输出呢&#xff1f; 分析…

专用开发工具和环境在嵌入式系统开发中的重要性

嵌入式系统是一种特殊类型的计算机系统&#xff0c;其设计和开发用于控制特定设备或执行特定任务。以下是嵌入式系统的一些特点以及与其开发相关的专用工具和环境&#xff1a; 特定目标&#xff1a;嵌入式系统通常被设计用于执行特定的任务或控制特定的设备。它们被定制以满足特…

开发一款财经直播系统需要注意的方面

数据保护与隐私&#xff1a;确保用户的个人信息和交易数据得到有效的保护&#xff0c;遵守相关的数据保护法规。采用高级加密技术来保护用户的敏感信息&#xff0c;并建立安全的存储和传输机制。 信息真实性&#xff1a;提供准确、可信的财经信息&#xff0c;确保平台上发布…

【Jenkins】Jenkins构建后端流水线

目录 一、新建任务1、输入任务名称&#xff0c;选择构建项目类型&#xff08;这里我选择的是Maven项目&#xff09;&#xff0c;任务名称一般格式为&#xff1a;项目名称-前后端2、创建成功后的结果 二、配置流水线1、进入刚创建好的任务页面中&#xff0c;点击配置2、General配…

Loki+Grafana监控docker容器日志

目标&#xff1a;最近开发人员时常需要查看各个环境项目中容器日志&#xff0c;而直接通过ssh终端使用docker logs命令查看日志不太安全&#xff0c;这会导致很多人员知道服务器的账户和密码&#xff0c;有没有一种可以收集所有容器日志的平台系统。那么这套系统就是LokiGrafan…

3.3C++输入流

C 输入概述 C输入是指程序从外部获取数据的过程。 C提供多种输入方法&#xff0c;包括从键盘输入、从文件读取、从网络获取&#xff0c;最常用的是从键盘输入。 C输入数据的函数是cin&#xff0c;它可以读取各种类型的数据&#xff0c;包括整数、浮点数、字符和字符串等。 …