用JavaScript寫了一個Scrambler - 魔術方塊

Table of Contents

最近在學習JavaScript,今天利用JavaScript寫了一個Scrambler的簡單簡單簡單程式,
,隨機出現亂數原始碼如下:

<script language="javascript">
function one()
{
x=Math.round(Math.random()*6)
if(x==1){document.write("R")}
if(x==2){document.write("L")}
if(x==3){document.write("U")}
if(x==4){document.write("D")}
if(x==5){document.write("F")}
if(x==6){document.write("B")}
}
function two()
{
a=Math.round(Math.random()*3)
if(a==1){document.write("")}
if(a==2){document.write("'")}
if(a==3){document.write("2")}
}
for(z=0;z<26;z=z+1){
one()+two()
}
</script>

設計原理:利用Javascript的亂數函數隨機獲得1~6的數字以及1~3的數字,1~6每一個
數字對應到(RLUDBF),1~3對應到(無、'、2),最後執行25次,得到25個亂數。

附註:
如果你有看出來,會發現本程式並沒有達到「真正的隨機」......而且有BUG的問題...

--
今古庸龍魔方網http://dragoncube.org/
今古庸龍魔方論壇http://dragoncube.org/forum/
台灣香港澳門魔術方塊俱樂部

--

All Comments

Leila avatarLeila2009-03-05
推, 不過有可能會出現連續兩個相同轉法, 如F2接F2或R 接R'
Ula avatarUla2009-03-05
樓上駭客任務救世主來的 我只看到一堆字母符號與數字
Catherine avatarCatherine2009-03-06
雖沒有到"真正的隨機", 但是架構已經有了. 推分享 :D
Edith avatarEdith2009-03-06
第一次寫出來,算不錯了! 慢慢再加些新東西上去吧
Aaliyah avatarAaliyah2009-03-06
我沒有學過,不過可以把數字取亂數範圍為5,加在前一個
Isla avatarIsla2009-03-09
數字上,如果超過 7 則減 6,這樣應該不會連續兩個一樣