Please could someone assist me with the following issue: I was trying to test some vm files for a jack Tic-Tac-Toe application, but i got the following VM emulator error "A built-in function tried to access memory outside the Heap or Screen range" , the error can be seen in the VM emulator screenshot in the link below:
https://www.dropbox.com/s/etde3zjk6jd4f8j/Screenshot%202020-01-28%2000.14.54.png?dl=0
Also, the error occurs when the emulator tries to print an Array element, from the board Array in the drawBoard() method, in my TicTacToeBoard class. What is surprising is that the array, I am trying to print or use is not too big or complex, as it just has 9 elements. Below are the Jack files for my application .(The first class, in the display is the TicTacToeBoard class, while the second, situated at the end is the Main Class.) Please any help would be seriously appreciated, as i have already spent hours on this.Thanks.
/** creates a Tic-Tac-Toe board */
class TicTacToeBoard{
field Array board; //an Array to be used for board construction
/** constructs a TicTacToe board */
constructor TicTacToeBoard new(){
var int i;
let board= Array.new(9);
let i = 0;
while(i < 9){
let board[i] = " ";
return this;
}
}
/** method draws the empty TicTacToe Board */
method void drawBoard(){
//do Output.printString("*** Start of drawBoard method");
//do Output.println(); /* DEBUG */
do Output.printString(board[6]);
do Output.printString("|");
do Output.printString(board[7]);
do Output.printString("|");
do Output.printString(board[8]);
//do Output.printString(getBoard[7] + "|" + getBoard[8] + "|" + getBoard[9]);
do Output.println();
do Output.printString("-+-+-");
do Output.println();
do Output.printString(board[3]);
do Output.printString("|");
do Output.printString(board[4]);
do Output.printString("|");
do Output.printString(board[5]);
//do Output.printString(getBoard[4] + "|" + getBoard[5] + "|" + getBoard[6]);
do Output.println();
do Output.printString("-+-+-");
do Output.println();
do Output.printString(board[0]);
do Output.printString("|");
do Output.printString(board[1]);
do Output.printString("|");
do Output.printString(board[2]);
//do Output.printString(getBoard[1] + "|" + getBoard[2] + "|" + getBoard[3]);
return;
}
/** method returns a copy of the board */
method Array getBoardCopy(){
var Array boardCopy;
var int i;
let i= 0;
let boardCopy= Array.new(9);
while(i< 9){
let boardCopy[i]= board[i];
}
return boardCopy;
}
}
/**Tests the Tic-Tac-ToeBoard class */
class Main{
function void main(){
var TicTacToeBoard tTTBoard;
let tTTBoard= TicTacToeBoard.new();
do tTTBoard.drawBoard();
return;
}
}