Code viewer for World: Mind Tutorial

// Cloned by Mathias Bazin on 13 Aug 2018 from World "Mind Tutorial" by Mathias Bazin 
// Please leave this clone trail here.
 

let actionEnum = Object.freeze({up: 0, down: 1, right: 2, left: 3});
let agent;
let coin;

function World() 
{ 

	this.newRun = function()
	{
	    //draw the scene
		
 	    ABWorld.init2d ( 100, 1000, "black" ); 
 	    
 	    agent = new THREE.Mesh( new THREE.SphereGeometry( 5, 32, 32 ), new THREE.MeshBasicMaterial({color: "red"}) );
 	    ABWorld.scene.add(agent);
 	    
 	    coin =  new THREE.Mesh( new THREE.SphereGeometry( 2, 32, 32 ), new THREE.MeshBasicMaterial({color: "yellow"}) );
 	    coin.position.set(AB.randomIntAtoB ( -50, 50 ),0,AB.randomIntAtoB ( -50, 50 ));
 	    ABWorld.scene.add(coin);
 	    
 		
	};


	this.takeAction = function ( action )		 
	{
		// Code for Three.js re-drawing of objects.  
		switch(action)
		{
		    case actionEnum.up:
		        agent.position.z -= 1;
		        break;
		        
		    case actionEnum.down:
		        agent.position.z += 1;
		        break;
		        
		    case actionEnum.left:
		        agent.position.x -= 1;
		        break;
		        
		    case actionEnum.right:
		        agent.position.x += 1;
		        break;
		}
	};


	this.endRun = function()
	{
	};


	this.getState = function()
	{
	    let state = {
	        agentx: agent.position.x,
	        agentz: agent.position.z,
	        coinx: coin.position.x,
	        coinz: coin.position.z,
	    };
	    
	  return ( state );  				 
	};

	
	this.getScore = function()
 	{
	  return ( 0 );		
	};

}