×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    4

    Unhappy What is the cause to which my WRT widget crashes in Nokia5800?

    Hi all.

    I am making reversi widget.

    My widget crashes when executing in Nokia5800 it for about 30 seconds.
    It don't crash in aptana emulator.

    What is the cause?

    Thank You

    The code is as follows.
    Code:
    /*
     * JavaScript file
     */
    
    var STONE_NONE  = 0;
    var STONE_WHITE = -1;
    var STONE_BLACK = 1;
    
    var TABLE_LEFT = 5;
    var TABLE_TOP  = 5;
    var STONE_SIZE = 44;
    
    var REV_TBL_W = 8;
    var REV_TBL_H = 8;
    
    var table;
    
    function Stone(tx, ty, x, y)
    {
    	this.x = x;
    	this.y = y;
    	
    	this.stone = STONE_NONE;
    	
    	this.bstoneImg = createImage('res/stone/black01.png', x, y, 44, 44);
    	this.wstoneImg = createImage('res/stone/white01.png', x, y, 44, 44);
    	
    	this.init = function() {
    		this.set(STONE_NONE);
    	}
    
    	this.set = function(s) {
    		this.stone = s;
    		
    		if (s == STONE_WHITE){
    			this.bstoneImg.style.visibility = 'hidden';
    			this.wstoneImg.style.visibility = 'visible';
    		} else if (s == STONE_BLACK){
    			this.bstoneImg.style.visibility = 'visible';
    			this.wstoneImg.style.visibility = 'hidden';
    		} else {
    			this.bstoneImg.style.visibility = 'hidden';
    			this.wstoneImg.style.visibility = 'hidden';
    		}
    	}
    
    	this.get = function() {
    		return this.stone;
    	}
    }
    
    function ReversiTable()
    {
    	this.tableImg = createImage('res/board.png', 0, 0, 360, 360);
    	
    	var i, j;
    	var ix = TABLE_LEFT,iy = TABLE_TOP;
    	this.table = new Array(REV_TBL_H);
    	this.chktable = new Array(REV_TBL_H);
    
    	for (i = 0; i < REV_TBL_H; i++){
    		this.table[i] = new Array(REV_TBL_W);
    		this.chktable[i] = new Array(REV_TBL_W);
    		
    		iy = TABLE_TOP;
    		for (j = 0; j < REV_TBL_W; j++){
    			this.chktable[i][j] = false;
    			this.table[i][j] = new Stone(i, j, ix, iy);
    			this.table[i][j].init();
    			
    			iy += STONE_SIZE;
    		}
    		ix += STONE_SIZE;
    	}
    	
    	this.curStone = 1;
    	this.turnCount = 0;
    	this.pre_x;
    	this.pre_y;
    	
    	this.vector = [ 
    		[ 0, -1 ],
    		[ 0,  1 ],
    		[-1,  0 ],
    		[ 1,  0 ],
    		[-1, -1 ],
    		[ 1,  1 ],
    		[ 1, -1 ],
    		[-1,  1 ]
     	];
     
    	this.getStone = function(x, y){
    		return this.table[x][y].get();
    	}
    	
    	this.setStone = function(stone , x, y){
    		this.table[x][y].set(stone);
    	}
    
    	this.putStone = function(stone, x, y) {
    		if (x < 0 || x >= REV_TBL_W) return;
    		if (y < 0 || y >= REV_TBL_H) return;
    		
    		var i, j;
    		
    		for(i=0;i<8;i++){
    			this.reverse(stone, x, y, this.vector[i][0], this.vector[i][1]);
    		}
    		this.setStone(stone, x, y);
    		
    		this.pre_x = x;
    		this.pre_y = y;
    	}
    
    	this.reverse = function(stone, x, y, dx, dy){
    		var etype;
    		var tx,ty;
    		var ret = false;
    		
    		etype = -stone;
    		
    		tx = x;
    		ty = y;
    		
    		tx += dx;
    		ty += dy;
    		while (tx >= 0 && ty >= 0 && tx < 8 && ty < 8){
    			
    			if (this.table[tx][ty].get() == etype) {
    				tx += dx;
    				ty += dy;
    			}
    			else if (this.table[tx][ty].get() == stone) {
    				ret = true;
    				break;
    			}
    			else {
    				ret = false;
    				break;
    			}
    		}
    		
    		if(ret){
    			tx = x;
    			ty = y;
    		
    			tx += dx;
    			ty += dy;
    			
    			
    			while (tx >= 0 && ty >= 0 && tx < 8 && ty < 8){
    				if (this.table[tx][ty].get() == etype) {
    					this.setStone(stone, tx, ty);
    					tx += dx;
    					ty += dy;
    				}
    				else if (this.table[tx][ty].get() == stone) {
    					break;
    				}
    				else {
    					break;
    				}
    			}	
    		}
    	}
    
    	this.canPutStone = function(stone , x, y){
    		if (x < 0 || x >= REV_TBL_W) return false;
    		if (y < 0 || y >= REV_TBL_H) return false;
    		
    		var i, j;
    		for(i=0;i<8;i++){
    			if(this.canPutStoneDirection(stone , x, y, this.vector[i][0], this.vector[i][1])){
    				return true;
    			}
    		}
    		return false;
    	}
    	
    	this.canPutStoneDirection = function(stone , x, y, dx, dy){
    		var etype;
    		var ret = false;
    		
    		etype = -stone;
    		
    		x += dx;
    		y += dy;
    		
    		while (x >= 0 && y >= 0 && x < 8 && y < 8){
    			if (this.table[x][y].get() == etype) {
    				x += dx;
    				y += dy;
    				
    				ret = true;
    			}
    			else if (this.table[x][y].get() == stone) {
    				return ret;
    			}
    			else {
    				return false;
    			}
    		}
    		return false;
    	}
    
    	this.init = function() {
    		var i, j;
    		for (i = 0; i < 8; i++) {
    			for (j = 0; j < 8; j++){
    				this.table[i][j].init();
    				this.chktable[i][j] = false;
    			}
    		}
    		this.table[3][3].set(STONE_WHITE);
    		this.table[4][3].set(STONE_BLACK);
    		this.table[3][4].set(STONE_BLACK);
    		this.table[4][4].set(STONE_WHITE);
    
    		this.curStone = 1;
    		this.turnCount = 0;
    	}
    	
    	this.nextTurn = function(){
    		this.curStone = -this.curStone;
    		this.turnCount++;
    	}
    
    	this.getCurStone = function(){
    		return this.curStone;
    	}
    	
    	this.getChkTable = function(x, y) {
    		return this.chktable[x][y];
    	}
    	
    	this.setCheckTable = function(type) {
    		var bw_count = new Array(2);
    		var count = 0;
    		
    		var i, j, k;
    		for (i = 0; i < 8; i++) {
    			for (j = 0; j < 8; j++) {
    				this.chktable[i][j] = false;
    				if (this.table[i][j].get() == STONE_NONE) {
    					if (this.canPutStone(type, i, j)){
    						this.chktable[i][j] = true;
    						count++;
    					}
    				} else 
    				if (this.table[i][j].get() == STONE_BLACK) {
    					bw_count[0]++;
    				} else 
    				if (this.table[i][j].get() == STONE_WHITE) {
    					bw_count[1]++;
    				}
    			}
    		}
    		return count;
    	}
    }
    
    function cpu_think(){
    	var i,j;
    	var curStone = table.getCurStone();
    	var count = table.setCheckTable(curStone);
    	var x, y;
    	var px,py;
    	
    	if (count > 0) {
    		for (i = 0; i < 8; i++) {
    			for (j = 0; j < 8; j++) {
    				if (table.getChkTable(i, j)) {
    					px = i;
    					py = j;
    					break;
    				}
    			}
    		}
    	
    		table.putStone(curStone, px, py);
    	}
    	else {
    		count = table.setCheckTable(-curStone);
    		if(count == 0){
    			table.init();
    			
    			setTimeout(cpu_think, 100);
    			return;
    		}
    	}
    	table.nextTurn();
    	setTimeout(cpu_think, 100);
    }
    
    
    function init()
    {
    	//	Add your code stpes here
    	table = new ReversiTable();
    	table.init();
    
    	setTimeout(cpu_think, 100);
    }
    
    
    function createImage(imgpath, x, y, w, h)
    {
    	var img;
    	
    	img = document.createElement('img');
    	img.id = 'cardImg';
    	img.style.left = x + 'px';
    	img.style.top  = y + 'px';
    	img.style.position = 'absolute';
    	img.width  = w;
    	img.height = h;
    	img.src = imgpath;
    	
    	document.body.appendChild(img);
    	return img;
    }

  2. #2
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: What is the cause to which my WRT widget crashes in Nokia5800?

    Hi akira0015,

    can you post a link to the widget you're testing, so that it'll be possible to directly test it and give you better support?

    Pit

  3. #3
    Registered User
    Join Date
    Apr 2009
    Posts
    4

    Re: What is the cause to which my WRT widget crashes in Nokia5800?

    Hi Pit,
    thanks Reply.

    i uploaded widget file & project file.

    http://project.gclue.jp/ovi/Reversi3.zip
    http://project.gclue.jp/ovi/Reversi3.wgz

    ID:gclue
    PASS:nokia

    please confirm it.
    thanks.

    akira

  4. #4
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: What is the cause to which my WRT widget crashes in Nokia5800?

    Got it,

    time to test and I'll let you know.

    Pit

  5. #5
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: What is the cause to which my WRT widget crashes in Nokia5800?

    First test results:

    * on WRT simulator it keeps playing indefinitely
    * on Nokia 5800XM it plays approx. for 30 seconds and then it gets blocked

    it this the same behavior that you get?

    Pit

  6. #6
    Registered User
    Join Date
    Apr 2009
    Posts
    4

    Re: What is the cause to which my WRT widget crashes in Nokia5800?

    Hi Pit.

    Yes, it is same behavior.
    It keeps playing indefinitely in my assumption.
    However, on Nokia 5800XM it stops at once.

    thanks.

    akira

  7. #7
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: What is the cause to which my WRT widget crashes in Nokia5800?

    Hi akira,

    I've tried enabling JavaScript errors logging on Nokia 5800 (http://library.forum.nokia.com/index...616259DB9.html), and here's the message that is shown when the games stops:
    Code:
    URL: line 181
    Error: Script is too big.
    So, this seems to be an optimization-related issue. You should probably modify your code to make it use less memory/resources on the device itself.

    Hope this helps,
    Pit

  8. #8
    Registered User
    Join Date
    Apr 2009
    Posts
    4

    Re: What is the cause to which my WRT widget crashes in Nokia5800?

    Hi Pit.

    Thank you very much.
    I did not know how to errors logging....

    Tentatively, when it was location.reload() every one game, it operated well.

    thanks.

Similar Threads

  1. Embed Flash Lite within a WRT widget?
    By bryanrieger in forum Symbian
    Replies: 10
    Last Post: 2010-04-18, 17:42
  2. How to open browser in emulator from wrt widget
    By sanjay6564 in forum Symbian
    Replies: 3
    Last Post: 2009-05-11, 10:31
  3. What is WRT 1.0, 1.1, 1.2 versions?
    By naroori in forum Symbian
    Replies: 2
    Last Post: 2008-12-24, 20:07
  4. Replies: 4
    Last Post: 2008-11-10, 14:49

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×