aboutsummaryrefslogtreecommitdiff
path: root/projects/09/K
diff options
context:
space:
mode:
authorYuchen Pei <me@ypei.me>2018-01-20 15:41:49 +0100
committerYuchen Pei <me@ypei.me>2018-01-20 15:41:49 +0100
commitd3a0cc3a8ba6dfeb64d3faeffdeb6845b60e5840 (patch)
treed58df9ec2480e2a9ec6240f9c797f83d1a0b1056 /projects/09/K
parent3571f998b28fbc8d9250ba04c983935f10a16c15 (diff)
rearranged the dir for github
- removed tools and pdfs - rearranged the projects dirs - added md files - other minor changes
Diffstat (limited to 'projects/09/K')
-rw-r--r--projects/09/K/Board.jack327
-rw-r--r--projects/09/K/Board.vm1465
-rw-r--r--projects/09/K/K.txt25
-rw-r--r--projects/09/K/KGame.jack57
-rw-r--r--projects/09/K/KGame.vm169
-rw-r--r--projects/09/K/Main.jack10
-rw-r--r--projects/09/K/Main.vm13
7 files changed, 0 insertions, 2066 deletions
diff --git a/projects/09/K/Board.jack b/projects/09/K/Board.jack
deleted file mode 100644
index 91a8d98..0000000
--- a/projects/09/K/Board.jack
+++ /dev/null
@@ -1,327 +0,0 @@
-class Board {
- field Array grid;
- field int nTurn, seed, status; // status: 0: begin game; 1: in game; 2: lose; 3: win;
- static String boardBar, strLost, strCont, strGameOver, strWon, strTurn;
-
- constructor Board new() {
- var int i;
- let grid = Array.new(4);
- let i = 0;
- while (i < 4) {
- let grid[i] = Array.new(4);
- let i = i + 1;
- }
- do initBoard();
- let seed = 0;
- return this;
- }
-
- function void init() {
- let boardBar = "+----+";
- let strLost = "You lost!";
- let strWon = "You won!";
- let strCont = "Press any key to continue";
- let strGameOver = "Game over!";
- let strTurn = "Turn: ";
- return;
- }
-
- method void initBoard() {
- var int i, j;
- var Array t;
- let i = 0;
- while (i < 4) {
- let j = 0;
- let t = grid[i];
- while (j < 4) {
- let t[j] = 32;
- let j = j + 1;
- }
- let i = i + 1;
- }
- let t = grid[0];
- let t[0] = 65;
- let nTurn = 0;
- let status = 0;
- return;
- }
-
-
- method void transpose() {
- do exch(0, 1);
- do exch(0, 2);
- do exch(0, 3);
- do exch(1, 2);
- do exch(1, 3);
- do exch(2, 3);
- return;
- }
-
- method void exch(int i, int j){
- var int t;
- var Array s1, s2;
- let s1 = grid[i];
- let s2 = grid[j];
- let t = s1[j];
- let s1[j] = s2[i];
- let s2[i] = t;
- return;
- }
-
- method void align(Array xs, boolean left){
- var int i, j;
- let i = 0;
- let j = 0;
- if (left) {
- while (i < 4) {
- if (xs[i] > 64) {
- let xs[j] = xs[i];
- let j = j + 1;
- }
- let i = i + 1;
- }
- while (j < 4) {
- let xs[j] = 32;
- let j = j + 1;
- }
- } else {
- while (i < 4) {
- if (xs[3 - i] > 64) {
- let xs[3 - j] = xs[3 - i];
- let j = j + 1;
- }
- let i = i + 1;
- }
- while (j < 4) {
- let xs[3 - j] = 32;
- let j = j + 1;
- }
- }
- return;
- }
-
- method void reduce(Array xs, boolean left){
- if ((xs[0] = xs[1]) & (xs[2] = xs[3]) & (xs[0] > 64) & (xs[2] > 64)) {
- if (left) {
- let xs[0] = xs[0] + 1;
- let xs[1] = xs[2] + 1;
- let xs[2] = 32;
- let xs[3] = 32;
- } else {
- let xs[3] = xs[3] + 1;
- let xs[2] = xs[1] + 1;
- let xs[1] = 32;
- let xs[0] = 32;
- }
- return;
- }
- if ((xs[0] = xs[1]) & (xs[0] > 64)) {
- if (left) {
- let xs[0] = xs[0] + 1;
- let xs[1] = xs[2];
- let xs[2] = xs[3];
- let xs[3] = 32;
- } else {
- let xs[1] = xs[1] + 1;
- let xs[0] = 32;
- }
- return;
- }
- if ((xs[2] = xs[3]) & (xs[2] > 64)) {
- if (left) {
- let xs[2] = xs[2] + 1;
- let xs[3] = 32;
- } else {
- let xs[3] = xs[3] + 1;
- let xs[2] = xs[1];
- let xs[1] = xs[0];
- let xs[0] = 32;
- }
- return;
- }
- if ((xs[1] = xs[2]) & (xs[1] > 64)) {
- if (left) {
- let xs[1] = xs[1] + 1;
- let xs[2] = xs[3];
- let xs[3] = 32;
- } else {
- let xs[2] = xs[2] + 1;
- let xs[1] = xs[0];
- let xs[0] = 32;
- }
- return;
- }
- return;
- }
-
- method void addTile(){
- var Array t;
- var int r, c, parity, newTile;
- /*
- let t = grid[1];
- if (t[1] = 32) {
- let t[1] = 65;
- }
- */
-
- if (~(status = 1)) {
- return;
- }
-
- let seed = seed * 25173 + 13849;
- if (seed < 0) {
- let seed = - seed;
- }
-
- if (seed - (seed / 2 * 2) = 0) {
- let parity = 1;
- } else {
- let parity = -1;
- }
-
- let seed = seed - (seed / 16 * 16);
- let r = seed / 4;
- let c = seed - (4 * r);
- let t = grid[r];
- let newTile = 65;
-
- while (t[c] > 64){
- let seed = seed + parity;
- if (seed < 0) {
- let seed = 15;
- }
- let seed = seed - (seed / 16 * 16);
- let r = seed / 4;
- let c = seed - (4 * r);
- let t = grid[r];
- let newTile = 131 - newTile;
- }
- let t[c] = newTile;
- return;
- }
-
- method void transform(char dir){
- var boolean isVertical, left;
- var int i;
- if ((dir = 0) | (dir = 1)) {
- let left = true;
- } else {
- let left = false;
- }
- if ((dir = 0) | (dir = 2)) {
- let isVertical = false;
- } else {
- let isVertical = true;
- }
- if (isVertical) {
- do transpose();
- }
- let i = 0;
- while (i < 4) {
- do align(grid[i], left);
- do reduce(grid[i], left);
- let i = i + 1;
- }
- if (isVertical) {
- do transpose();
- }
- return;
- }
-
- method void next(int dir){
- let nTurn = nTurn + 1;
- do transform(dir);
- do updateStatus();
- return;
- }
-
- method int getStatus(){
- return status;
- }
-
- method void setStatus(int x){
- let status = x;
- return;
- }
-
- method void updateStatus(){
- var int i, j;
- var Array r;
- let i = 0;
- while (i < 4) {
- let r = grid[i];
- let j = 0;
- while (j < 4) {
- if (r[j] = 75) {
- let status = 3;
- return;
- }
- if (r[j] = 32) {
- let status = 1;
- return;
- }
- let j = j + 1;
- }
- let i = i + 1;
- }
- let status = 2;
- return;
- }
-
- method void draw(){
- var int r, c, i, j;
- var Array t;
- let r = 9;
- let c = 30;
-
- if (status = 0) {
- do Output.moveCursor(r - 1, c - 1);
- do Output.printChar(75);
- do Output.moveCursor(r + 1, c - 1);
- do Output.printString(strCont);
- } else { if (status = 2) {
- do Output.moveCursor(r - 1, c - 1);
- do Output.printString(strGameOver);
- do Output.moveCursor(r + 1, c - 1);
- do Output.printString(strLost);
- do Output.moveCursor(r + 3, c - 1);
- do Output.printString(strCont);
- } else { if (status = 3) {
- do Output.moveCursor(r - 1, c - 1);
- do Output.printString(strGameOver);
- do Output.moveCursor(r + 1, c - 1);
- do Output.printString(strWon);
- do Output.moveCursor(r + 3, c - 1);
- do Output.printString(strCont);
- } else {
- do Output.moveCursor(r - 1, c - 1);
- do Output.printString(boardBar);
- do Output.moveCursor(r + 4, c - 1);
- do Output.printString(boardBar);
-
- let i = 0;
- while (i < 4) {
- let j = 0;
- do Output.moveCursor(r + i, c - 1);
- do Output.printChar(124); // 124 is |
- let t = grid[i];
- while (j < 4) {
- do Output.printChar(t[j]);
- let j = j + 1;
- }
- do Output.printChar(124);
- let i = i + 1;
- }
-
- do Output.moveCursor(r + 6, c - 2);
- do Output.printString(strTurn);
- do Output.printInt(nTurn);
- }}}
- return;
- }
-
- method void dispose() {
- do Memory.deAlloc(this);
- return;
- }
-}
diff --git a/projects/09/K/Board.vm b/projects/09/K/Board.vm
deleted file mode 100644
index 985e813..0000000
--- a/projects/09/K/Board.vm
+++ /dev/null
@@ -1,1465 +0,0 @@
-function Board.new 1
-push constant 4
-call Memory.alloc 1
-pop pointer 0
-push constant 4
-call Array.new 1
-pop this 0
-push constant 0
-pop local 0
-label WHILE_EXP0
-push local 0
-push constant 4
-lt
-not
-if-goto WHILE_END0
-push local 0
-push this 0
-add
-push constant 4
-call Array.new 1
-pop temp 0
-pop pointer 1
-push temp 0
-pop that 0
-push local 0
-push constant 1
-add
-pop local 0
-goto WHILE_EXP0
-label WHILE_END0
-push pointer 0
-call Board.initBoard 1
-pop temp 0
-push constant 0
-pop this 2
-push pointer 0
-return
-function Board.init 0
-push constant 6
-call String.new 1
-push constant 43
-call String.appendChar 2
-push constant 45
-call String.appendChar 2
-push constant 45
-call String.appendChar 2
-push constant 45
-call String.appendChar 2
-push constant 45
-call String.appendChar 2
-push constant 43
-call String.appendChar 2
-pop static 0
-push constant 9
-call String.new 1
-push constant 89
-call String.appendChar 2
-push constant 111
-call String.appendChar 2
-push constant 117
-call String.appendChar 2
-push constant 32
-call String.appendChar 2
-push constant 108
-call String.appendChar 2
-push constant 111
-call String.appendChar 2
-push constant 115
-call String.appendChar 2
-push constant 116
-call String.appendChar 2
-push constant 33
-call String.appendChar 2
-pop static 1
-push constant 8
-call String.new 1
-push constant 89
-call String.appendChar 2
-push constant 111
-call String.appendChar 2
-push constant 117
-call String.appendChar 2
-push constant 32
-call String.appendChar 2
-push constant 119
-call String.appendChar 2
-push constant 111
-call String.appendChar 2
-push constant 110
-call String.appendChar 2
-push constant 33
-call String.appendChar 2
-pop static 4
-push constant 25
-call String.new 1
-push constant 80
-call String.appendChar 2
-push constant 114
-call String.appendChar 2
-push constant 101
-call String.appendChar 2
-push constant 115
-call String.appendChar 2
-push constant 115
-call String.appendChar 2
-push constant 32
-call String.appendChar 2
-push constant 97
-call String.appendChar 2
-push constant 110
-call String.appendChar 2
-push constant 121
-call String.appendChar 2
-push constant 32
-call String.appendChar 2
-push constant 107
-call String.appendChar 2
-push constant 101
-call String.appendChar 2
-push constant 121
-call String.appendChar 2
-push constant 32
-call String.appendChar 2
-push constant 116
-call String.appendChar 2
-push constant 111
-call String.appendChar 2
-push constant 32
-call String.appendChar 2
-push constant 99
-call String.appendChar 2
-push constant 111
-call String.appendChar 2
-push constant 110
-call String.appendChar 2
-push constant 116
-call String.appendChar 2
-push constant 105
-call String.appendChar 2
-push constant 110
-call String.appendChar 2
-push constant 117
-call String.appendChar 2
-push constant 101
-call String.appendChar 2
-pop static 2
-push constant 10
-call String.new 1
-push constant 71
-call String.appendChar 2
-push constant 97
-call String.appendChar 2
-push constant 109
-call String.appendChar 2
-push constant 101
-call String.appendChar 2
-push constant 32
-call String.appendChar 2
-push constant 111
-call String.appendChar 2
-push constant 118
-call String.appendChar 2
-push constant 101
-call String.appendChar 2
-push constant 114
-call String.appendChar 2
-push constant 33
-call String.appendChar 2
-pop static 3
-push constant 6
-call String.new 1
-push constant 84
-call String.appendChar 2
-push constant 117
-call String.appendChar 2
-push constant 114
-call String.appendChar 2
-push constant 110
-call String.appendChar 2
-push constant 58
-call String.appendChar 2
-push constant 32
-call String.appendChar 2
-pop static 5
-push constant 0
-return
-function Board.initBoard 3
-push argument 0
-pop pointer 0
-push constant 0
-pop local 0
-label WHILE_EXP0
-push local 0
-push constant 4
-lt
-not
-if-goto WHILE_END0
-push constant 0
-pop local 1
-push local 0
-push this 0
-add
-pop pointer 1
-push that 0
-pop local 2
-label WHILE_EXP1
-push local 1
-push constant 4
-lt
-not
-if-goto WHILE_END1
-push local 1
-push local 2
-add
-push constant 32
-pop temp 0
-pop pointer 1
-push temp 0
-pop that 0
-push local 1
-push constant 1
-add
-pop local 1
-goto WHILE_EXP1
-label WHILE_END1
-push local 0
-push constant 1
-add
-pop local 0
-goto WHILE_EXP0
-label WHILE_END0
-push constant 0
-push this 0
-add
-pop pointer 1
-push that 0
-pop local 2
-push constant 0
-push local 2
-add
-push constant 65
-pop temp 0
-pop pointer 1
-push temp 0
-pop that 0
-push constant 0
-pop this 1
-push constant 0
-pop this 3
-push constant 0
-return
-function Board.transpose 0
-push argument 0
-pop pointer 0
-push pointer 0
-push constant 0
-push constant 1
-call Board.exch 3
-pop temp 0
-push pointer 0
-push constant 0
-push constant 2
-call Board.exch 3
-pop temp 0
-push pointer 0
-push constant 0
-push constant 3
-call Board.exch 3
-pop temp 0
-push pointer 0
-push constant 1
-push constant 2
-call Board.exch 3
-pop temp 0
-push pointer 0
-push constant 1
-push constant 3
-call Board.exch 3
-pop temp 0
-push pointer 0
-push constant 2
-push constant 3
-call Board.exch 3
-pop temp 0
-push constant 0
-return
-function Board.exch 3
-push argument 0
-pop pointer 0
-push argument 1
-push this 0
-add
-pop pointer 1
-push that 0
-pop local 1
-push argument 2
-push this 0
-add
-pop pointer 1
-push that 0
-pop local 2
-push argument 2
-push local 1
-add
-pop pointer 1
-push that 0
-pop local 0
-push argument 2
-push local 1
-add
-push argument 1
-push local 2
-add
-pop pointer 1
-push that 0
-pop temp 0
-pop pointer 1
-push temp 0
-pop that 0
-push argument 1
-push local 2
-add
-push local 0
-pop temp 0
-pop pointer 1
-push temp 0
-pop that 0
-push constant 0
-return
-function Board.align 2
-push argument 0
-pop pointer 0
-push constant 0
-pop local 0
-push constant 0
-pop local 1
-push argument 2
-if-goto IF_TRUE0
-goto IF_FALSE0
-label IF_TRUE0
-label WHILE_EXP0
-push local 0
-push constant 4
-lt
-not
-if-goto WHILE_END0
-push local 0
-push argument 1
-add
-pop pointer 1
-push that 0
-push constant 64
-gt
-if-goto IF_TRUE1
-goto IF_FALSE1
-label IF_TRUE1
-push local 1
-push argument 1
-add
-push local 0
-push argument 1
-add
-pop pointer 1
-push that 0
-pop temp 0
-pop pointer 1
-push temp 0
-pop that 0
-push local 1
-push constant 1
-add
-pop local 1
-label IF_FALSE1
-push local 0
-push constant 1
-add
-pop local 0
-goto WHILE_EXP0
-label WHILE_END0
-label WHILE_EXP1
-push local 1
-push constant 4
-lt
-not
-if-goto WHILE_END1
-push local 1
-push argument 1
-add
-push constant 32
-pop temp 0
-pop pointer 1
-push temp 0
-pop that 0
-push local 1
-push constant 1
-add
-pop local 1
-goto WHILE_EXP1
-label WHILE_END1
-goto IF_END0
-label IF_FALSE0
-label WHILE_EXP2
-push local 0
-push constant 4
-lt
-not
-if-goto WHILE_END2
-push constant 3
-push local 0
-sub
-push argument 1
-add
-pop pointer 1
-push that 0
-push constant 64
-gt
-if-goto IF_TRUE2
-goto IF_FALSE2
-label IF_TRUE2
-push constant 3
-push local 1
-sub
-push argument 1
-add
-push constant 3
-push local 0
-sub
-push argument 1
-add
-pop pointer 1
-push that 0
-pop temp 0
-pop pointer 1
-push temp 0
-pop that 0
-push local 1
-push constant 1
-add
-pop local 1
-label IF_FALSE2
-push local 0
-push constant 1
-add
-pop local 0
-goto WHILE_EXP2
-label WHILE_END2
-label WHILE_EXP3
-push local 1
-push constant 4
-lt
-not
-if-goto WHILE_END3
-push constant 3
-push local 1
-sub
-push argument 1
-add
-push constant 32
-pop temp 0
-pop pointer 1
-push temp 0
-pop that 0
-push local 1
-push constant 1
-add
-pop local 1
-goto WHILE_EXP3
-label WHILE_END3
-label IF_END0
-push constant 0
-return
-function Board.reduce 0
-push argument 0
-pop pointer 0
-push constant 0
-push argument 1
-add
-pop pointer 1
-push that 0
-push constant 1
-push argument 1
-add
-pop pointer 1
-push that 0
-eq
-push constant 2
-push argument 1
-add
-pop pointer 1
-push that 0
-push constant 3
-push argument 1
-add
-pop pointer 1
-push that 0
-eq
-and
-push constant 0
-push argument 1
-add
-pop pointer 1
-push that 0
-push constant 64
-gt
-and
-push constant 2
-push argument 1
-add
-pop pointer 1
-push that 0
-push constant 64
-gt
-and
-if-goto IF_TRUE0
-goto IF_FALSE0
-label IF_TRUE0
-push argument 2
-if-goto IF_TRUE1
-goto IF_FALSE1
-label IF_TRUE1
-push constant 0
-push argument 1
-add
-push constant 0
-push argument 1
-add
-pop pointer 1
-push that 0
-push constant 1
-add
-pop temp 0
-pop pointer 1
-push temp 0
-pop that 0
-push constant 1
-push argument 1
-add
-push constant 2
-push argument 1
-add
-pop pointer 1
-push that 0
-push constant 1
-add
-pop temp 0
-pop pointer 1
-push temp 0
-pop that 0
-push constant 2
-push argument 1
-add
-push constant 32
-pop temp 0
-pop pointer 1
-push temp 0
-pop that 0
-push constant 3
-push argument 1
-add
-push constant 32
-pop temp 0
-pop pointer 1
-push temp 0
-pop that 0
-goto IF_END1
-label IF_FALSE1
-push constant 3
-push argument 1
-add
-push constant 3
-push argument 1
-add
-pop pointer 1
-push that 0
-push constant 1
-add
-pop temp 0
-pop pointer 1
-push temp 0
-pop that 0
-push constant 2
-push argument 1
-add
-push constant 1
-push argument 1
-add
-pop pointer 1
-push that 0
-push constant 1
-add
-pop temp 0
-pop pointer 1
-push temp 0
-pop that 0
-push constant 1
-push argument 1
-add
-push constant 32
-pop temp 0
-pop pointer 1
-push temp 0
-pop that 0
-push constant 0
-push argument 1
-add
-push constant 32
-pop temp 0
-pop pointer 1
-push temp 0
-pop that 0
-label IF_END1
-push constant 0
-return
-label IF_FALSE0
-push constant 0
-push argument 1
-add
-pop pointer 1
-push that 0
-push constant 1
-push argument 1
-add
-pop pointer 1
-push that 0
-eq
-push constant 0
-push argument 1
-add
-pop pointer 1
-push that 0
-push constant 64
-gt
-and
-if-goto IF_TRUE2
-goto IF_FALSE2
-label IF_TRUE2
-push argument 2
-if-goto IF_TRUE3
-goto IF_FALSE3
-label IF_TRUE3
-push constant 0
-push argument 1
-add
-push constant 0
-push argument 1
-add
-pop pointer 1
-push that 0
-push constant 1
-add
-pop temp 0
-pop pointer 1
-push temp 0
-pop that 0
-push constant 1
-push argument 1
-add
-push constant 2
-push argument 1
-add
-pop pointer 1
-push that 0
-pop temp 0
-pop pointer 1
-push temp 0
-pop that 0
-push constant 2
-push argument 1
-add
-push constant 3
-push argument 1
-add
-pop pointer 1
-push that 0
-pop temp 0
-pop pointer 1
-push temp 0
-pop that 0
-push constant 3
-push argument 1
-add
-push constant 32
-pop temp 0
-pop pointer 1
-push temp 0
-pop that 0
-goto IF_END3
-label IF_FALSE3
-push constant 1
-push argument 1
-add
-push constant 1
-push argument 1
-add
-pop pointer 1
-push that 0
-push constant 1
-add
-pop temp 0
-pop pointer 1
-push temp 0
-pop that 0
-push constant 0
-push argument 1
-add
-push constant 32
-pop temp 0
-pop pointer 1
-push temp 0
-pop that 0
-label IF_END3
-push constant 0
-return
-label IF_FALSE2
-push constant 2
-push argument 1
-add
-pop pointer 1
-push that 0
-push constant 3
-push argument 1
-add
-pop pointer 1
-push that 0
-eq
-push constant 2
-push argument 1
-add
-pop pointer 1
-push that 0
-push constant 64
-gt
-and
-if-goto IF_TRUE4
-goto IF_FALSE4
-label IF_TRUE4
-push argument 2
-if-goto IF_TRUE5
-goto IF_FALSE5
-label IF_TRUE5
-push constant 2
-push argument 1
-add
-push constant 2
-push argument 1
-add
-pop pointer 1
-push that 0
-push constant 1
-add
-pop temp 0
-pop pointer 1
-push temp 0
-pop that 0
-push constant 3
-push argument 1
-add
-push constant 32
-pop temp 0
-pop pointer 1
-push temp 0
-pop that 0
-goto IF_END5
-label IF_FALSE5
-push constant 3
-push argument 1
-add
-push constant 3
-push argument 1
-add
-pop pointer 1
-push that 0
-push constant 1
-add
-pop temp 0
-pop pointer 1
-push temp 0
-pop that 0
-push constant 2
-push argument 1
-add
-push constant 1
-push argument 1
-add
-pop pointer 1
-push that 0
-pop temp 0
-pop pointer 1
-push temp 0
-pop that 0
-push constant 1
-push argument 1
-add
-push constant 0
-push argument 1
-add
-pop pointer 1
-push that 0
-pop temp 0
-pop pointer 1
-push temp 0
-pop that 0
-push constant 0
-push argument 1
-add
-push constant 32
-pop temp 0
-pop pointer 1
-push temp 0
-pop that 0
-label IF_END5
-push constant 0
-return
-label IF_FALSE4
-push constant 1
-push argument 1
-add
-pop pointer 1
-push that 0
-push constant 2
-push argument 1
-add
-pop pointer 1
-push that 0
-eq
-push constant 1
-push argument 1
-add
-pop pointer 1
-push that 0
-push constant 64
-gt
-and
-if-goto IF_TRUE6
-goto IF_FALSE6
-label IF_TRUE6
-push argument 2
-if-goto IF_TRUE7
-goto IF_FALSE7
-label IF_TRUE7
-push constant 1
-push argument 1
-add
-push constant 1
-push argument 1
-add
-pop pointer 1
-push that 0
-push constant 1
-add
-pop temp 0
-pop pointer 1
-push temp 0
-pop that 0
-push constant 2
-push argument 1
-add
-push constant 3
-push argument 1
-add
-pop pointer 1
-push that 0
-pop temp 0
-pop pointer 1
-push temp 0
-pop that 0
-push constant 3
-push argument 1
-add
-push constant 32
-pop temp 0
-pop pointer 1
-push temp 0
-pop that 0
-goto IF_END7
-label IF_FALSE7
-push constant 2
-push argument 1
-add
-push constant 2
-push argument 1
-add
-pop pointer 1
-push that 0
-push constant 1
-add
-pop temp 0
-pop pointer 1
-push temp 0
-pop that 0
-push constant 1
-push argument 1
-add
-push constant 0
-push argument 1
-add
-pop pointer 1
-push that 0
-pop temp 0
-pop pointer 1
-push temp 0
-pop that 0
-push constant 0
-push argument 1
-add
-push constant 32
-pop temp 0
-pop pointer 1
-push temp 0
-pop that 0
-label IF_END7
-push constant 0
-return
-label IF_FALSE6
-push constant 0
-return
-function Board.addTile 5
-push argument 0
-pop pointer 0
-push this 3
-push constant 1
-eq
-not
-if-goto IF_TRUE0
-goto IF_FALSE0
-label IF_TRUE0
-push constant 0
-return
-label IF_FALSE0
-push this 2
-push constant 25173
-call Math.multiply 2
-push constant 13849
-add
-pop this 2
-push this 2
-push constant 0
-lt
-if-goto IF_TRUE1
-goto IF_FALSE1
-label IF_TRUE1
-push this 2
-neg
-pop this 2
-label IF_FALSE1
-push this 2
-push this 2
-push constant 2
-call Math.divide 2
-push constant 2
-call Math.multiply 2
-sub
-push constant 0
-eq
-if-goto IF_TRUE2
-goto IF_FALSE2
-label IF_TRUE2
-push constant 1
-pop local 3
-goto IF_END2
-label IF_FALSE2
-push constant 1
-neg
-pop local 3
-label IF_END2
-push this 2
-push this 2
-push constant 16
-call Math.divide 2
-push constant 16
-call Math.multiply 2
-sub
-pop this 2
-push this 2
-push constant 4
-call Math.divide 2
-pop local 1
-push this 2
-push constant 4
-push local 1
-call Math.multiply 2
-sub
-pop local 2
-push local 1
-push this 0
-add
-pop pointer 1
-push that 0
-pop local 0
-push constant 65
-pop local 4
-label WHILE_EXP0
-push local 2
-push local 0
-add
-pop pointer 1
-push that 0
-push constant 64
-gt
-not
-if-goto WHILE_END0
-push this 2
-push local 3
-add
-pop this 2
-push this 2
-push constant 0
-lt
-if-goto IF_TRUE3
-goto IF_FALSE3
-label IF_TRUE3
-push constant 15
-pop this 2
-label IF_FALSE3
-push this 2
-push this 2
-push constant 16
-call Math.divide 2
-push constant 16
-call Math.multiply 2
-sub
-pop this 2
-push this 2
-push constant 4
-call Math.divide 2
-pop local 1
-push this 2
-push constant 4
-push local 1
-call Math.multiply 2
-sub
-pop local 2
-push local 1
-push this 0
-add
-pop pointer 1
-push that 0
-pop local 0
-push constant 131
-push local 4
-sub
-pop local 4
-goto WHILE_EXP0
-label WHILE_END0
-push local 2
-push local 0
-add
-push local 4
-pop temp 0
-pop pointer 1
-push temp 0
-pop that 0
-push constant 0
-return
-function Board.transform 3
-push argument 0
-pop pointer 0
-push argument 1
-push constant 0
-eq
-push argument 1
-push constant 1
-eq
-or
-if-goto IF_TRUE0
-goto IF_FALSE0
-label IF_TRUE0
-push constant 0
-not
-pop local 1
-goto IF_END0
-label IF_FALSE0
-push constant 0
-pop local 1
-label IF_END0
-push argument 1
-push constant 0
-eq
-push argument 1
-push constant 2
-eq
-or
-if-goto IF_TRUE1
-goto IF_FALSE1
-label IF_TRUE1
-push constant 0
-pop local 0
-goto IF_END1
-label IF_FALSE1
-push constant 0
-not
-pop local 0
-label IF_END1
-push local 0
-if-goto IF_TRUE2
-goto IF_FALSE2
-label IF_TRUE2
-push pointer 0
-call Board.transpose 1
-pop temp 0
-label IF_FALSE2
-push constant 0
-pop local 2
-label WHILE_EXP0
-push local 2
-push constant 4
-lt
-not
-if-goto WHILE_END0
-push pointer 0
-push local 2
-push this 0
-add
-pop pointer 1
-push that 0
-push local 1
-call Board.align 3
-pop temp 0
-push pointer 0
-push local 2
-push this 0
-add
-pop pointer 1
-push that 0
-push local 1
-call Board.reduce 3
-pop temp 0
-push local 2
-push constant 1
-add
-pop local 2
-goto WHILE_EXP0
-label WHILE_END0
-push local 0
-if-goto IF_TRUE3
-goto IF_FALSE3
-label IF_TRUE3
-push pointer 0
-call Board.transpose 1
-pop temp 0
-label IF_FALSE3
-push constant 0
-return
-function Board.next 0
-push argument 0
-pop pointer 0
-push this 1
-push constant 1
-add
-pop this 1
-push pointer 0
-push argument 1
-call Board.transform 2
-pop temp 0
-push pointer 0
-call Board.updateStatus 1
-pop temp 0
-push constant 0
-return
-function Board.getStatus 0
-push argument 0
-pop pointer 0
-push this 3
-return
-function Board.setStatus 0
-push argument 0
-pop pointer 0
-push argument 1
-pop this 3
-push constant 0
-return
-function Board.updateStatus 3
-push argument 0
-pop pointer 0
-push constant 0
-pop local 0
-label WHILE_EXP0
-push local 0
-push constant 4
-lt
-not
-if-goto WHILE_END0
-push local 0
-push this 0
-add
-pop pointer 1
-push that 0
-pop local 2
-push constant 0
-pop local 1
-label WHILE_EXP1
-push local 1
-push constant 4
-lt
-not
-if-goto WHILE_END1
-push local 1
-push local 2
-add
-pop pointer 1
-push that 0
-push constant 75
-eq
-if-goto IF_TRUE0
-goto IF_FALSE0
-label IF_TRUE0
-push constant 3
-pop this 3
-push constant 0
-return
-label IF_FALSE0
-push local 1
-push local 2
-add
-pop pointer 1
-push that 0
-push constant 32
-eq
-if-goto IF_TRUE1
-goto IF_FALSE1
-label IF_TRUE1
-push constant 1
-pop this 3
-push constant 0
-return
-label IF_FALSE1
-push local 1
-push constant 1
-add
-pop local 1
-goto WHILE_EXP1
-label WHILE_END1
-push local 0
-push constant 1
-add
-pop local 0
-goto WHILE_EXP0
-label WHILE_END0
-push constant 2
-pop this 3
-push constant 0
-return
-function Board.draw 5
-push argument 0
-pop pointer 0
-push constant 9
-pop local 0
-push constant 30
-pop local 1
-push this 3
-push constant 0
-eq
-if-goto IF_TRUE0
-goto IF_FALSE0
-label IF_TRUE0
-push local 0
-push constant 1
-sub
-push local 1
-push constant 1
-sub
-call Output.moveCursor 2
-pop temp 0
-push constant 75
-call Output.printChar 1
-pop temp 0
-push local 0
-push constant 1
-add
-push local 1
-push constant 1
-sub
-call Output.moveCursor 2
-pop temp 0
-push static 2
-call Output.printString 1
-pop temp 0
-goto IF_END0
-label IF_FALSE0
-push this 3
-push constant 2
-eq
-if-goto IF_TRUE1
-goto IF_FALSE1
-label IF_TRUE1
-push local 0
-push constant 1
-sub
-push local 1
-push constant 1
-sub
-call Output.moveCursor 2
-pop temp 0
-push static 3
-call Output.printString 1
-pop temp 0
-push local 0
-push constant 1
-add
-push local 1
-push constant 1
-sub
-call Output.moveCursor 2
-pop temp 0
-push static 1
-call Output.printString 1
-pop temp 0
-push local 0
-push constant 3
-add
-push local 1
-push constant 1
-sub
-call Output.moveCursor 2
-pop temp 0
-push static 2
-call Output.printString 1
-pop temp 0
-goto IF_END1
-label IF_FALSE1
-push this 3
-push constant 3
-eq
-if-goto IF_TRUE2
-goto IF_FALSE2
-label IF_TRUE2
-push local 0
-push constant 1
-sub
-push local 1
-push constant 1
-sub
-call Output.moveCursor 2
-pop temp 0
-push static 3
-call Output.printString 1
-pop temp 0
-push local 0
-push constant 1
-add
-push local 1
-push constant 1
-sub
-call Output.moveCursor 2
-pop temp 0
-push static 4
-call Output.printString 1
-pop temp 0
-push local 0
-push constant 3
-add
-push local 1
-push constant 1
-sub
-call Output.moveCursor 2
-pop temp 0
-push static 2
-call Output.printString 1
-pop temp 0
-goto IF_END2
-label IF_FALSE2
-push local 0
-push constant 1
-sub
-push local 1
-push constant 1
-sub
-call Output.moveCursor 2
-pop temp 0
-push static 0
-call Output.printString 1
-pop temp 0
-push local 0
-push constant 4
-add
-push local 1
-push constant 1
-sub
-call Output.moveCursor 2
-pop temp 0
-push static 0
-call Output.printString 1
-pop temp 0
-push constant 0
-pop local 2
-label WHILE_EXP0
-push local 2
-push constant 4
-lt
-not
-if-goto WHILE_END0
-push constant 0
-pop local 3
-push local 0
-push local 2
-add
-push local 1
-push constant 1
-sub
-call Output.moveCursor 2
-pop temp 0
-push constant 124
-call Output.printChar 1
-pop temp 0
-push local 2
-push this 0
-add
-pop pointer 1
-push that 0
-pop local 4
-label WHILE_EXP1
-push local 3
-push constant 4
-lt
-not
-if-goto WHILE_END1
-push local 3
-push local 4
-add
-pop pointer 1
-push that 0
-call Output.printChar 1
-pop temp 0
-push local 3
-push constant 1
-add
-pop local 3
-goto WHILE_EXP1
-label WHILE_END1
-push constant 124
-call Output.printChar 1
-pop temp 0
-push local 2
-push constant 1
-add
-pop local 2
-goto WHILE_EXP0
-label WHILE_END0
-push local 0
-push constant 6
-add
-push local 1
-push constant 2
-sub
-call Output.moveCursor 2
-pop temp 0
-push static 5
-call Output.printString 1
-pop temp 0
-push this 1
-call Output.printInt 1
-pop temp 0
-label IF_END2
-label IF_END1
-label IF_END0
-push constant 0
-return
-function Board.dispose 0
-push argument 0
-pop pointer 0
-push pointer 0
-call Memory.deAlloc 1
-pop temp 0
-push constant 0
-return
diff --git a/projects/09/K/K.txt b/projects/09/K/K.txt
deleted file mode 100644
index dc75c82..0000000
--- a/projects/09/K/K.txt
+++ /dev/null
@@ -1,25 +0,0 @@
-from a to k
-
-- a title frame showing game name and instructions. space to continue.
-- a main frame showing the game running
-- a endofgame frame showing game results: win or lose
-
-- a Board class with cell being a 4 by 4 two-d array.
-- arrange strings according to an orientation: arrange(4 strings, dir)=cells
- - dir: 0: align to left, 1: align to right, 2: align to top, 3:align to bottom
- - e.g.: arrange({"abc", "bc", "dc", "efeh", 0}) gives the following board:
- abc_
- bc__
- dc__
- efeh
- - arrange({"abc", "bc", "dc", "efeh", 0}, 3) gives the following
- ___e
- a__f
- bbde
- ccch
-- a new tile of 'a' or 'b' appears each turn somewhere, using some quasirandomisation e.g. (23 * n^2 + 79) mod 16.
- - addtile(char, x, y)
-- the board transformation: board.trans(dir) = arrange(dir) . (fmap reduce) . getstring(dir). calls getstrings, then reduce on each row / column
-- board.getstrings(dir)= the strings according to direction dir. Inverse of arrange.
-- reduce(string)=string: reduce("baac")=="bbc"; reduce("aabb")=="bc"; and reduce("cbb")== "cc" instead of "d".
-- when one of the hjkl keys is pressed get the direction dir.
diff --git a/projects/09/K/KGame.jack b/projects/09/K/KGame.jack
deleted file mode 100644
index 017b4e8..0000000
--- a/projects/09/K/KGame.jack
+++ /dev/null
@@ -1,57 +0,0 @@
-class KGame{
- field Board board;
-
- constructor KGame new() {
- let board = Board.new();
- do board.draw();
- return this;
- }
-
- method void dispose() {
- do board.dispose();
- do Memory.deAlloc(this);
- return;
- }
-
- method void run() {
- var int key, key1, st;
- var boolean exit;
- let exit = false;
- while (~exit) {
- let st = board.getStatus();
- let key = 0;
- while (key = 0) {
- let key = Keyboard.keyPressed();
- }
- let key1 = key;
- while (~(key1 = 0)) {
- let key1 = Keyboard.keyPressed();
- }
- if (key = 81) {
- let exit = true;
- } else { if ((st = 0)) {
- do Screen.clearScreen();
- do board.setStatus(1);
- do board.draw();
- } else { if ((st = 2) | (st = 3)) {
- do Screen.clearScreen();
- do board.setStatus(0);
- do board.draw();
- do board.initBoard();
- } else { if (key = 82) { // r for restart
- do Screen.clearScreen();
- do board.initBoard();
- do board.draw();
- } else { if ((key > 129) & (key < 134)) {
- do Screen.clearScreen();
- do board.next(key - 130);
- do board.draw();
- do Sys.wait(300);
- do Screen.clearScreen();
- do board.addTile();
- do board.draw();
- }}}}}
- }
- return;
- }
-}
diff --git a/projects/09/K/KGame.vm b/projects/09/K/KGame.vm
deleted file mode 100644
index df3a069..0000000
--- a/projects/09/K/KGame.vm
+++ /dev/null
@@ -1,169 +0,0 @@
-function KGame.new 0
-push constant 1
-call Memory.alloc 1
-pop pointer 0
-call Board.new 0
-pop this 0
-push this 0
-call Board.draw 1
-pop temp 0
-push pointer 0
-return
-function KGame.dispose 0
-push argument 0
-pop pointer 0
-push this 0
-call Board.dispose 1
-pop temp 0
-push pointer 0
-call Memory.deAlloc 1
-pop temp 0
-push constant 0
-return
-function KGame.run 4
-push argument 0
-pop pointer 0
-push constant 0
-pop local 3
-label WHILE_EXP0
-push local 3
-not
-not
-if-goto WHILE_END0
-push this 0
-call Board.getStatus 1
-pop local 2
-push constant 0
-pop local 0
-label WHILE_EXP1
-push local 0
-push constant 0
-eq
-not
-if-goto WHILE_END1
-call Keyboard.keyPressed 0
-pop local 0
-goto WHILE_EXP1
-label WHILE_END1
-push local 0
-pop local 1
-label WHILE_EXP2
-push local 1
-push constant 0
-eq
-not
-not
-if-goto WHILE_END2
-call Keyboard.keyPressed 0
-pop local 1
-goto WHILE_EXP2
-label WHILE_END2
-push local 0
-push constant 81
-eq
-if-goto IF_TRUE0
-goto IF_FALSE0
-label IF_TRUE0
-push constant 0
-not
-pop local 3
-goto IF_END0
-label IF_FALSE0
-push local 2
-push constant 0
-eq
-if-goto IF_TRUE1
-goto IF_FALSE1
-label IF_TRUE1
-call Screen.clearScreen 0
-pop temp 0
-push this 0
-push constant 1
-call Board.setStatus 2
-pop temp 0
-push this 0
-call Board.draw 1
-pop temp 0
-goto IF_END1
-label IF_FALSE1
-push local 2
-push constant 2
-eq
-push local 2
-push constant 3
-eq
-or
-if-goto IF_TRUE2
-goto IF_FALSE2
-label IF_TRUE2
-call Screen.clearScreen 0
-pop temp 0
-push this 0
-push constant 0
-call Board.setStatus 2
-pop temp 0
-push this 0
-call Board.draw 1
-pop temp 0
-push this 0
-call Board.initBoard 1
-pop temp 0
-goto IF_END2
-label IF_FALSE2
-push local 0
-push constant 82
-eq
-if-goto IF_TRUE3
-goto IF_FALSE3
-label IF_TRUE3
-call Screen.clearScreen 0
-pop temp 0
-push this 0
-call Board.initBoard 1
-pop temp 0
-push this 0
-call Board.draw 1
-pop temp 0
-goto IF_END3
-label IF_FALSE3
-push local 0
-push constant 129
-gt
-push local 0
-push constant 134
-lt
-and
-if-goto IF_TRUE4
-goto IF_FALSE4
-label IF_TRUE4
-call Screen.clearScreen 0
-pop temp 0
-push this 0
-push local 0
-push constant 130
-sub
-call Board.next 2
-pop temp 0
-push this 0
-call Board.draw 1
-pop temp 0
-push constant 300
-call Sys.wait 1
-pop temp 0
-call Screen.clearScreen 0
-pop temp 0
-push this 0
-call Board.addTile 1
-pop temp 0
-push this 0
-call Board.draw 1
-pop temp 0
-label IF_FALSE4
-label IF_END3
-label IF_END2
-label IF_END1
-label IF_END0
-goto WHILE_EXP0
-label WHILE_END0
-push constant 0
-return
diff --git a/projects/09/K/Main.jack b/projects/09/K/Main.jack
deleted file mode 100644
index 7f86973..0000000
--- a/projects/09/K/Main.jack
+++ /dev/null
@@ -1,10 +0,0 @@
-class Main {
- function void main() {
- var KGame game;
- do Board.init();
- let game = KGame.new();
- do game.run();
- do game.dispose();
- return;
- }
-}
diff --git a/projects/09/K/Main.vm b/projects/09/K/Main.vm
deleted file mode 100644
index 0441c7a..0000000
--- a/projects/09/K/Main.vm
+++ /dev/null
@@ -1,13 +0,0 @@
-function Main.main 1
-call Board.init 0
-pop temp 0
-call KGame.new 0
-pop local 0
-push local 0
-call KGame.run 1
-pop temp 0
-push local 0
-call KGame.dispose 1
-pop temp 0
-push constant 0
-return