JScript
Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: General Discussion
Forum Description: General discussion and chat on any topic.
URL: https://forums.webwiz.net/forum_posts.asp?TID=14389
Printed Date: 01 April 2026 at 5:47am Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com
Topic: JScript
Posted By: VBScript
Subject: JScript
Date Posted: 23 March 2005 at 12:30pm
Can any one help me comment the following code please?
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
//Maximum number of disks
var MAXHEIGHT = 8;
//Number of selected disks
var ndisk;
//Timer variable
var timer = null;
//Move from array (0-255)
var mvfrom = new Array(255);
//Move to array (0-255)
var mvto = new Array(255);
var mv, imv;
//Tower Array
var tower = new Array(3);
var h = new Array(3);
var spc = " ";
//Set disk name array
var dname = new Array(
"|",
"111",
"22222",
"3333333",
"444444444",
"55555555555",
"6666666666666",
"777777777777777",
"88888888888888888");
function init() {
// Initallize function
if (!timer) {
//If timer is not set, set s to the selected number of disks
s = document.formHanoi.disk.options[document.formHanoi.disk.selectedIndex].value;
if (s == "random") {
//If s is set to random then get the date
now = new Date();
ndisk = parseInt(now.getTime() / 1000) % 8 + 1;
//delete the now variable and its content
delete now;
}
else ndisk = s;
//number of moves = 0
mv = 0;
//Call hanoi function
hanoi(0, 2, 1, ndisk);
for (i = 0; i < 3; i++)
tower = new Array(MAXHEIGHT);
for (i = 0; i < ndisk; i++)
tower[0] = ndisk - i;
h[0] = ndisk;
h[1] = h[2] = 0;
imv = 0;
document.formHanoi.display.value = gentower();
timer =
window.setTimeout("gennexttower()",
document.formHanoi.delay.options[document.formHanoi.delay.selectedIndex].value);
}
}
function stop() {
if (timer) {
//If the timer is not empty then clear it
//and set to nothing
window.clearTimeout(timer);
timer = null;
}
}
function hanoi(from,to,buf,nmv) {
if (nmv > 1) {
hanoi(from, buf, to, nmv - 1);
mvfrom[mv] = from;
mvto[mv++] = to;
hanoi(buf, to, from, nmv - 1);
}
else {
mvfrom[mv] = from;
mvto[mv++] = to;
}
}
function gennexttower() {
tower[mvto[imv]][h[mvto[imv]]++] = tower[mvfrom[imv]][--h[mvfrom[imv]]];
document.formHanoi.display.value = gentower();
if (++imv < mv)
timer =
window.setTimeout("gennexttower()",
document.formHanoi.delay.options[document.formHanoi.delay.selectedIndex].value);
else {
for (i = 0; i < 3; i++)
delete tower;
timer = null;
}
}
function gentower() {
s = " \n";
for (i = MAXHEIGHT - 1; i >= 0; i--) {
for (j = 0; j < tower.length; j++) {
len = i < h[j] ? tower[j] : 0;
width = MAXHEIGHT - len;
s += " " + spc.substring(0, width) + dname[len] + spc.substring(0, width);
}
s += "\n";
}
return s+"=======================================================";
}
-->
</script>
|
Replies:
Posted By: Phat
Date Posted: 23 March 2005 at 6:30pm
|
what's the problem? There are comments in there.
|
Posted By: VBScript
Date Posted: 24 March 2005 at 2:40am
|
Only half of it is commented. I dont understand the rest, i am not an
expert in Javascript I hoped someone could help finish the commenting.
|
|