Write a Report as to how you would modify your code if the player was moving, this should be detailed enough that potentially it could be coded, though we are not asking you to write code, just explain how.

Paper, Order, or Assignment Requirements

 

1 page report Write a Report as to how you would modify your code if the player was moving, this should be detailed enough that potentially it could be coded, though we are not asking you to write code, just explain how.

The following is the code;

This Code is an A* algorithm that allows the agent (hedgehog) to find the player (rabbit)

 

 

/*jslint browser:true */

/*global loadImages*/

/*global clearGrid*/

/*global displayImages*/

/*global scaleX*/

/*global scaleY*/

/*global ctx*/

 

var scenery = [[0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],

[0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],

[0, 0, 2, 2, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],

[0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0],

[0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0],

[0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0],

[0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 2, 2, 2, 0, 0, 0],

[0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],

[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],

[0, 0, 0, 0, 2, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 2, 0, 0, 0],

[0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 2, 0, 0, 0],

[0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0],

[0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 2, 0, 0, 0],

[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],

[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]];

var gridState = true;

var Img1, Img2, Img3, Img4;

var Player = [-360, -140];

var Agent = [320, 260];

var moving;

function initialiseExample() {

“use strict”;

loadImages();

return;

}

// to start the game and move the Hedgehog toward to the player.

function startGame() {

“use strict”;

moving = setInterval(function () {moveAgent()}, 500);

}

//stop moving Hedgehog and chasing to the player.

function endGame() {

“use strict”;

clearInterval(moving);

}

function toggleGrid() {

“use strict”;

if (gridState === true) {

clearGrid(false, false, 40);

gridState = false;

displayImages();

} else {

clearGrid(true, false, 40);

gridState = true;

displayImages();

}

}

 

//The Agent will look for four directions and find the shortest way forward the Player to step. This function will loop until the Agent reaches the Player.

function moveAgent() {

“use strict”;

var i, m, n;

var checkingPoints = [];

var checkingX,checkingY, X1, Y1;

var distance = function(x1, y1, x2, y2) {

return Math.sqrt((x1 – x2) * (x1 – x2) + (y1 – y2) * (y1 – y2));

}

for (var i = 1; i <= 4; i++) {

switch(i){

//For suitable heuristics, the Agent always considers 4 directions: up, down, left, right distance to the Player for each case will be calculated and the optimized direction will be chosen.

case 1:

checkingX = Agent[0] + 40;

checkingY = Agent[1] + 0;

break;

case 2:

checkingX = Agent[0] + 0;

checkingY = Agent[1] + 40;

break;

case 3:

checkingX = Agent[0] + -40;

checkingY = Agent[1] + 0;

break;

case 4:

checkingX = Agent[0] + 0;

checkingY = Agent[1] + -40;

break;

default:

break;

}

if (checkingX >= 400 || checkingX <= -400 || checkingY >=340 || checkingY <= -300){

continue;

}

 

var checkObstacle = false; // check if the position is available.

for (m = 0; m < 15; m = m + 1) {

for (n = 0; n < 20; n = n + 1) {

if (scenery[m][n]) {

Y1 = Number(300 – (40 * m));

X1 = Number((40 * n) + -400);

if (checkingX == X1 && checkingY == Y1){

checkObstacle = true;

}

}

}

}

if (checkObstacle){

continue;

}

checkingPoints.push([checkingX,checkingY]);

};

var checkedPoint = 0;

var minDistance = distance(Player[0],Player[1],checkingPoints[0][0],checkingPoints[0][1]);// find distance between two location.

for (var i = 0; i < checkingPoints.length; i++) {

console.log(distance(Player[0],Player[1],checkingPoints[i][0],checkingPoints[i][1]));// the location for the shortest distance.

if (distance(Player[0],Player[1],checkingPoints[i][0],checkingPoints[i][1]) < minDistance){

checkedPoint = i;

minDistance = distance(Player[0],Player[1],checkingPoints[i][0],checkingPoints[0][1]);

}

};

Agent = checkingPoints[checkedPoint]; //move the agent

clearGrid(true, true, 40);

displayImages();

if(distance(Agent[0],Agent[1],Player[0],Player[1]) == 0){ // check the distance between the agent and the player is 0.

clearInterval(moving);

}

}

 

function loadImages() {

“use strict”;

var imgToLoad = 4, imgLoaded = 0;

var onImgLoad = function () {

imgLoaded = imgLoaded + 1;

if (imgLoaded === imgToLoad) {

displayImages();

}

};

Img1 = new Image();

Img1.src = ‘images/playerf.gif’;

Img1.onload = onImgLoad;

Img2 = new Image();

Img2.src = ‘images/hogf.gif’;

Img2.onload = onImgLoad;

Img3 = new Image();

Img3.src = ‘images/river.gif’;

Img3.onload = onImgLoad;

Img4 = new Image();

Img4.src = ‘images/tree.gif’;

Img4.onload = onImgLoad;

}

 

function displayImages() {

“use strict”;

var X1, Y1, i, j;

//display User

X1 = scaleX(Number(Player[0]));

Y1 = scaleY(Number(Player[1]));

ctx.drawImage(Img1, X1, Y1);

//display Enemy

X1 = scaleX(Number(Agent[0]));

Y1 = scaleY(Number(Agent[1]));

ctx.drawImage(Img2, X1, Y1);

//display Scenery

for (i = 0; i < 15; i = i + 1) {

for (j = 0; j < 20; j = j + 1) {

if (scenery[i][j] === 1) {

Y1 = scaleY(Number(300 – (40 * i)));

X1 = scaleX(Number((40 * j) + -400));

ctx.drawImage(Img3, X1, Y1);

}

if (scenery[i][j] === 2) {

Y1 = scaleY(Number(300 – (40 * i)));

X1 = scaleX(Number((40 * j) + -400));

ctx.drawImage(Img4, X1, Y1);

}

}

}

}

 

function doKeyDown(e) {

“use strict”;

var tempx, tempy;

if (e.keyCode === 119) { //W Key

tempy = Player[1];

tempy = tempy + 40;

Player[1] = tempy;

}

if (e.keyCode === 115) { //S Key

tempy = Player[1];

tempy = tempy – 40;

Player[1] = tempy;

}

if (e.keyCode === 97) { //A Key

tempx = Player[0];

tempx = tempx – 40;

Player[0] = tempx;

}

if (e.keyCode === 100) { //D Key

tempx = Player[0];

tempx = tempx + 40;

Player[0] = tempx;

}

clearGrid(gridState, false, 40);

displayImages();

}

 

 

Write a Report (1 page) as to how you would modify your code if the player was moving, this should be detailed enough that potentially it could be coded, though we are not asking you to write code, just explain how.

 

RABBIT=PLAYER

Order a unique copy of this paper
(550 words)

Approximate price: $22

Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees

Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.

Money-back guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

Read more

Zero-plagiarism guarantee

Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.

Read more

Free-revision policy

Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.

Read more

Privacy policy

Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.

Read more

Fair-cooperation guarantee

By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.

Read more

Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
$26
The price is based on these factors:
Academic level
Number of pages
Urgency

Order your essay today and save 7% with the discount code CPH7