|
|
// 准备一些变量
var a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0;
var a1 = 0, b1 = 0, c1 = 0, d1 = 0, e1 = 0, f1 = 0, g1 = 0, h1 = 0;
var a2, b2, c2, d2, e2, f2, g2, h2;
// 设置模拟器
$("#begin").click(function () {
$("#free div").each(function () {
$(this).prop('class', 'empty');
});
getBefore();
$("#free div").each(function (i) {
var id = $(this).prop("id");
if (id == "a3") {
if (a1 > 0) {
$(this).prop('class', 'full');
}
}
if (id == "b3") {
if (b1 > 0) {
$(this).prop('class', 'full');
}
}
if (id == "c3") {
if (c1 > 0) {
$(this).prop('class', 'full');
}
}
if (id == "d3") {
if (d1 > 0) {
$(this).prop('class', 'full');
}
}
if (id == "e3") {
if (e1 > 0) {
$(this).prop('class', 'full');
}
}
if (id == "f3") {
if (f1 > 0) {
$(this).prop('class', 'full');
}
}
if (id == "g3") {
if (g1 > 0) {
$(this).prop('class', 'full');
}
}
if (id == "h3") {
if (h1 > 0) {
$(this).prop('class', 'full');
}
}
});
});
function getColor(now) {
if ($(now).prop("className")== 'empty') {
return 0;
} else {
return 1;
}
}
// 获取数据
function getBefore() {
$("#before div").each(function (i) {
var id = $(this).prop("id");
if (id == "a1") {
a1 = getColor($(this));
}
if (id == "b1") {
b1 = getColor($(this));
}
if (id == "c1") {
c1 = getColor($(this));
}
if (id == "d1") {
d1 = getColor($(this));
}
if (id == "e1") {
e1 = getColor($(this));
}
if (id == "f1") {
f1 = getColor($(this));
}
if (id == "g1") {
g1 = getColor($(this));
}
if (id == "h1") {
h1 = getColor($(this));
}
});
}
// 开始计算
$("#go").click(function () {
getBefore();
$("#after div").each(function () {
$(this).prop('class', 'empty');
});
for (a = 0; a <= 1; a++)
{
for (b = 0; b <= 1; b++)
{
for (c = 0; c <= 1; c++)
{
for (d = 0; d <= 1; d++)
{
for (e = 0; e <= 1; e++)
{
for (f = 0; f <= 1; f++)
{
for (g = 0; g <= 1; g++)
{
for (h = 0; h <= 1; h++)
{
a2 = h + a + b + a1;
b2 = a + b + c + b1;
c2 = b + c + d + c1;
d2 = c + d + e + d1;
e2 = d + e + f + e1;
f2 = e + f + g + f1;
g2 = f + g + h + g1;
h2 = g + h + a + h1;
if (((a2 == 0) || (a2 == 2) || (a2 == 4)) && ((b2 == 0) || (b2 == 2) || (b2 == 4)) && ((c2 == 0) || (c2 == 2) || (c2 == 4)) && ((d2 == 0) || (d2 == 2) || (d2 == 4))
&& ((e2 == 0) || (e2 == 2) || (e2 == 4)) && ((f2 == 0) || (f2 == 2) || (f2 == 4)) && ((g2 == 0) || (g2 == 2) || (g2 == 4)) && ((h2 == 0) || (h2 == 2) || (h2 == 4)))
{
// 输出结果
$("#after div").each(function (i) {
var id = $(this).prop("id");
if (id == "a2") {
if (a == 0) {
$(this).prop('class', 'full');
}
}
if (id == "b2") {
if (b == 0) {
$(this).prop('class', 'full');
}
}
if (id == "c2") {
if (c == 0) {
$(this).prop('class', 'full');
}
}
if (id == "d2") {
if (d == 0) {
$(this).prop('class', 'full');
}
}
if (id == "e2") {
if (e == 0) {
$(this).prop('class', 'full');
}
}
if (id == "f2") {
if (f == 0) {
$(this).prop('class', 'full');
}
}
if (id == "g2") {
if (g == 0) {
$(this).prop('class', 'full');
}
}
if (id == "h2") {
if (h == 0) {
$(this).prop('class', 'full');
}
}
});
return false; // 成功跳出循环
}
}
}
}
}
}
}
}
}
}); |
|