From e2cc55782b6036ee31be39edefd77b8e39ac9369 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Mon, 8 Jan 2018 19:08:36 +0100 Subject: project 9 checkpoint - the game works properly after dumbing down the random number generator. generator. --- projects/09/K/Board.jack | 20 +++++- projects/09/K/Board.vm | 159 +++++++++++++++++++++++------------------------ 2 files changed, 95 insertions(+), 84 deletions(-) diff --git a/projects/09/K/Board.jack b/projects/09/K/Board.jack index c465f95..cea3ae6 100644 --- a/projects/09/K/Board.jack +++ b/projects/09/K/Board.jack @@ -194,6 +194,13 @@ class Board { } method void addTile(){ + var Array t; + let t = grid[1]; + if (t[1] = 32) { + let t[1] = 65; + } + return; + /* var int x, y, r, c; var char z; var Array t; @@ -214,6 +221,7 @@ class Board { } let t[c] = z; return; + */ } method void transform(char dir){ @@ -241,9 +249,9 @@ class Board { } method void next(char dir){ - do addTile(); let nTurn = nTurn + 1; do transform(dir); + do addTile(); return; } @@ -252,15 +260,23 @@ class Board { var Array t; let r = 9; let c = 30; + + do Output.moveCursor(r - 1, c - 1); + do Output.printString("+----+"); + do Output.moveCursor(r + 4, c - 1); + do Output.printString("+----+"); + let i = 0; while (i < 4) { let j = 0; - do Output.moveCursor(r + i, c); + do Output.moveCursor(r + i, c - 1); + do Output.printString("|"); let t = grid[i]; while (j < 4) { do Output.printChar(t[j]); let j = j + 1; } + do Output.printString("|"); let i = i + 1; } return; diff --git a/projects/09/K/Board.vm b/projects/09/K/Board.vm index 398171f..ce1e791 100644 --- a/projects/09/K/Board.vm +++ b/projects/09/K/Board.vm @@ -894,101 +894,34 @@ return label IF_FALSE6 push argument 1 return -function Board.addTile 6 +function Board.addTile 1 push argument 0 pop pointer 0 -push this 1 -pop local 0 -push constant 23 -push local 0 -call Math.multiply 2 -push local 0 -call Math.multiply 2 -push constant 79 -add -pop local 1 -push local 1 -push local 1 -push constant 16 -call Math.divide 2 -push constant 16 -call Math.multiply 2 -sub -pop local 0 -push local 0 -push constant 4 -call Math.divide 2 -pop local 2 -push local 0 -push local 2 -push constant 4 -call Math.multiply 2 -sub -pop local 3 -push constant 65 -pop local 4 -push local 2 +push constant 1 push this 0 add pop pointer 1 push that 0 -pop local 5 -label WHILE_EXP0 -push local 3 -push local 5 -add -pop pointer 1 -push that 0 -push constant 64 -gt -not -if-goto WHILE_END0 -push constant 23 -push local 0 -call Math.multiply 2 -push local 0 -call Math.multiply 2 -push constant 79 -add -pop local 1 -push local 1 -push local 1 -push constant 16 -call Math.divide 2 -push constant 16 -call Math.multiply 2 -sub pop local 0 +push constant 1 push local 0 -push constant 4 -call Math.divide 2 -pop local 2 -push local 0 -push local 2 -push constant 4 -call Math.multiply 2 -sub -pop local 3 -push constant 131 -push local 4 -sub -pop local 4 -push local 2 -push this 0 add pop pointer 1 push that 0 -pop local 5 -goto WHILE_EXP0 -label WHILE_END0 -push local 3 -push local 5 +push constant 32 +eq +if-goto IF_TRUE0 +goto IF_FALSE0 +label IF_TRUE0 +push constant 1 +push local 0 add -push local 4 +push constant 65 pop temp 0 pop pointer 1 push temp 0 pop that 0 +label IF_FALSE0 push constant 0 return function Board.transform 4 @@ -1076,9 +1009,6 @@ return function Board.next 0 push argument 0 pop pointer 0 -push pointer 0 -call Board.addTile 1 -pop temp 0 push this 1 push constant 1 add @@ -1087,6 +1017,9 @@ push pointer 0 push argument 1 call Board.transform 2 pop temp 0 +push pointer 0 +call Board.addTile 1 +pop temp 0 push constant 0 return function Board.draw 5 @@ -1096,6 +1029,54 @@ push constant 9 pop local 0 push constant 30 pop local 1 +push local 0 +push constant 1 +sub +push local 1 +push constant 1 +sub +call Output.moveCursor 2 +pop temp 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 +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 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 +call Output.printString 1 +pop temp 0 push constant 0 pop local 2 label WHILE_EXP0 @@ -1110,8 +1091,16 @@ push local 0 push local 2 add push local 1 +push constant 1 +sub call Output.moveCursor 2 pop temp 0 +push constant 1 +call String.new 1 +push constant 124 +call String.appendChar 2 +call Output.printString 1 +pop temp 0 push local 2 push this 0 add @@ -1137,6 +1126,12 @@ add pop local 3 goto WHILE_EXP1 label WHILE_END1 +push constant 1 +call String.new 1 +push constant 124 +call String.appendChar 2 +call Output.printString 1 +pop temp 0 push local 2 push constant 1 add -- cgit v1.2.3