WE WRITE CUSTOM ACADEMIC PAPERS

100% Original, Plagiarism Free, Tailored to your instructions

Order Now!

Graphics and Artificial Intelligence

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 Now https://thecustomwritings.com/order/ YOU CAN ALSO PLACE OTHER SIMILAR ORDERS ON OUR WEBSITE AND GET AMAZING DISCOUNTS!!!

Our Service Charter

  1. Excellent Quality / 100% Plagiarism-Free

    We employ a number of measures to ensure top quality essays. The papers go through a system of quality control prior to delivery. We run plagiarism checks on each paper to ensure that they will be 100% plagiarism-free. So, only clean copies hit customers’ emails. We also never resell the papers completed by our writers. So, once it is checked using a plagiarism checker, the paper will be unique. Speaking of the academic writing standards, we will stick to the assignment brief given by the customer and assign the perfect writer. By saying “the perfect writer” we mean the one having an academic degree in the customer’s study field and positive feedback from other customers.
  2. Free Revisions

    We keep the quality bar of all papers high. But in case you need some extra brilliance to the paper, here’s what to do. First of all, you can choose a top writer. It means that we will assign an expert with a degree in your subject. And secondly, you can rely on our editing services. Our editors will revise your papers, checking whether or not they comply with high standards of academic writing. In addition, editing entails adjusting content if it’s off the topic, adding more sources, refining the language style, and making sure the referencing style is followed.
  3. Confidentiality / 100% No Disclosure

    We make sure that clients’ personal data remains confidential and is not exploited for any purposes beyond those related to our services. We only ask you to provide us with the information that is required to produce the paper according to your writing needs. Please note that the payment info is protected as well. Feel free to refer to the support team for more information about our payment methods. The fact that you used our service is kept secret due to the advanced security standards. So, you can be sure that no one will find out that you got a paper from our writing service.
  4. Money Back Guarantee

    If the writer doesn’t address all the questions on your assignment brief or the delivered paper appears to be off the topic, you can ask for a refund. Or, if it is applicable, you can opt in for free revision within 14-30 days, depending on your paper’s length. The revision or refund request should be sent within 14 days after delivery. The customer gets 100% money-back in case they haven't downloaded the paper. All approved refunds will be returned to the customer’s credit card or Bonus Balance in a form of store credit. Take a note that we will send an extra compensation if the customers goes with a store credit.
  5. 24/7 Customer Support

    We have a support team working 24/7 ready to give your issue concerning the order their immediate attention. If you have any questions about the ordering process, communication with the writer, payment options, feel free to join live chat. Be sure to get a fast response. They can also give you the exact price quote, taking into account the timing, desired academic level of the paper, and the number of pages.

Excellent Quality
Zero Plagiarism
Expert Writers

Instant Quote

Subject:
Type:
Pages/Words:
Single spaced
approx 275 words per page
Urgency (Less urgent, less costly):
Level:
Currency:
Total Cost: NaN

Get 10% Off on your 1st order!