From caaec4a6d77d8cc15ba9d393ca460cd528ea4b43 Mon Sep 17 00:00:00 2001 From: nanochess Date: Tue, 16 Feb 2021 15:58:54 -0600 Subject: [PATCH 1/4] Ported ANIMAL to Javascript --- 03 Animal/javascript/animal.html | 10 ++ 03 Animal/javascript/animal.js | 162 +++++++++++++++++++++++++++++++ 2 files changed, 172 insertions(+) create mode 100644 03 Animal/javascript/animal.html create mode 100644 03 Animal/javascript/animal.js diff --git a/03 Animal/javascript/animal.html b/03 Animal/javascript/animal.html new file mode 100644 index 00000000..d13d8c7b --- /dev/null +++ b/03 Animal/javascript/animal.html @@ -0,0 +1,10 @@ + + +ANIMAL + + +

+
+
+
+
diff --git a/03 Animal/javascript/animal.js b/03 Animal/javascript/animal.js
new file mode 100644
index 00000000..a9deae8c
--- /dev/null
+++ b/03 Animal/javascript/animal.js	
@@ -0,0 +1,162 @@
+// ANIMAL
+//
+// Converted from BASIC to Javascript by Oscar Toledo G. (nanochess)
+//
+
+function print(str)
+{
+    document.getElementById("output").appendChild(document.createTextNode(str));
+}
+
+function input()
+{
+    var input_element;
+    var input_str;
+    
+    return new Promise(function (resolve) {
+                       input_element = document.createElement("INPUT");
+                       
+                       print("? ");
+                       input_element.setAttribute("type", "text");
+                       input_element.setAttribute("length", "50");
+                       document.getElementById("output").appendChild(input_element);
+                       input_element.focus();
+                       input_str = undefined;
+                       input_element.addEventListener("keydown", function (event) {
+                                                      if (event.keyCode == 13) {
+                                                        input_str = input_element.value;
+                                                        document.getElementById("output").removeChild(input_element);
+                                                        print(input_str);
+                                                        print("\n");
+                                                        resolve(input_str);
+                                                      }
+                                                      });
+                       });
+}
+
+function tab(space)
+{
+    var str = "";
+    while (space-- > 0)
+        str += " ";
+    return str;
+}
+
+print(tab(32) + "ANIMAL\n");
+print(tab(15) + "CREATIVE COMPUTING  MORRISTOWN, NEW JERSEY\n");
+print("\n");
+print("\n");
+print("\n");
+print("PLAY 'GUESS THE ANIMAL'\n");
+print("\n");
+print("THINK OF AN ANIMAL AND THE COMPUTER WILL TRY TO GUESS IT.\n");
+print("\n");
+
+var k;
+var n;
+var str;
+var q;
+var z;
+var c;
+var t;
+
+var animals = [
+               "\\QDOES IT SWIM\\Y1\\N2\\",
+               "\\AFISH",
+               "\\ABIRD",
+               ];
+
+n = animals.length;
+
+function show_animals() {
+    var x;
+    
+    print("\n");
+    print("ANIMALS I ALREADY KNOW ARE:\n");
+    str = "";
+    x = 0;
+    for (var i = 0; i < n; i++) {
+        if (animals[i].substr(0, 2) == "\\A") {
+            while (str.length < 15 * x)
+                str += " ";
+            for (var z = 2; z < animals[i].length; z++) {
+                if (animals[i][z] == "\\")
+                    break;
+                str += animals[i][z];
+            }
+            x++;
+            if (x == 4) {
+                x = 0;
+                print(str + "\n");
+                str = "";
+            }
+        }
+    }
+    if (str != "")
+        print(str + "\n");
+}
+
+// Main control section
+async function main()
+{
+    while (1) {
+        while (1) {
+            print("ARE YOU THINKING OF AN ANIMAL");
+            str = await input();
+            if (str == "LIST")
+                show_animals();
+            if (str[0] == "Y")
+                break;
+        }
+        
+        k = 0;
+        do {
+            // Subroutine to print questions
+            q = animals[k];
+            while (1) {
+                str = "";
+                for (z = 2; z < q.length; z++) {
+                    if (q[z] == "\\")
+                        break;
+                    str += q[z];
+                }	
+                print(str);
+                c = await input();
+                if (c[0] == "Y" || c[0] == "N")
+                    break;
+            }
+            t = "\\" + c[0];
+            x = q.indexOf(t);
+            k = parseInt(q.substr(x + 2));	
+        } while (animals[k].substr(0,2) == "\\Q") ;
+        
+        print("IS IT A " + animals[k].substr(2));
+        a = await input();
+        if (a[0] == "Y") {
+            print("WHY NOT TRY ANOTHER ANIMAL?\n");
+            continue;
+        }
+        print("THE ANIMAL YOU WERE THINKING OF WAS A ");
+        v = await input();
+        print("PLEASE TYPE IN A QUESTION THAT WOULD DISTINGUISH A\n");
+        print(v + " FROM A " + animals[k].substr(2) + "\n");
+        x = await input();
+        while (1) {
+            print("FOR A " + v + " THE ANSWER WOULD BE ");
+            a = await input();
+            a = a.substr(0, 1);
+            if (a == "Y" || a == "N")
+                break;
+        }
+        if (a == "Y")
+            b = "N";
+        if (a == "N")
+            b = "Y";
+        z1 = animals.length;
+        animals[z1] = animals[k];
+        animals[z1 + 1] = "\\A" + v;
+        animals[k] = "\\Q" + x + "\\" + a + (z1 + 1) + "\\" + b + z1 + "\\";
+    }
+}
+
+main();

From 837ed7e93a0b02e18039bf6d5c7217a72f7851b1 Mon Sep 17 00:00:00 2001
From: nanochess 
Date: Tue, 16 Feb 2021 16:48:04 -0600
Subject: [PATCH 2/4] Ported ACEY DUCEY to Javascript

---
 01 Acey Ducey/javascript/aceyducey.html |   9 ++
 01 Acey Ducey/javascript/aceyducey.js   | 135 ++++++++++++++++++++++++
 2 files changed, 144 insertions(+)
 create mode 100644 01 Acey Ducey/javascript/aceyducey.html
 create mode 100644 01 Acey Ducey/javascript/aceyducey.js

diff --git a/01 Acey Ducey/javascript/aceyducey.html b/01 Acey Ducey/javascript/aceyducey.html
new file mode 100644
index 00000000..991e3b5c
--- /dev/null
+++ b/01 Acey Ducey/javascript/aceyducey.html	
@@ -0,0 +1,9 @@
+
+
+ACEY DUCEY
+
+
+

+
+
+
diff --git a/01 Acey Ducey/javascript/aceyducey.js b/01 Acey Ducey/javascript/aceyducey.js
new file mode 100644
index 00000000..cefc062f
--- /dev/null
+++ b/01 Acey Ducey/javascript/aceyducey.js	
@@ -0,0 +1,135 @@
+// ACEY DUCEY
+//
+// Converted from BASIC to Javascript by Oscar Toledo G. (nanochess)
+//
+
+function print(str)
+{
+    document.getElementById("output").appendChild(document.createTextNode(str));
+}
+
+function input()
+{
+    var input_element;
+    var input_str;
+    
+    return new Promise(function (resolve) {
+                       input_element = document.createElement("INPUT");
+                       
+                       print("? ");
+                       input_element.setAttribute("type", "text");
+                       input_element.setAttribute("length", "50");
+                       document.getElementById("output").appendChild(input_element);
+                       input_element.focus();
+                       input_str = undefined;
+                       input_element.addEventListener("keydown", function (event) {
+                                                      if (event.keyCode == 13) {
+                                                      input_str = input_element.value;
+                                                      document.getElementById("output").removeChild(input_element);
+                                                      print(input_str);
+                                                      print("\n");
+                                                      resolve(input_str);
+                                                      }
+                                                      });
+                       });
+}
+
+function tab(space)
+{
+    var str = "";
+    while (space-- > 0)
+        str += " ";
+    return str;
+}
+
+print(tab(26) + "ACEY DUCEY CARD GAME\n");
+print(tab(15) + "CREATIVE COMPUTING  MORRISTOWN, NEW JERSEY\n");
+print("\n");
+print("\n");
+print("ACEY-DUCEY IS PLAYED IN THE FOLLOWING MANNER\n");
+print("THE DEALER (COMPUTER) DEALS TWO CARDS FACE UP\n");
+print("YOU HAVE AN OPTION TO BET OR NOT BET DEPENDING\n");
+print("ON WHETHER OR NOT YOU FEEL THE CARD WILL HAVE\n");
+print("A VALUE BETWEEN THE FIRST TWO.\n");
+print("IF YOU DO NOT WANT TO BET, INPUT A 0\n");
+
+function show_card(card)
+{
+    if (card < 11)
+        print(card + "\n");
+    else if (card == 11)
+        print("JACK\n");
+    else if (card == 12)
+        print("QUEEN\n");
+    else if (card == 13)
+        print("KING\n");
+    else
+        print("ACE\n");
+}
+
+// Main program
+async function main()
+{
+    q = 100;
+    while (1) {
+        print("YOU NOW HAVE " + q + " DOLLARS.\n");
+        print("\n");
+        
+        do {
+            print("HERE ARE YOUR NEXT TWO CARDS: \n");
+            do {
+                a = Math.floor(Math.random() * 12 + 2);
+                b = Math.floor(Math.random() * 12 + 2);
+            } while (a >= b) ;
+            show_card(a);
+            show_card(b);
+            print("\n");
+            while (1) {
+                print("\n");
+                print("WHAT IS YOUR BET");
+                m = parseInt(await input());
+                if (m > 0) {
+                    if (m > q) {
+                        print("SORRY, MY FRIEND, BUT YOU BET TOO MUCH.\n");
+                        print("YOU HAVE ONLY " + q + "DOLLARS TO BET.\n");
+                        continue;
+                    }
+                    break;
+                }
+                m = 0;
+                print("CHICKEN!!\n");
+                print("\n");
+                break;
+            }
+        } while (m == 0) ;
+        c = Math.floor(Math.random() * 12 + 2);
+        show_card(c);
+        if (c > a && c < b) {
+            print("YOU WIN!!!\n");
+            q = q + m;
+        } else {
+            print("SORRY, YOU LOSE\n");
+            if (m >= q) {
+                print("\n");
+                print("\n");
+                print("SORRY, FRIEND, BUT YOU BLEW YOUR WAD.\n");
+                print("\n");
+                print("\n");
+                print("TRY AGAIN (YES OR NO)");
+                a = await input();
+                print("\n");
+                print("\n");
+                if (a == "YES") {
+                    q = 100;
+                } else {
+                    print("O.K., HOPE YOU HAD FUN!");
+                    break;
+                }
+            } else {
+                q = q - m;
+            }
+        }
+    }
+}
+
+main();

From 13e3a977fec822bdf96077b0c613dc3f07040604 Mon Sep 17 00:00:00 2001
From: nanochess 
Date: Tue, 16 Feb 2021 16:49:05 -0600
Subject: [PATCH 3/4] Solved small bug in ACEY DUCYE Javascript

---
 01 Acey Ducey/javascript/aceyducey.js | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/01 Acey Ducey/javascript/aceyducey.js b/01 Acey Ducey/javascript/aceyducey.js
index cefc062f..d0983443 100644
--- a/01 Acey Ducey/javascript/aceyducey.js	
+++ b/01 Acey Ducey/javascript/aceyducey.js	
@@ -78,8 +78,8 @@ async function main()
         do {
             print("HERE ARE YOUR NEXT TWO CARDS: \n");
             do {
-                a = Math.floor(Math.random() * 12 + 2);
-                b = Math.floor(Math.random() * 12 + 2);
+                a = Math.floor(Math.random() * 13 + 2);
+                b = Math.floor(Math.random() * 13 + 2);
             } while (a >= b) ;
             show_card(a);
             show_card(b);
@@ -102,7 +102,7 @@ async function main()
                 break;
             }
         } while (m == 0) ;
-        c = Math.floor(Math.random() * 12 + 2);
+        c = Math.floor(Math.random() * 13 + 2);
         show_card(c);
         if (c > a && c < b) {
             print("YOU WIN!!!\n");

From 35fbfd5b67ceb36115e8bb445976ed5a4d9c8496 Mon Sep 17 00:00:00 2001
From: nanochess 
Date: Tue, 16 Feb 2021 18:13:41 -0600
Subject: [PATCH 4/4] Ported AMAZING to Javascript, also corrected BASIC source
 code

---
 02 Amazing/amazing.bas             |   2 +-
 02 Amazing/javascript/amazing.html |   9 +
 02 Amazing/javascript/amazing.js   | 319 +++++++++++++++++++++++++++++
 3 files changed, 329 insertions(+), 1 deletion(-)
 create mode 100644 02 Amazing/javascript/amazing.html
 create mode 100644 02 Amazing/javascript/amazing.js

diff --git a/02 Amazing/amazing.bas b/02 Amazing/amazing.bas
index c140f86f..63255319 100644
--- a/02 Amazing/amazing.bas	
+++ b/02 Amazing/amazing.bas	
@@ -80,7 +80,7 @@
 680 IF W(R+1,S)<>0 THEN 740
 685 IF S<>V THEN 700
 690 IF Z=1 THEN 730
-695 Q=1:GOTO 830
+695 Q=1:GOTO 710
 700 IF W(R,S+1)<>0 THEN 730
 710 X=INT(RND(1)*2+1)
 720 ON X GOTO 860,910
diff --git a/02 Amazing/javascript/amazing.html b/02 Amazing/javascript/amazing.html
new file mode 100644
index 00000000..c066a3e9
--- /dev/null
+++ b/02 Amazing/javascript/amazing.html	
@@ -0,0 +1,9 @@
+
+
+AMAZING
+
+
+

+
+
+
diff --git a/02 Amazing/javascript/amazing.js b/02 Amazing/javascript/amazing.js
new file mode 100644
index 00000000..427e0793
--- /dev/null
+++ b/02 Amazing/javascript/amazing.js	
@@ -0,0 +1,319 @@
+// AMAZING
+//
+// Converted from BASIC to Javascript by Oscar Toledo G. (nanochess)
+//
+
+function print(str)
+{
+    document.getElementById("output").appendChild(document.createTextNode(str));
+}
+
+function input()
+{
+    var input_element;
+    var input_str;
+    
+    return new Promise(function (resolve) {
+                       input_element = document.createElement("INPUT");
+                       
+                       print("? ");
+                       input_element.setAttribute("type", "text");
+                       input_element.setAttribute("length", "50");
+                       document.getElementById("output").appendChild(input_element);
+                       input_element.focus();
+                       input_str = undefined;
+                       input_element.addEventListener("keydown", function (event) {
+                                                      if (event.keyCode == 13) {
+                                                      input_str = input_element.value;
+                                                      document.getElementById("output").removeChild(input_element);
+                                                      print(input_str);
+                                                      print("\n");
+                                                      resolve(input_str);
+                                                      }
+                                                      });
+                       });
+}
+
+function tab(space)
+{
+    var str = "";
+    while (space-- > 0)
+        str += " ";
+    return str;
+}
+
+print(tab(28) + "AMAZING PROGRAM\n");
+print(tab(15) + "CREATIVE COMPUTING  MORRISTOWN, NEW JERSEY\n");
+print("\n");
+print("\n");
+print("\n");
+print("FOR EXAMPLE TYPE 10,10 AND PRESS ENTER\n");
+print("\n");
+
+// Main program
+async function main()
+{
+    while (1) {
+        print("WHAT ARE YOUR WIDTH AND LENGTH");
+        a = await input();
+        h = parseInt(a);
+        v2 = parseInt(a.substr(a.indexOf(",") + 1));
+        if (h > 1 && v2 > 1)
+            break;
+        print("MEANINGLESS DIMENSIONS.  TRY AGAIN.\n");
+    }
+    w = [];
+    v = [];
+    for (i = 1; i <= h; i++) {
+        w[i] = [];
+        v[i] = [];
+        for (j = 1; j <= v2; j++) {
+            w[i][j] = 0;
+            v[i][j] = 0;
+        }
+    }
+    print("\n");
+    print("\n");
+    print("\n");
+    print("\n");
+    q = 0;
+    z = 0;
+    x = Math.floor(Math.random() * h + 1);
+    for (i = 1; i <= h; i++) {
+        if (i == x)
+            print(".  ");
+        else
+            print(".--");
+    }
+    print(".\n");
+    c = 1;
+    w[x][1] = c;
+    c++;
+    r = x;
+    s = 1;
+    entry = 0;
+    while (1) {
+        if (entry == 2) {	// Search for a non-explored cell
+            do {
+                if (r < h) {
+                    r++;
+                } else if (s < v2) {
+                    r = 1;
+                    s++;
+                } else {
+                    r = 1;
+                    s = 1;
+                }
+            } while (w[r][s] == 0) ;
+        }
+        if (entry == 0 && r - 1 > 0 && w[r - 1][s] == 0) {	// Can go left?
+            if (s - 1 > 0 && w[r][s - 1] == 0) {	// Can go up?
+                if (r < h && w[r + 1][s] == 0) {	// Can go right?
+                    // Choose left/up/right
+                    x = Math.floor(Math.random() * 3 + 1);
+                } else if (s < v2) {
+                    if (w[r][s + 1] == 0) {	// Can go down?
+                        // Choose left/up/down
+                        x = Math.floor(Math.random() * 3 + 1);
+                        if (x == 3)
+                            x = 4;
+                    } else {
+                        x = Math.floor(Math.random() * 2 + 1);
+                    }
+                } else if (z == 1) {
+                    x = Math.floor(Math.random() * 2 + 1);
+                } else {
+                    q = 1;
+                    x = Math.floor(Math.random() * 3 + 1);
+                    if (x == 3)
+                        x = 4;
+                }
+            } else if (r < h && w[r + 1][s] == 0) {	// Can go right?
+                if (s < v2) {
+                    if (w[r][s + 1] == 0) {	// Can go down?
+                        // Choose left/right/down
+                        x = Math.floor(Math.random() * 3 + 1);
+                    } else {
+                        x = Math.floor(Math.random() * 2 + 1);
+                    }
+                    if (x >= 2)
+                        x++;
+                } else if (z == 1) {
+                    x = Math.floor(Math.random() * 2 + 1);
+                    if (x >= 2)
+                        x++;
+                } else {
+                    q = 1;
+                    x = Math.floor(Math.random() * 3 + 1);
+                    if (x >= 2)
+                        x++;
+                }
+            } else if (s < v2) {
+                if (w[r][s + 1] == 0) {	// Can go down?
+                    // Choose left/down
+                    x = Math.floor(Math.random() * 2 + 1);
+                    if (x == 2)
+                        x = 4;
+                } else {
+                    x = 1;
+                }
+            } else if (z == 1) {
+                x = 1;
+            } else {
+                q = 1;
+                x = Math.floor(Math.random() * 2 + 1);
+                if (x == 2)
+                    x = 4;
+            }
+        } else if (s - 1 > 0 && w[r][s - 1] == 0) {	// Can go up?
+            if (r < h && w[r + 1][s] == 0) {
+                if (s < v2) {
+                    if (w[r][s + 1] == 0)
+                        x = Math.floor(Math.random() * 3 + 2);
+                    else
+                        x = Math.floor(Math.random() * 2 + 2);
+                } else if (z == 1) {
+                    x = Math.floor(Math.random() * 2 + 2);
+                } else {
+                    q = 1;
+                    x = Math.floor(Math.random() * 3 + 2);
+                }
+            } else if (s < v2) {
+                if (w[r][s + 1] == 0) {
+                    x = Math.floor(Math.random() * 2 + 2);
+                    if (x == 3)
+                        x = 4;
+                } else {
+                    x = 2;
+                }
+            } else if (z == 1) {
+                x = 2;
+            } else {
+                q = 1;
+                x = Math.floor(Math.random() * 2 + 2);
+                if (x == 3)
+                    x = 4;
+            }
+        } else if (r < h && w[r + 1][s] == 0) {	// Can go right?
+            if (s < v2) {
+                if (w[r][s + 1] == 0)
+                    x = Math.floor(Math.random() * 2 + 3);
+                else
+                    x = 3;
+            } else if (z == 1) {
+                x = 3;
+            } else {
+                q = 1;
+                x = Math.floor(Math.random() * 2 + 3);
+            }
+        } else if (s < v2) {
+            if (w[r][s + 1] == 0) 	// Can go down?
+                x = 4;
+            else {
+                entry = 2;	// Blocked!
+                continue;
+            }
+        } else if (z == 1) {
+            entry = 2;	// Blocked!
+            continue;
+        } else {
+            q = 1;
+            x = 4;
+        }
+        if (x == 1) {	// Left
+            w[r - 1][s] = c;
+            c++;
+            v[r - 1][s] = 2;
+            r--;
+            if (c == h * v2 + 1)
+                break;
+            q = 0;
+            entry = 0;
+        } else if (x == 2) {	// Up
+            w[r][s - 1] = c;
+            c++;
+            v[r][s - 1] = 1;
+            s--;
+            if (c == h * v2 + 1)
+                break;
+            q = 0;
+            entry = 0;
+        } else if (x == 3) {	// Right
+            w[r + 1][s] = c;
+            c++;
+            if (v[r][s] == 0)
+                v[r][s] = 2;
+            else
+                v[r][s] = 3;
+            r++;
+            if (c == h * v2 + 1)
+                break;
+            entry = 1;
+        } else if (x == 4) {	// Down
+            if (q != 1) {	// Only if not blocked
+                w[r][s + 1] = c;
+                c++;
+                if (v[r][s] == 0)
+                    v[r][s] = 1;
+                else
+                    v[r][s] = 3;
+                s++;
+                if (c == h * v2 + 1)
+                    break;
+                entry = 0;
+            } else {
+                z = 1;
+                if (v[r][s] == 0) {
+                    v[r][s] = 1;
+                    q = 0;
+                    r = 1;
+                    s = 1;
+                    while (w[r][s] == 0) {
+                        if (r < h) {
+                            r++;
+                        } else if (s < v2) {
+                            r = 1;
+                            s++;
+                        } else {
+                            r = 1;
+                            s = 1;
+                        }
+                    }
+                    entry = 0;
+                } else {
+                    v[r][s] = 3;
+                    q = 0;
+                    entry = 2;
+                }
+            }
+        }
+    }
+    for (j = 1; j <= v2; j++) {
+        str = "I";
+        for (i = 1; i <= h; i++) {
+            if (v[i][j] < 2)
+                str += "  I";
+            else
+                str += "   ";
+        }
+        print(str + "\n");
+        str = "";
+        for (i = 1; i <= h; i++) {
+            if (v[i][j] == 0 || v[i][j] == 2)
+                str += ":--";
+            else
+                str += ":  ";
+        }
+        print(str + ".\n");
+    }
+// If you want to see the order of visited cells
+//    for (j = 1; j <= v2; j++) {
+//        str = "I";
+//        for (i = 1; i <= h; i++) {
+//            str += w[i][j] + " ";
+//        }
+//        print(str + "\n");
+//    }
+}
+
+main();