Find the shortest route through a maze using linking and linked lists, the strategy is based on the
concept of breadth first search. (Code for maze provided) (Previously asked before with no
response)
--------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------
--------------------------------
We are going to look at the problem of finding the shortest path through a maze. We will make
use of linking and linked lists to discover the shortest path from the entrance to the center of the
maze. The strategy we will use is based on the concept of breadth first search.
You will be provided with a GUI program that creates and draws a maze. It also provides a
method which you will use to draw the shortest path when you have discovered it. The following
illustrates the program running when it has been successfully completed.
The Maze
The maze is represented in the program by the Maze class (where you will add code to find and
draw the shortest path). It uses a 2 dimensional array of MazeCell objects to capture all the
important data about the maze itself. The MazeCell class is as follows:
class MazeCell {
// nth, sth, est, wst used to identify walls
// true indicates the wall is present
boolean nth, sth, wst, est;
// visited is used to indicate that a cell has been processed
boolean visited;
// row, col is used to facilitate finding the neighbors of a cell
int row, col;
// Constructor takes a row and column parameter for the cell
public MazeCell(int i, int j) {
row = i;
col = j;
// All walls are initially present for every cell
// The build process will remove some of the walls
nth = sth = est = wst = true;
// Initially no cells have been visited
visited = false;
}
}
Once the maze has been built, each cell contains its own row and column number. The walls of
the cell have been set to true or false. Any wall set to false means that there is a neighboring cell
in that direction which can be accessed. For example, if nth is set to false, then there is no wall
between this cell and its neighboring cell to the north. The orientation of the maze relative to the
GUI representation and relative to the directions is as follows:
0, n-1 North
n-1, n-1 West
East 0, 0
South n-1, 0
In the GUI representation, rows of the maze are vertical, columns are horizontal. Cell 0,0 of the
maze in drawn in the lower left corner. The following summarizes what to do to move in a
specific direction from any cell in the maze. Remember, each cell contains its own row, col
position.
North neighbor is at row, col + 1
South neighbor is at row, col – 1
East neighbor is at row + 1, col
West neighbor is at row – 1, col
The 2 dimensional array is set up with 2 additional rows and 2 additional columns to serve as a
border for the actual maze itself. The entry point to the maze is at cell 1, 1. The center of the
maze is.
I need help with this maze gui that I wrote in java, I am trying to .pdfarihantgiftgallery
I need help with this maze gui that I wrote in java, I am trying to find the shortest path but I dont
know how to implement the FindshortestPath Method.
using a BREADTH FIRST SEARCH and the stradgey below to ONLY FIND THE SHORTEST
PATH, the method \"FindshortestPath(); is the only part you need to add code too.
I was given this as a stragedy to solve the findshortestpathMethod():
Create two LinkedLists of MazeMap objects. One will be the list of map objects for cells at
distance x from the center. The other will be the list of map objects for cells at distance x + 1.
Initialize the list at distance x to contain a MazeMap object which refers to the center cell of the
maze. Since this map object refers to the center cell, it does not need to refer to any other
MazeMap object, so its MazeMap reference can be set to null. Set the center cell’s visited field
to true to indicate that this cell has already been added to the map.
Set up a loop to run until the maze entrance is mapped. This loop does the following:
Set up a loop to process each map object from the list at distance x. This loop does the following:
i.Get the cell from the map object
ii.If this cell is the entrance cell, set the entrance and break out of the loop!
iii.Check each direction from this cell and for an accessible neighbor cell
Get a reference to that neighbor cell
If the neighbor cell has not already been visited
Set the cell’s visited field to true so its only processed once
Create a MazeMap object that refers to this neighbor cell
Make this MazeMap object refer to the current map object being processed – ie the cell one step
closer to center
Add this MazeMap object to the list at distance x + 1
List at distance x has been processed. The list at distance x + 1 is now complete, so make the list
at distance x refer to list at distance x + 1. Then create a new empty list for the list at distance x +
1.
At this point, the entrance points at the map object which refers to cell 1,1. That map object also
refers to a map object which is one step closer to the center. Write a loop that traverses this trail
of references until it reaches the end (a null reference). For each map object:
Get the cell referred to.
Call the drawCircle method with a color, the cell’s row and column, and SMALL.
Call the delay method with a SHORT delay. This slows down the drawing process so you can
watch the path being displayed.
Advance to the next map object in the list.
here is the code so far*********
package mazepackage;
import java.util.LinkedList;
import java.util.Random;
import javafx.scene.paint.Color;
public class Maze {
private int N; // dimension of maze
private MazeCell[][] maze;
private Random rand = new Random();
// Used to signal the maze has been solved
private boolean done;
// time in milliseconds (from currentTimeMillis()) when we can draw again
// used to control the frame rate
private long nextDraw = -1;
private MazeApp mf;
// Define constants for the circle size
private final double BI.
SaveI need help with this maze gui that I wrote in java, I am tryi.pdfarihantstoneart
Save
I need help with this maze gui that I wrote in java, I am trying to find the shortest path but I dont
know how to implement the FindshortestPath Method.
I was given this as a stragedy to solve the findshortestpathMethod():
Create two LinkedLists of MazeMap objects. One will be the list of map objects for cells at
distance x from the center. The other will be the list of map objects for cells at distance x + 1.
Initialize the list at distance x to contain a MazeMap object which refers to the center cell of the
maze. Since this map object refers to the center cell, it does not need to refer to any other
MazeMap object, so its MazeMap reference can be set to null. Set the center cell’s visited field
to true to indicate that this cell has already been added to the map.
Set up a loop to run until the maze entrance is mapped. This loop does the following:
Set up a loop to process each map object from the list at distance x. This loop does the following:
i.Get the cell from the map object
ii.If this cell is the entrance cell, set the entrance and break out of the loop!
iii.Check each direction from this cell and for an accessible neighbor cell
Get a reference to that neighbor cell
If the neighbor cell has not already been visited
Set the cell’s visited field to true so its only processed once
Create a MazeMap object that refers to this neighbor cell
Make this MazeMap object refer to the current map object being processed – ie the cell one step
closer to center
Add this MazeMap object to the list at distance x + 1
List at distance x has been processed. The list at distance x + 1 is now complete, so make the list
at distance x refer to list at distance x + 1. Then create a new empty list for the list at distance x +
1.
At this point, the entrance points at the map object which refers to cell 1,1. That map object also
refers to a map object which is one step closer to the center. Write a loop that traverses this trail
of references until it reaches the end (a null reference). For each map object:
Get the cell referred to.
Call the drawCircle method with a color, the cell’s row and column, and SMALL.
Call the delay method with a SHORT delay. This slows down the drawing process so you can
watch the path being displayed.
Advance to the next map object in the list.
here is the code so far*********
here is my code: ******mazeApp*******
package mazepackage;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.TextInputDialog;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class MazeApp extends Application
{
// default canvas size is DEFAULT_SIZE-by-DEFAULT_SIZE
private static final int DEFAULT_SIZE = 768;
private int width = DEFAULT_SIZE;
private int height = DEFAULT_SIZE;
// The graphics context is needed to enable drawing on the canvas
private Graphics.
1) IntroductionThis practical work consists of developingAbbyWhyte974
1) Introduction:
This practical work consists of developing a set of definitions of functions which make it
possible to generate mazes and draw them using the turtle.
In this work, you have to imagine that you are the programmer of a library that allows
you to generate labyrinths. You must write functions that will be used by other
programmers to make specific drawings. (create a labyrinth of a certain size).
The algorithm for generating mazes is imposed on you and is described in the next
section. Your task is to code this algorithm, and the necessary helper functions, in
Python using Turtle.
2) Labyrinths
The mazes you need to generate are based on a rectangular grid like this:
This grid is made up of square cells. In this example there are 8 columns and 4 rows of
cells. For a given cell there are 4 walls that we will call the North, East, South, and West
walls (to simplify \ N ", \ E", \ S ", \ O") of the cell. A labyrinth has a certain width in
number of cells (NX), a certain height in number of cells (NY), and a certain “step”(the
width and height of each square cell, in number of pixels). The labyrinth is therefore
created by eliminating certain walls from the grid. The outer wall of the grid is drilled at
the top left (the entrance to the labyrinth) and lower right (the exit from the labyrinth).
The creation of a labyrinth consists of determining which walls in each cell need to be
removed. For each cell it is necessary to eliminate at least one of its 4 walls, and
possibly all 4. Here is a labyrinth using the previous grid (i.e. with NX = 8, NY = 4, step =
40):
The choice of the walls to eliminate cannot be done completely randomly because this
could generate a drawing. which is not a labyrinth, that is to say a drawing which does
not follow a path from the entrance to the exit. The algorithm you should use uses
random numbers to create the maze but ensures that there always is exactly one path
between entering and exiting the maze. In fact, the algorithm guarantees that there is
always exactly one path between any cell and any other cell (what is formally called
an underlying tree). Before explaining the algorithm we must first number each
horizontal wall and each vertical wall and give a coordinate (x, y) to each cell as follows:
It should be noted that the coordinate system (x, y) of the cells places (0,0) at the top
left (x grows towards the right, and grows down there). Also notice that there are NX
(NY + 1) horizontal walls and (NX + 1) NY vertical walls. So the horizontal walls are
numbered from 0 to (NX (NY + 1)) 1 and the vertical walls from 0 to ((NX + 1) NY) 1.
The relation between the (x, y) coordinate of a cell and the numbers of its walls N, E, S,
O is the next one :
N = x + y x NX
E = 1 + x + y x (NX + 1)
S = x + (y + 1) x NX
O = x + y x (NX + 1)
Note that the wall number N can be used to uniquely identify a cell with
only one number. For example in the grid above the cell in position (5,2) has the nu ...
1) IntroductionThis practical work consists of developingMartineMccracken314
1) Introduction:
This practical work consists of developing a set of definitions of functions which make it
possible to generate mazes and draw them using the turtle.
In this work, you have to imagine that you are the programmer of a library that allows
you to generate labyrinths. You must write functions that will be used by other
programmers to make specific drawings. (create a labyrinth of a certain size).
The algorithm for generating mazes is imposed on you and is described in the next
section. Your task is to code this algorithm, and the necessary helper functions, in
Python using Turtle.
2) Labyrinths
The mazes you need to generate are based on a rectangular grid like this:
This grid is made up of square cells. In this example there are 8 columns and 4 rows of
cells. For a given cell there are 4 walls that we will call the North, East, South, and West
walls (to simplify \ N ", \ E", \ S ", \ O") of the cell. A labyrinth has a certain width in
number of cells (NX), a certain height in number of cells (NY), and a certain “step”(the
width and height of each square cell, in number of pixels). The labyrinth is therefore
created by eliminating certain walls from the grid. The outer wall of the grid is drilled at
the top left (the entrance to the labyrinth) and lower right (the exit from the labyrinth).
The creation of a labyrinth consists of determining which walls in each cell need to be
removed. For each cell it is necessary to eliminate at least one of its 4 walls, and
possibly all 4. Here is a labyrinth using the previous grid (i.e. with NX = 8, NY = 4, step =
40):
The choice of the walls to eliminate cannot be done completely randomly because this
could generate a drawing. which is not a labyrinth, that is to say a drawing which does
not follow a path from the entrance to the exit. The algorithm you should use uses
random numbers to create the maze but ensures that there always is exactly one path
between entering and exiting the maze. In fact, the algorithm guarantees that there is
always exactly one path between any cell and any other cell (what is formally called
an underlying tree). Before explaining the algorithm we must first number each
horizontal wall and each vertical wall and give a coordinate (x, y) to each cell as follows:
It should be noted that the coordinate system (x, y) of the cells places (0,0) at the top
left (x grows towards the right, and grows down there). Also notice that there are NX
(NY + 1) horizontal walls and (NX + 1) NY vertical walls. So the horizontal walls are
numbered from 0 to (NX (NY + 1)) 1 and the vertical walls from 0 to ((NX + 1) NY) 1.
The relation between the (x, y) coordinate of a cell and the numbers of its walls N, E, S,
O is the next one :
N = x + y x NX
E = 1 + x + y x (NX + 1)
S = x + (y + 1) x NX
O = x + y x (NX + 1)
Note that the wall number N can be used to uniquely identify a cell with
only one number. For example in the grid above the cell in position (5,2) has the nu ...
These questions are prepared by Classical Programming Experts and are asked during job interviews.The Solution to the given programs are prepared by Programming Experts and are often asked in job interviews. Knowing solution to these problems will help you clear your concepts.
I need help with this maze gui that I wrote in java, I am trying to .pdfarihantgiftgallery
I need help with this maze gui that I wrote in java, I am trying to find the shortest path but I dont
know how to implement the FindshortestPath Method.
using a BREADTH FIRST SEARCH and the stradgey below to ONLY FIND THE SHORTEST
PATH, the method \"FindshortestPath(); is the only part you need to add code too.
I was given this as a stragedy to solve the findshortestpathMethod():
Create two LinkedLists of MazeMap objects. One will be the list of map objects for cells at
distance x from the center. The other will be the list of map objects for cells at distance x + 1.
Initialize the list at distance x to contain a MazeMap object which refers to the center cell of the
maze. Since this map object refers to the center cell, it does not need to refer to any other
MazeMap object, so its MazeMap reference can be set to null. Set the center cell’s visited field
to true to indicate that this cell has already been added to the map.
Set up a loop to run until the maze entrance is mapped. This loop does the following:
Set up a loop to process each map object from the list at distance x. This loop does the following:
i.Get the cell from the map object
ii.If this cell is the entrance cell, set the entrance and break out of the loop!
iii.Check each direction from this cell and for an accessible neighbor cell
Get a reference to that neighbor cell
If the neighbor cell has not already been visited
Set the cell’s visited field to true so its only processed once
Create a MazeMap object that refers to this neighbor cell
Make this MazeMap object refer to the current map object being processed – ie the cell one step
closer to center
Add this MazeMap object to the list at distance x + 1
List at distance x has been processed. The list at distance x + 1 is now complete, so make the list
at distance x refer to list at distance x + 1. Then create a new empty list for the list at distance x +
1.
At this point, the entrance points at the map object which refers to cell 1,1. That map object also
refers to a map object which is one step closer to the center. Write a loop that traverses this trail
of references until it reaches the end (a null reference). For each map object:
Get the cell referred to.
Call the drawCircle method with a color, the cell’s row and column, and SMALL.
Call the delay method with a SHORT delay. This slows down the drawing process so you can
watch the path being displayed.
Advance to the next map object in the list.
here is the code so far*********
package mazepackage;
import java.util.LinkedList;
import java.util.Random;
import javafx.scene.paint.Color;
public class Maze {
private int N; // dimension of maze
private MazeCell[][] maze;
private Random rand = new Random();
// Used to signal the maze has been solved
private boolean done;
// time in milliseconds (from currentTimeMillis()) when we can draw again
// used to control the frame rate
private long nextDraw = -1;
private MazeApp mf;
// Define constants for the circle size
private final double BI.
SaveI need help with this maze gui that I wrote in java, I am tryi.pdfarihantstoneart
Save
I need help with this maze gui that I wrote in java, I am trying to find the shortest path but I dont
know how to implement the FindshortestPath Method.
I was given this as a stragedy to solve the findshortestpathMethod():
Create two LinkedLists of MazeMap objects. One will be the list of map objects for cells at
distance x from the center. The other will be the list of map objects for cells at distance x + 1.
Initialize the list at distance x to contain a MazeMap object which refers to the center cell of the
maze. Since this map object refers to the center cell, it does not need to refer to any other
MazeMap object, so its MazeMap reference can be set to null. Set the center cell’s visited field
to true to indicate that this cell has already been added to the map.
Set up a loop to run until the maze entrance is mapped. This loop does the following:
Set up a loop to process each map object from the list at distance x. This loop does the following:
i.Get the cell from the map object
ii.If this cell is the entrance cell, set the entrance and break out of the loop!
iii.Check each direction from this cell and for an accessible neighbor cell
Get a reference to that neighbor cell
If the neighbor cell has not already been visited
Set the cell’s visited field to true so its only processed once
Create a MazeMap object that refers to this neighbor cell
Make this MazeMap object refer to the current map object being processed – ie the cell one step
closer to center
Add this MazeMap object to the list at distance x + 1
List at distance x has been processed. The list at distance x + 1 is now complete, so make the list
at distance x refer to list at distance x + 1. Then create a new empty list for the list at distance x +
1.
At this point, the entrance points at the map object which refers to cell 1,1. That map object also
refers to a map object which is one step closer to the center. Write a loop that traverses this trail
of references until it reaches the end (a null reference). For each map object:
Get the cell referred to.
Call the drawCircle method with a color, the cell’s row and column, and SMALL.
Call the delay method with a SHORT delay. This slows down the drawing process so you can
watch the path being displayed.
Advance to the next map object in the list.
here is the code so far*********
here is my code: ******mazeApp*******
package mazepackage;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.TextInputDialog;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class MazeApp extends Application
{
// default canvas size is DEFAULT_SIZE-by-DEFAULT_SIZE
private static final int DEFAULT_SIZE = 768;
private int width = DEFAULT_SIZE;
private int height = DEFAULT_SIZE;
// The graphics context is needed to enable drawing on the canvas
private Graphics.
1) IntroductionThis practical work consists of developingAbbyWhyte974
1) Introduction:
This practical work consists of developing a set of definitions of functions which make it
possible to generate mazes and draw them using the turtle.
In this work, you have to imagine that you are the programmer of a library that allows
you to generate labyrinths. You must write functions that will be used by other
programmers to make specific drawings. (create a labyrinth of a certain size).
The algorithm for generating mazes is imposed on you and is described in the next
section. Your task is to code this algorithm, and the necessary helper functions, in
Python using Turtle.
2) Labyrinths
The mazes you need to generate are based on a rectangular grid like this:
This grid is made up of square cells. In this example there are 8 columns and 4 rows of
cells. For a given cell there are 4 walls that we will call the North, East, South, and West
walls (to simplify \ N ", \ E", \ S ", \ O") of the cell. A labyrinth has a certain width in
number of cells (NX), a certain height in number of cells (NY), and a certain “step”(the
width and height of each square cell, in number of pixels). The labyrinth is therefore
created by eliminating certain walls from the grid. The outer wall of the grid is drilled at
the top left (the entrance to the labyrinth) and lower right (the exit from the labyrinth).
The creation of a labyrinth consists of determining which walls in each cell need to be
removed. For each cell it is necessary to eliminate at least one of its 4 walls, and
possibly all 4. Here is a labyrinth using the previous grid (i.e. with NX = 8, NY = 4, step =
40):
The choice of the walls to eliminate cannot be done completely randomly because this
could generate a drawing. which is not a labyrinth, that is to say a drawing which does
not follow a path from the entrance to the exit. The algorithm you should use uses
random numbers to create the maze but ensures that there always is exactly one path
between entering and exiting the maze. In fact, the algorithm guarantees that there is
always exactly one path between any cell and any other cell (what is formally called
an underlying tree). Before explaining the algorithm we must first number each
horizontal wall and each vertical wall and give a coordinate (x, y) to each cell as follows:
It should be noted that the coordinate system (x, y) of the cells places (0,0) at the top
left (x grows towards the right, and grows down there). Also notice that there are NX
(NY + 1) horizontal walls and (NX + 1) NY vertical walls. So the horizontal walls are
numbered from 0 to (NX (NY + 1)) 1 and the vertical walls from 0 to ((NX + 1) NY) 1.
The relation between the (x, y) coordinate of a cell and the numbers of its walls N, E, S,
O is the next one :
N = x + y x NX
E = 1 + x + y x (NX + 1)
S = x + (y + 1) x NX
O = x + y x (NX + 1)
Note that the wall number N can be used to uniquely identify a cell with
only one number. For example in the grid above the cell in position (5,2) has the nu ...
1) IntroductionThis practical work consists of developingMartineMccracken314
1) Introduction:
This practical work consists of developing a set of definitions of functions which make it
possible to generate mazes and draw them using the turtle.
In this work, you have to imagine that you are the programmer of a library that allows
you to generate labyrinths. You must write functions that will be used by other
programmers to make specific drawings. (create a labyrinth of a certain size).
The algorithm for generating mazes is imposed on you and is described in the next
section. Your task is to code this algorithm, and the necessary helper functions, in
Python using Turtle.
2) Labyrinths
The mazes you need to generate are based on a rectangular grid like this:
This grid is made up of square cells. In this example there are 8 columns and 4 rows of
cells. For a given cell there are 4 walls that we will call the North, East, South, and West
walls (to simplify \ N ", \ E", \ S ", \ O") of the cell. A labyrinth has a certain width in
number of cells (NX), a certain height in number of cells (NY), and a certain “step”(the
width and height of each square cell, in number of pixels). The labyrinth is therefore
created by eliminating certain walls from the grid. The outer wall of the grid is drilled at
the top left (the entrance to the labyrinth) and lower right (the exit from the labyrinth).
The creation of a labyrinth consists of determining which walls in each cell need to be
removed. For each cell it is necessary to eliminate at least one of its 4 walls, and
possibly all 4. Here is a labyrinth using the previous grid (i.e. with NX = 8, NY = 4, step =
40):
The choice of the walls to eliminate cannot be done completely randomly because this
could generate a drawing. which is not a labyrinth, that is to say a drawing which does
not follow a path from the entrance to the exit. The algorithm you should use uses
random numbers to create the maze but ensures that there always is exactly one path
between entering and exiting the maze. In fact, the algorithm guarantees that there is
always exactly one path between any cell and any other cell (what is formally called
an underlying tree). Before explaining the algorithm we must first number each
horizontal wall and each vertical wall and give a coordinate (x, y) to each cell as follows:
It should be noted that the coordinate system (x, y) of the cells places (0,0) at the top
left (x grows towards the right, and grows down there). Also notice that there are NX
(NY + 1) horizontal walls and (NX + 1) NY vertical walls. So the horizontal walls are
numbered from 0 to (NX (NY + 1)) 1 and the vertical walls from 0 to ((NX + 1) NY) 1.
The relation between the (x, y) coordinate of a cell and the numbers of its walls N, E, S,
O is the next one :
N = x + y x NX
E = 1 + x + y x (NX + 1)
S = x + (y + 1) x NX
O = x + y x (NX + 1)
Note that the wall number N can be used to uniquely identify a cell with
only one number. For example in the grid above the cell in position (5,2) has the nu ...
These questions are prepared by Classical Programming Experts and are asked during job interviews.The Solution to the given programs are prepared by Programming Experts and are often asked in job interviews. Knowing solution to these problems will help you clear your concepts.
In this presentation, we will be building a Sudoku Solver solely using Functional Programming idioms in Scala. This is a great opportunity to learn the very basics of Scala, the power of its built in Vector library and how it differs from what's build in Java 8.
The presentation will be structured as follow:
1. Quick Introduction to Sudoku
2. Short introduction to Scala and the concepts required for the Solver
3. Let's get coding!
-- USING UNITY TRYING TO CREATE A CLICK TO PATH- THAT YOU CLICK ON AND.pdfganisyedtrd
// USING UNITY TRYING TO CREATE A CLICK TO PATH, THAT YOU CLICK ON AND
THE AGENT/AVATAR FOLLOWS THE BEST PATH TO GET THERE
// AT THE SAME TIME THERE IS A GUARD CHASING THE AGENT USING
AWARENESS AND PAHTFINDING.
//THIS IS THE MapManager.cs the Agent.cs I could upload it
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.UI;
// Custom struct to hold the per-tile information needed for the A* pathing search
public struct grid_cell
{
public bool visited;
public bool isBlocked;
public Vector2Int parent;
public float g, h, f;
}
public class MapManager : MonoBehaviour
{
// fixed map size for simplicity - map file must match
public const int WIDTH = 12;
public const int HEIGHT = 12;
// need to know tile size (color for debugging)
private Vector2 TILE_SIZE;
private Color TILE_COLOR;
// prefab tiles (and debugging labels)
public GameObject[] _tilePrefabs;
public GameObject _labelPrefab;
public GameObject _uiCanvas;
// A* pathfinding array and queue
private grid_cell[,] _map = new grid_cell[WIDTH, HEIGHT];
private List<KeyValuePair<float, Vector2Int>> _openList = new List<KeyValuePair<float,
Vector2Int>>();
// references to tile spriterenderers and tile labels for debugging
private SpriteRenderer[,] _tiles = new SpriteRenderer[WIDTH, HEIGHT];
private Text[,] _labels = new Text[WIDTH, HEIGHT];
// steps is a convenient way to generate the 8 children of a grid square
private Vector2Int[] _steps = new Vector2Int[8];
void Start()
{
TILE_SIZE = _tilePrefabs[0].transform.GetComponent<SpriteRenderer>()
.bounds.extents * 2;
// load map and create tiles
readMapFile();
// for debugging, store the color of an unblocked tile (for changing them back)
TILE_COLOR = _tiles[0,0].color;
// store "step" vectors for the four cardinal directions
_steps[0].x = -1; _steps[0].y = 0;
_steps[1].x = 0; _steps[1].y = -1;
_steps[2].x = 0; _steps[2].y = 1;
_steps[3].x = 1; _steps[3].y = 0;
// and the four diagonal directions
_steps[4].x = 1; _steps[4].y = 1;
_steps[5].x = 1; _steps[5].y = -1;
_steps[6].x = -1; _steps[6].y = 1;
_steps[7].x = -1; _steps[7].y = -1;
}
/*********************************************************************************************
Collision with blocked tiles (walls)
- called by agents
- returns a response vector indicating the amount to "push" the agent out of the walls
- (0,0) indicates no collisions happening
*/
public Vector2 checkBlockedCollision(Vector2 pos, Vector2 extents)
{
// convert the world position that we're checking to the coordinates of a grid cell
Vector2Int posGC = vectorToGC(pos);
// loop over the diagonal steps to check the diagonally-adjacent cells
// check those first, because a diagonal collision implies two cardinal direction collisions
for (int si=4;si<_steps.Length;si++) {
// for each diagonal neighbor
Vector2Int step = _steps[si];
Vector2Int neighbor = posGC + step;
// if it's not on the map or not blocked, then no collision possible
if (!onMap(neighbor)) continue;
if.
Java Question help needed In the program Fill the Add statements.pdfkamdinrossihoungma74
Item 8 Singly ionized (one electron removed) atoms are accelerated and then passed through a
velocity selector consisting of perpendicular electric and magnetic fields. The electric field is 158
V/m and the magnetic field is 3.13 Times 10^2 T. The ions next enter a uniform magnetic field
of magnitude 1.73 Times 10^-2 T that is oriented perpendicular to their velocity. How fast are
the ions moving when they emerge from the velocity selector? If the radius of the path of the
ions in the second magnetic field is 17.4 cm, what is their mass?
Solution
A)
In Velocity selector Electric field & Magnetic field forces on ions are equal & opposite ,this is
because it allows ions with a particular velocity only passes undeflected.
so we can say,
Bqv = Eq
B:magnetic field density
E:Electric field
v:velocity at which the ions remains undeflected.
v=E/B
v = 158V/m / 3.13*10-2 T
=> v = 4.78*103 m/s
B)
as it enteres next in uniform magnetic field of value B=1.73*10-2 T
Work done in uniform magnetic field is zero.It only changes the direction.So B provides
centripetal force for the ions while changing direction in circular path of radius r=17.4cm.
Bqv = mv²/r
m = Bqr / v = (1.73*10-2T)(1.6*10-19C)(0.174m) / (4.78*103m/s)
=>m = 1*10-25 kg.
In this chapter we are going to get familiar with recursion and its applications. Recursion represents a powerful programming technique in which a method makes a call to itself from within its own method body. By means of recursion we can solve complicated combinatorial problems, in which we can easily exhaust different combinatorial configurations, e.g. generating permutations and variations and simulating nested loops. We are going to demonstrate many examples of correct and incorrect usage of recursion and convince you how useful it can be.
Briefly explain four functions of stems. SolutionFunction of S.pdfsanuoptical
Briefly explain four functions of stems.
Solution
Function of Stems:
1. It helps store water , as in cacti, and the products of photosynthesis, as in the trunk of sago
palm (Metroxylon sagu) and sweet palm (Argenga pinnata) which store large stock of starch
2. Young green stem also performs a minor role in the production of food through the process of
photosynthesis, but in some species (e.g. cactus) the stem is the chief photosynthesizing organ
3. It supports the leaves, flowers and fruits and connect them with roots. In trees and shrubs the
main stem or trunk provides a strong columnar structure from which branches are attached
raising the leaves upward to be expressed more fully to the sun
4. The plant stem serves as a means of asexual reproduction in many species..
AVR was one of the first microcontroller families to use A. on-chip .pdfsanuoptical
AVR was one of the first microcontroller families to use A. on-chip flash memory for program
storage B. one-time programmable ROM, EPROM, or EEPROM C. both A and B
EMBEDDED SYSTEMS is a computer system with a dedicated function within a larger A.
digital and logical system B. mechanical or electrical system C. both A and B An integrated
circuit that contains all the functions of a central processing unit of a computer is A.
Microprocessor B. Microcontroller C. Both A and b A main system bus, ram, rom/flash, and
typically a set of other devices such as a programmable interrupt controller, analog/digital
converters, any number of general purpose 10 devices A. Microcontroller B. Microprocessor
C. None of the above ASSEMBLY LANGUAGE is an assembly (or assembler) language, often
abbreviated asm, is a A. low-level programming language for a computer B. high-level
programming language for a computer A. C. both A and B
Solution
AVR was one of the first micro controller families to use on chipflash memory for program
storage
Embedded syatems are mechanical or electrical syatems
An integrated circuit that has all functions of a cpu is micro processor
Assembler language is low level programming language for a computer
A main system........... Micro processor.
More Related Content
Similar to Find the shortest route through a maze using linking and linked list.pdf
In this presentation, we will be building a Sudoku Solver solely using Functional Programming idioms in Scala. This is a great opportunity to learn the very basics of Scala, the power of its built in Vector library and how it differs from what's build in Java 8.
The presentation will be structured as follow:
1. Quick Introduction to Sudoku
2. Short introduction to Scala and the concepts required for the Solver
3. Let's get coding!
-- USING UNITY TRYING TO CREATE A CLICK TO PATH- THAT YOU CLICK ON AND.pdfganisyedtrd
// USING UNITY TRYING TO CREATE A CLICK TO PATH, THAT YOU CLICK ON AND
THE AGENT/AVATAR FOLLOWS THE BEST PATH TO GET THERE
// AT THE SAME TIME THERE IS A GUARD CHASING THE AGENT USING
AWARENESS AND PAHTFINDING.
//THIS IS THE MapManager.cs the Agent.cs I could upload it
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.UI;
// Custom struct to hold the per-tile information needed for the A* pathing search
public struct grid_cell
{
public bool visited;
public bool isBlocked;
public Vector2Int parent;
public float g, h, f;
}
public class MapManager : MonoBehaviour
{
// fixed map size for simplicity - map file must match
public const int WIDTH = 12;
public const int HEIGHT = 12;
// need to know tile size (color for debugging)
private Vector2 TILE_SIZE;
private Color TILE_COLOR;
// prefab tiles (and debugging labels)
public GameObject[] _tilePrefabs;
public GameObject _labelPrefab;
public GameObject _uiCanvas;
// A* pathfinding array and queue
private grid_cell[,] _map = new grid_cell[WIDTH, HEIGHT];
private List<KeyValuePair<float, Vector2Int>> _openList = new List<KeyValuePair<float,
Vector2Int>>();
// references to tile spriterenderers and tile labels for debugging
private SpriteRenderer[,] _tiles = new SpriteRenderer[WIDTH, HEIGHT];
private Text[,] _labels = new Text[WIDTH, HEIGHT];
// steps is a convenient way to generate the 8 children of a grid square
private Vector2Int[] _steps = new Vector2Int[8];
void Start()
{
TILE_SIZE = _tilePrefabs[0].transform.GetComponent<SpriteRenderer>()
.bounds.extents * 2;
// load map and create tiles
readMapFile();
// for debugging, store the color of an unblocked tile (for changing them back)
TILE_COLOR = _tiles[0,0].color;
// store "step" vectors for the four cardinal directions
_steps[0].x = -1; _steps[0].y = 0;
_steps[1].x = 0; _steps[1].y = -1;
_steps[2].x = 0; _steps[2].y = 1;
_steps[3].x = 1; _steps[3].y = 0;
// and the four diagonal directions
_steps[4].x = 1; _steps[4].y = 1;
_steps[5].x = 1; _steps[5].y = -1;
_steps[6].x = -1; _steps[6].y = 1;
_steps[7].x = -1; _steps[7].y = -1;
}
/*********************************************************************************************
Collision with blocked tiles (walls)
- called by agents
- returns a response vector indicating the amount to "push" the agent out of the walls
- (0,0) indicates no collisions happening
*/
public Vector2 checkBlockedCollision(Vector2 pos, Vector2 extents)
{
// convert the world position that we're checking to the coordinates of a grid cell
Vector2Int posGC = vectorToGC(pos);
// loop over the diagonal steps to check the diagonally-adjacent cells
// check those first, because a diagonal collision implies two cardinal direction collisions
for (int si=4;si<_steps.Length;si++) {
// for each diagonal neighbor
Vector2Int step = _steps[si];
Vector2Int neighbor = posGC + step;
// if it's not on the map or not blocked, then no collision possible
if (!onMap(neighbor)) continue;
if.
Java Question help needed In the program Fill the Add statements.pdfkamdinrossihoungma74
Item 8 Singly ionized (one electron removed) atoms are accelerated and then passed through a
velocity selector consisting of perpendicular electric and magnetic fields. The electric field is 158
V/m and the magnetic field is 3.13 Times 10^2 T. The ions next enter a uniform magnetic field
of magnitude 1.73 Times 10^-2 T that is oriented perpendicular to their velocity. How fast are
the ions moving when they emerge from the velocity selector? If the radius of the path of the
ions in the second magnetic field is 17.4 cm, what is their mass?
Solution
A)
In Velocity selector Electric field & Magnetic field forces on ions are equal & opposite ,this is
because it allows ions with a particular velocity only passes undeflected.
so we can say,
Bqv = Eq
B:magnetic field density
E:Electric field
v:velocity at which the ions remains undeflected.
v=E/B
v = 158V/m / 3.13*10-2 T
=> v = 4.78*103 m/s
B)
as it enteres next in uniform magnetic field of value B=1.73*10-2 T
Work done in uniform magnetic field is zero.It only changes the direction.So B provides
centripetal force for the ions while changing direction in circular path of radius r=17.4cm.
Bqv = mv²/r
m = Bqr / v = (1.73*10-2T)(1.6*10-19C)(0.174m) / (4.78*103m/s)
=>m = 1*10-25 kg.
In this chapter we are going to get familiar with recursion and its applications. Recursion represents a powerful programming technique in which a method makes a call to itself from within its own method body. By means of recursion we can solve complicated combinatorial problems, in which we can easily exhaust different combinatorial configurations, e.g. generating permutations and variations and simulating nested loops. We are going to demonstrate many examples of correct and incorrect usage of recursion and convince you how useful it can be.
Briefly explain four functions of stems. SolutionFunction of S.pdfsanuoptical
Briefly explain four functions of stems.
Solution
Function of Stems:
1. It helps store water , as in cacti, and the products of photosynthesis, as in the trunk of sago
palm (Metroxylon sagu) and sweet palm (Argenga pinnata) which store large stock of starch
2. Young green stem also performs a minor role in the production of food through the process of
photosynthesis, but in some species (e.g. cactus) the stem is the chief photosynthesizing organ
3. It supports the leaves, flowers and fruits and connect them with roots. In trees and shrubs the
main stem or trunk provides a strong columnar structure from which branches are attached
raising the leaves upward to be expressed more fully to the sun
4. The plant stem serves as a means of asexual reproduction in many species..
AVR was one of the first microcontroller families to use A. on-chip .pdfsanuoptical
AVR was one of the first microcontroller families to use A. on-chip flash memory for program
storage B. one-time programmable ROM, EPROM, or EEPROM C. both A and B
EMBEDDED SYSTEMS is a computer system with a dedicated function within a larger A.
digital and logical system B. mechanical or electrical system C. both A and B An integrated
circuit that contains all the functions of a central processing unit of a computer is A.
Microprocessor B. Microcontroller C. Both A and b A main system bus, ram, rom/flash, and
typically a set of other devices such as a programmable interrupt controller, analog/digital
converters, any number of general purpose 10 devices A. Microcontroller B. Microprocessor
C. None of the above ASSEMBLY LANGUAGE is an assembly (or assembler) language, often
abbreviated asm, is a A. low-level programming language for a computer B. high-level
programming language for a computer A. C. both A and B
Solution
AVR was one of the first micro controller families to use on chipflash memory for program
storage
Embedded syatems are mechanical or electrical syatems
An integrated circuit that has all functions of a cpu is micro processor
Assembler language is low level programming language for a computer
A main system........... Micro processor.
Complete the implementation of the binary search tree started in cla.pdfsanuoptical
Complete the implementation of the binary search tree started in class. You know you are done
when the main function runs correctly with all commented lines uncommented, and printing
shows the expected behavior of a BST.
CODE:
# TODO: implement inorder
# TODO: implement find
# TODO: implement maximum, minimum
# TODO: implement successor, predecessor
# TODO: implement delete
def main():
bst = Node(3, None)
for k in [5, 7, 4, 5, 6]:
bst.insert(k)
# print(bst.inorder())
# for k in [4, 3, 6, 2, 1, 7]:
# print(\"find {}: {}\".format(k, bst.find(k) != None))
# for k in [4,3, 2]:
# n = bst.find(k)
# if n != None:
# s = n.successor()
# print(\"successor of {}: {}\".format(k, s.key if s != None else None))
# s = n.predecessor()
# print(\"predecessor of {}: {}\".format(k, s.key if s != None else None))
# s = n.delete()
# print(\"deleted {}\".format(s.key))
# print(bst.inorder())
class Node:
def __init__(self, key, parent):
self.key = key # self is Python for \"this\"
self.parent = parent
self.left = None
self.right = None
def inorder(self):
\'\'\'returns list of the keys in an inorder traversal of the tree rooted at self\'\'\'
# TODO: replace \"pass\" keyword with actual code
# Hint: li.append(value) appends a value to list li
# Hint: li = list1 + list2 returns the concatnenation of list1 and list2
# Hint: use dot notation to call method: inorder(node) ---> node.inorder()
# To test: uncomment line 10 and click \"Run\"
li = [] # empty list
if self.left is not None:
pass
pass
if self.right is not None:
pass
return li
def insert(self, key):
\'\'\'inserts a new node with given key into subtree rooted at self node\'\'\'
if key < self.key:
if self.left is None: # None is Python for null, \"is\" = \"==\", \"is not\" = \"!=\"
self.left = Node(key, self)
else:
self.left.insert(key)
else:
if self.right is None:
self.right = Node(key, self)
else:
self.right.insert(key)
def find(self, key):
\'\'\'returns a node in the subtree rooted at self with this key or
None if no such key exists\'\'\'
# Hint: similar to insert()
# Test: uncomment lines 11 and 12, click \"Run\"
pass
def minimum(self):
\'\'\'returns the node with minimum key in the subtree rooted at self\'\'\'
pass
def maximum(self):
\'\'\'returns the node with maximum key in the is subtree rooted at self\'\'\'
pass
def successor(self):
\'\'\'returns successor of the self node or None if it does not have one\'\'\'
# TODO: fill the if statement
if self.right is not None:
pass
c, p = self, self.parent
while p is not None and c is p.right:
c, p = p, p.parent
return p
def predecessor(self):
\'\'\'returns the predecessor of the self node or None if it does not have one\'\'\'
pass
def delete(self):
\'\'\'deletes the self node from the tree and returns that node\'\'\'
parent, left, right = self.parent, self.left, self.right
# case 0: no children
if left is None and right is None:
if parent is not None:
if self is parent.left:
parent.left = None
else:
parent.right = None
return self
# case 1: one or two children, no pa.
A researcher was interested in studying Americans email habits. She .pdfsanuoptical
A researcher was interested in studying Americans email habits. She suspected that Americans
spend less than 7 hours a week answering their email.The General Social Survey in 2004
included a question that asked about the number of hours that the respondent spend on email per
week. The General Social Survey in 2002 asked 1,264 respondents this question. The sample
mean number of hours was 6.02 and the sample standard deviation was 7.80. Find the test
statistic.A. 4.47
Solution
Test Statistic
Population Mean(U)=7
Sample X(Mean)=6.02
Standard Deviation(S.D)=7.8
Number (n)=1264
we use Test Statistic (t) = x-U/(s.d/Sqrt(n))
to =6.02-7/(7.8/Sqrt(1263))
to =-4.47
ANS:B.-4.47.
A 50 mL stock sample of cells is diluted 110 six times. If 0.1 mL o.pdfsanuoptical
A 50 mL stock sample of cells is diluted 1/10 six times. If 0.1 mL of the most dilute sample
generates 75 colonies on an agar plate, calculate the original concentration of bacteria present in
the original sample?
Solution
Answer:
Given:
Dilution factor= 1/10^6
Number of colonies= 75
Volume of sample = 0.1 mL to the plate
CFU/ml = ?
cfu/ml = (no. of colonies)/ dilution factor x volume of culture plate
cfu/ml = (75)/ (1/10^6 x 0.1)
cfu/ml = 75 x 10^7.
Why are clocks (or timers) discussed in the context of IO systems.pdfsanuoptical
Why are clocks (or timers) discussed in the context of I/O systems?
Solution
1) Time operations are not standard across all systems.
2) A timer can be used to trigger operations and to measure elapsed time. It can be set to trigger
an interrupt at a specific future time, or to trigger interrupts periodically on a regular basis to take
place.
3) Provide current time, elapsed time, etc..
why the SSB receiver re-injects the missing carrier Why add the c.pdfsanuoptical
why the SSB receiver re-injects the missing carrier? Why add the carrier back in after
downshifting the incoming modulated signal instead of before
why the SSB receiver re-injects the missing carrier? Why add the carrier back in after
downshifting the incoming modulated signal instead of before
Solution
Re-injection of carrier is done by BFO,this re-injection of carrier allows easy de-modulation of
RF and even IF signal also.if injected carrier is at the wrong frequencyrelative to the station then
the audiio will become disorted..
80 µl of 10^-5 dilution of E. coli culture was plated on LB agar and.pdfsanuoptical
80 µl of 10^-5 dilution of E. coli culture was plated on LB agar and incubated at 37 degree
Celsius overnight. Next day, you observed 212 colonies on this plate. Based on this information,
calculate the viable count (cfu/mL) of the original E. coli culture.
Solution
Colony forming units (CFU)/mL (from plate C) = (no. of colonies x dilution factor) / volume of
culture plate
Number of colonies observed is = 212
Dilution factor is = 10^5
Volume of culture plate =80 µl
Colony forming units (CFU)/mL (from plate C) = 212*10^5/ 0.08 ml
= 26.50* 10^7 CFU/ml.
Which of the following statements about pyruvate is most accurate P.pdfsanuoptical
Which of the following statements about pyruvate is most accurate? Pyruvate can be produced
only from carbohydrates; Pyruvate dehydrogenase complex does not belong to the Krebs cycle.
Therefore, pyruvate dehydrogenase is not a step-controlling enzyme for the Krebs cycle;
Pyruvate can be reversibly converted to phosphoenolpyruvate by pyruvate kinase; Pyruvate is a
main precursor of oxaloacetate in the Krebs cycle; Pyruvate dehydrogenase converts pyruvate to
acetyl CoA and generates one NADH that is equivalent to 2ATP if the NADH is transferred to
mitochondria via glycerol 3-phosphate shuttle system.
Solution
Correct answer is B
Pyruvate dehydrogenase complex does not belong to Krebs Cycle.Therefore pyruvate
dehydrogenase is not a step controlling enzyme for krebs cycle.
PDH complex catalyses the conversion of Pyruvate into Acetyl CoA. Acetyl CoA then enters
Krebs cycle and forms oxaloacetate. Therefore action of PDH comples does not determine the
control of krebs cycle,..
Which CLI modes let you use the show running-config commandA. Use.pdfsanuoptical
Which CLI modes let you use the show running-config command?
A. User
B. Privileged
C. Global Configuration
D. Setup
E. All of the above
Solution
B is correct. You can run the show running-config command in Privileged (Enable) modes.
A, C, D, and E are incorrect. A, C, and D are incorrect because the show running-
configcommand is not available in these modes. E is incorrect because choices A, C, and D are
incorrect..
What is meant by star activity with respect to a restriction enz.pdfsanuoptical
What is meant by \"star activity\" with respect to a restriction enzyme.
I just need a 1-2 sentence explanation
Solution
1. Star activity is a general property of Restriction endonuclease.
2. During some non-standard reaction conitions, specific restriction enzymes are can cleave the
sequences which are similar , but not identical ,to their efined recognition seqences.
3.Such kind of soecificity has been calle \" Star activity\"..
Type III hypersensitivities are also referred to as immune complex me.pdfsanuoptical
Type III hypersensitivities are also referred to as immune complex mediated hypersensitivities.
Which cell is responsible for clearing the antibody-antigen complexes that are formed? In type I
hypersensitivity, prior sensitization to the antigen/allergen is not required because it\'s an
immediate type of reaction. True False Which cell types participate in antibody mediated
attacks of either cells or red blood cells in type II hypersensitivities?
Solution
Hypersensitive is the group of unfavourable reactions produced by the normal Immune system. It
includes allergies and Autoimmunity. Type-III immunity is immune complex mediated diseases
that include Serum sickness, Rheumatoid arthritis etc. The mediators are IgG, complement and
Neutrophills.
7. Answer is Macrophages.
8. False: Prior sensitization with allergin, leads to IgE production, then they bind to mast cells.
Again encounter wits same allergin, bind to these mast cell bound IgE. Finally leads to
degranulation and Type-1 hypersensitivity.
9. All three types of cells: Macrophages, NK cells and Neutrophils.
True, False, Uncertain with Explanation(a) Including an interacti.pdfsanuoptical
True, False, Uncertain with Explanation:
(a) Including an interaction term between two independent variables, X1 and X2, allows for the
measurement of the effect of a unit increase in X1 and X2, above and beyond the sum of the
individual effects of a unit increase in the two variables alone.
Solution
When an interaction is present, the lines in a graph of the means will not be parallel. Another
way of describing the interaction is to say that the effects of one factor are not the same at all
levels of the other factor.Also we woll say that “the simple effects are different,” because a
simple effect looks at the effects of one factor at each level of the other factor.
An interaction effect is a change in the simple main effect of one variable over levels of the
second. An A X B or A BY B interaction is a change in the simple main effect of B over levels
of A or the change in the simple main effect of A over levels of B.In either case the cell means
cannot be modeled simply by knowing the size of the main effects. An additional set of
parameters must be used to explain the differences between the cell means. These parameters are
collectively called an interaction.
If interaction is significant, determine whether interactions are important. If not, can examine
main effects
If interaction present & important, determine whether interaction is simple or complex.
. For simple interactions, can still talk about the main effects of A at each level of B
For complex interaction, must simply consider all pairs of levels as separate treatments.
If interaction effects are very small compared to main effects or only apparent in a small number
of treatments, then they are probably unimportant.
We can proceed by keeping interaction in the model, but using marginal means for each
significant main effect individually
The interaction effect is so large and/or pervasive that main effects cannot be interpreted on their
own.
This is TRUE statement..
Traits that are detrimental to the long-term survival of an individu.pdfsanuoptical
Traits that are detrimental to the long-term survival of an individual can occur in a population
(select all that apply):
a. if they arise due to a mutation.
b. Never
c. when the trait increases an individual\'s chance of reproducing.
d. because there has to be variation in the population.
e. if they enter the population through gene flow from another habitat where the traits are
favorable.
Solution
a. if they arise due to a mutation.
d. because there has to be variation in the population..
The sampling distribution of the sample mean is the probability dist.pdfsanuoptical
The sampling distribution of the sample mean is the probability distribution of all
a. the sample statistics and their probability of occurrence..
b. the normal population parameters and their probability of occurrence..
c. the possible sample means and their probability of occurrence.
d. sample means.
Solution
sample means..
The lantana has which inflorescence morphology type campanulte tub.pdfsanuoptical
The lantana has which inflorescence morphology type? campanulte tubular cruciform rotate
ligulate The rose has which inflorescence morphology type? campanulte tubular cruciform
rotate ligulate The fig is which type of fruit? Simple - Legume Simple - Drupe Simple - Berry
Multiple Aggregate
Solution
19- lantana has campanulate inflorescence
20-Rotate
21-Multiple fruit or false fruit.
The intensity of the sound of traffic at a busy intersection was mea.pdfsanuoptical
The intensity of the sound of traffic at a busy intersection was measured at 2.0 × 101 W/m2. Find
the decibel level. (Round your answer to the nearest whole number.)
Solution
Sound intensity of traffic at a busy intersection is given by I = 2×10^1 W/m².
Now,
Reference sound intensity Io = 10^12 W/m² (Threshold of hearing)
Reference sound intensity level LIo = 0 dB (Threshold of hearing level)
we need to find sound intensity level LI in dB when entering sound intensity I = 2×10^1 W/m².
Sound intensity level LI = 10×log (I / Io) dB = 10×log (2×10^1 / 10^12)=10*11.30 dB
= 113.01 dB
=113dB on round off.
The garden pea is described as self-fertilizing. What does this .pdfsanuoptical
The garden pea is described as \"self-fertilizing.\" What does this mean and why was this
significant to the success of Mendel\'s inheritance experiments?
Solution
The pea plant which Mendel chose for conducting experiments, is most ideal for controlled
breeding, since it can easily be subjected to cross pollination as well as self pollination. This
gives the success to Mendel\'s inheritance experiments.
The main other resons for mendal success are.
The equation for the time of one swing of a pendulum is given by T = .pdfsanuoptical
The equation for the time of one swing of a pendulum is given by T = 2 pi Squareroot L/32
where T is the time in seconds, pi almostequalto 3.14, & L is the length in feet. What is the
length of the pendulum if it makes one (1) swing in 4 seconds, according to the formula?
Solution
T=2*pi*(L/32)^.5
Squaring on both sides
(T/(2*pi))^2=L/32
Given time =4 sec
L/32= (4/(2pi))^2
L/32= 4/10
L=128/10
L=12.8
Length of pendulum =12.8 units
L/32=.
The assumption that arrivals follow a Poisson probability distributi.pdfsanuoptical
The assumption that arrivals follow a Poisson probability distribution is equivalent to the
assumption that the time between arrivals has
a normal probability distribution
an exponential probability distribution
a uniform probability distribution
a Poisson probability distributiona.
a normal probability distributionb.
an exponential probability distributionc.
a uniform probability distributiond.
a Poisson probability distribution
Solution
The assumption that arrivals follow a Poisson probability distribution is equivalent to the
assumption that the time between arrivals has b. an exponential probability distribution.
2024.06.01 Introducing a competency framework for languag learning materials ...Sandy Millin
http://sandymillin.wordpress.com/iateflwebinar2024
Published classroom materials form the basis of syllabuses, drive teacher professional development, and have a potentially huge influence on learners, teachers and education systems. All teachers also create their own materials, whether a few sentences on a blackboard, a highly-structured fully-realised online course, or anything in between. Despite this, the knowledge and skills needed to create effective language learning materials are rarely part of teacher training, and are mostly learnt by trial and error.
Knowledge and skills frameworks, generally called competency frameworks, for ELT teachers, trainers and managers have existed for a few years now. However, until I created one for my MA dissertation, there wasn’t one drawing together what we need to know and do to be able to effectively produce language learning materials.
This webinar will introduce you to my framework, highlighting the key competencies I identified from my research. It will also show how anybody involved in language teaching (any language, not just English!), teacher training, managing schools or developing language learning materials can benefit from using the framework.
Operation “Blue Star” is the only event in the history of Independent India where the state went into war with its own people. Even after about 40 years it is not clear if it was culmination of states anger over people of the region, a political game of power or start of dictatorial chapter in the democratic setup.
The people of Punjab felt alienated from main stream due to denial of their just demands during a long democratic struggle since independence. As it happen all over the word, it led to militant struggle with great loss of lives of military, police and civilian personnel. Killing of Indira Gandhi and massacre of innocent Sikhs in Delhi and other India cities was also associated with this movement.
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
Synthetic fiber production is a fascinating and complex field that blends chemistry, engineering, and environmental science. By understanding these aspects, students can gain a comprehensive view of synthetic fiber production, its impact on society and the environment, and the potential for future innovations. Synthetic fibers play a crucial role in modern society, impacting various aspects of daily life, industry, and the environment. ynthetic fibers are integral to modern life, offering a range of benefits from cost-effectiveness and versatility to innovative applications and performance characteristics. While they pose environmental challenges, ongoing research and development aim to create more sustainable and eco-friendly alternatives. Understanding the importance of synthetic fibers helps in appreciating their role in the economy, industry, and daily life, while also emphasizing the need for sustainable practices and innovation.
A Strategic Approach: GenAI in EducationPeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
Honest Reviews of Tim Han LMA Course Program.pptxtimhan337
Personal development courses are widely available today, with each one promising life-changing outcomes. Tim Han’s Life Mastery Achievers (LMA) Course has drawn a lot of interest. In addition to offering my frank assessment of Success Insider’s LMA Course, this piece examines the course’s effects via a variety of Tim Han LMA course reviews and Success Insider comments.
Macroeconomics- Movie Location
This will be used as part of your Personal Professional Portfolio once graded.
Objective:
Prepare a presentation or a paper using research, basic comparative analysis, data organization and application of economic information. You will make an informed assessment of an economic climate outside of the United States to accomplish an entertainment industry objective.
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdfTechSoup
In this webinar you will learn how your organization can access TechSoup's wide variety of product discount and donation programs. From hardware to software, we'll give you a tour of the tools available to help your nonprofit with productivity, collaboration, financial management, donor tracking, security, and more.
Biological screening of herbal drugs: Introduction and Need for
Phyto-Pharmacological Screening, New Strategies for evaluating
Natural Products, In vitro evaluation techniques for Antioxidants, Antimicrobial and Anticancer drugs. In vivo evaluation techniques
for Anti-inflammatory, Antiulcer, Anticancer, Wound healing, Antidiabetic, Hepatoprotective, Cardio protective, Diuretics and
Antifertility, Toxicity studies as per OECD guidelines
Acetabularia Information For Class 9 .docxvaibhavrinwa19
Acetabularia acetabulum is a single-celled green alga that in its vegetative state is morphologically differentiated into a basal rhizoid and an axially elongated stalk, which bears whorls of branching hairs. The single diploid nucleus resides in the rhizoid.
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
The French Revolution, which began in 1789, was a period of radical social and political upheaval in France. It marked the decline of absolute monarchies, the rise of secular and democratic republics, and the eventual rise of Napoleon Bonaparte. This revolutionary period is crucial in understanding the transition from feudalism to modernity in Europe.
For more information, visit-www.vavaclasses.com
Introduction to AI for Nonprofits with Tapp NetworkTechSoup
Dive into the world of AI! Experts Jon Hill and Tareq Monaur will guide you through AI's role in enhancing nonprofit websites and basic marketing strategies, making it easy to understand and apply.
Home assignment II on Spectroscopy 2024 Answers.pdf
Find the shortest route through a maze using linking and linked list.pdf
1. Find the shortest route through a maze using linking and linked lists, the strategy is based on the
concept of breadth first search. (Code for maze provided) (Previously asked before with no
response)
--------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------
--------------------------------
We are going to look at the problem of finding the shortest path through a maze. We will make
use of linking and linked lists to discover the shortest path from the entrance to the center of the
maze. The strategy we will use is based on the concept of breadth first search.
You will be provided with a GUI program that creates and draws a maze. It also provides a
method which you will use to draw the shortest path when you have discovered it. The following
illustrates the program running when it has been successfully completed.
The Maze
The maze is represented in the program by the Maze class (where you will add code to find and
draw the shortest path). It uses a 2 dimensional array of MazeCell objects to capture all the
important data about the maze itself. The MazeCell class is as follows:
class MazeCell {
// nth, sth, est, wst used to identify walls
// true indicates the wall is present
boolean nth, sth, wst, est;
// visited is used to indicate that a cell has been processed
boolean visited;
// row, col is used to facilitate finding the neighbors of a cell
int row, col;
// Constructor takes a row and column parameter for the cell
public MazeCell(int i, int j) {
row = i;
col = j;
// All walls are initially present for every cell
// The build process will remove some of the walls
nth = sth = est = wst = true;
// Initially no cells have been visited
visited = false;
}
}
2. Once the maze has been built, each cell contains its own row and column number. The walls of
the cell have been set to true or false. Any wall set to false means that there is a neighboring cell
in that direction which can be accessed. For example, if nth is set to false, then there is no wall
between this cell and its neighboring cell to the north. The orientation of the maze relative to the
GUI representation and relative to the directions is as follows:
0, n-1 North
n-1, n-1 West
East 0, 0
South n-1, 0
In the GUI representation, rows of the maze are vertical, columns are horizontal. Cell 0,0 of the
maze in drawn in the lower left corner. The following summarizes what to do to move in a
specific direction from any cell in the maze. Remember, each cell contains its own row, col
position.
North neighbor is at row, col + 1
South neighbor is at row, col – 1
East neighbor is at row + 1, col
West neighbor is at row – 1, col
The 2 dimensional array is set up with 2 additional rows and 2 additional columns to serve as a
border for the actual maze itself. The entry point to the maze is at cell 1, 1. The center of the
maze is at cell N/2, N/2.The task is to find the shortest path from the entry point to the center,
then draw that path on the GUI as pictured above.
The Search Strategy
The basic approach is to start at the center and find all the accessible cells adjacent to the center
(neighbors). Each neighbor is placed on a list. When completed, this list contains all the cells that
are one step from the center. Once all the neighbors to the center are on this list, every cell in that
list is processed the same way. A new list is created which contains all the neighbors of all the
cells on the first list. When the first list is completely processed, the second list contains all the
cells that are 2 steps away from the center. This process is repeated until the entrance is located.
As each cell is added to the second list, it is important to remember the cell that is one step closer
to the center. For instance if cell 20, 20 is the center, and it has a north neighbor at cell 20, 21
then when we add cell 20,21 to the list of neighbors, we need to remember that we reached this
neighbor coming from cell 20, 20. This information will be used to track the shortest path back
to the center when we have reached the entrance.
To facilitate the mapping the maze, we need a data structure to store a reference to a neighbor
cell and a reference to the piece of maze map information that contains a reference to the cell that
3. is one step closer to the center. The following data structure accomplishes this.
class MazeMap {
// Reference to neighboring cell
MazeCell nFromCenter = null;
// Reference to map info which contains a reference
// to the cell that is one step closer to the center
MazeMap nMinus1FromCtr = null;
The Maze class contains a method called findShortestPath that you must implement. The
following is a description of the steps needed to successfully find and display the shortest path
thru the maze.
Create two LinkedLists of MazeMap objects. One will be the list of map objects for cells at
distance x from the center. The other will be the list of map objects for cells at distance x + 1.
Initialize the list at distance x to contain a MazeMap object which refers to the center cell of the
maze. Since this map object refers to the center cell, it does not need to refer to any other
MazeMap object, so its MazeMap reference can be set to null. Set the center cell’s visited field
to true to indicate that this cell has already been added to the map.
Set up a loop to run until the maze entrance is mapped. This loop does the following:
Set up a loop to process each map object from the list at distance x. This loop does the following:
i.Get the cell from the map object
ii.If this cell is the entrance cell, set the entrance and break out of the loop!
iii.Check each direction from this cell and for an accessible neighbor cell
Get a reference to that neighbor cell
If the neighbor cell has not already been visited
Set the cell’s visited field to true so its only processed once
Create a MazeMap object that refers to this neighbor cell
Make this MazeMap object refer to the current map object being processed – ie the cell one step
closer to center
Add this MazeMap object to the list at distance x + 1
List at distance x has been processed. The list at distance x + 1 is now complete, so make the list
at distance x refer to list at distance x + 1. Then create a new empty list for the list at distance x +
1.
At this point, the entrance points at the map object which refers to cell 1,1. That map object also
refers to a map object which is one step closer to the center. Write a loop that traverses this trail
of references until it reaches the end (a null reference). For each map object:
Get the cell referred to.
Call the drawCircle method with a color, the cell’s row and column, and SMALL.
4. Call the delay method with a SHORT delay. This slows down the drawing process so you can
watch the path being displayed.
Advance to the next map object in the list.
Testing
Once you have gotten your solution to compile, run the program for a list of size 20 and observe
whether your program displays a valid path from the entrance to the center. If you have a
problem, it is very likely that you will need to make use of breakpoints to step through how your
algorithm is working, or to find where it is getting hung up.
PROVIDED CODE
public class Maze {
private int N; // dimension of maze
private MazeCell[][] maze;
private Random rand = new Random();
// Used to signal the maze has been solved
private boolean done;
// time in milliseconds (from currentTimeMillis()) when we can draw again
// used to control the frame rate
private long nextDraw = -1;
private MazeApp mf;
// Define constants for the circle size
private final double BIG = 0.375;
private final double SMALL = 0.25;
// Define constants for the delay times
private final int SHORT = 30;
private final int LONG = 500;
public Maze(MazeApp ma, int n) {
N = n;
mf = ma;
mf.setXscale(0, N + 2);
mf.setYscale(0, N + 2);
}
public void buildAndDrawMaze() {
createMaze();
buildMaze();
drawMaze();
}
5. // create the initial data structures that contain the maze data
private void createMaze() {
maze = new MazeCell[N + 2][N + 2];
for (int i = 0; i < N + 2; i++) {
for (int j = 0; j < N + 2; j++) {
maze[i][j] = new MazeCell(i, j);
}
}
// initialize border cells as already visited
for (int x = 0; x < N + 2; x++) {
maze[x][0].visited = true;
maze[x][N + 1].visited = true;
}
for (int y = 0; y < N + 2; y++) {
maze[0][y].visited = true;
maze[N + 1][y].visited = true;
}
}
// build the maze
private void buildMaze(int x, int y) {
maze[x][y].visited = true;
// while there is an unvisited neighbor
while (!maze[x][y + 1].visited || !maze[x + 1][y].visited
|| !maze[x][y - 1].visited || !maze[x - 1][y].visited) {
// pick random neighbor (could use Knuth's trick instead)
while (true) {
int r = rand.nextInt(4);
if (r == 0 && !maze[x][y + 1].visited) {
maze[x][y].nth = false;
maze[x][y + 1].sth = false;
buildMaze(x, y + 1);
break;
} else if (r == 1 && !maze[x + 1][y].visited) {
maze[x][y].est = false;
maze[x + 1][y].wst = false;
buildMaze(x + 1, y);
6. break;
} else if (r == 2 && !maze[x][y - 1].visited) {
maze[x][y].sth = false;
maze[x][y - 1].nth = false;
buildMaze(x, y - 1);
break;
} else if (r == 3 && !maze[x - 1][y].visited) {
maze[x][y].wst = false;
maze[x - 1][y].est = false;
buildMaze(x - 1, y);
break;
}
}
}
}
// build the maze starting from lower left
private void buildMaze() {
buildMaze(1, 1);
// Make sure visited is reset to false
for (int x = 1; x < N + 1; x++) {
for (int y = 1; y < N + 1; y++) {
maze[x][y].visited = false;
}
}
// delete some random walls
for (int i = 0; i < N; i++) {
int x = 1 + rand.nextInt(N - 1);
int y = 1 + rand.nextInt(N - 1);
maze[x][y].nth = maze[x][y + 1].sth = false;
}
}
// draw the initial maze
private void drawMaze() {
drawCircle(Color.RED, N / 2, N / 2, BIG);
drawCircle(Color.RED, 1, 1, BIG);
// Draw the walls in black
7. mf.setPenColor(Color.BLACK);
for (int x = 1; x <= N; x++) {
for (int y = 1; y <= N; y++) {
if (maze[x][y].sth) {
mf.line(x, y, x + 1, y);
}
if (maze[x][y].nth) {
mf.line(x, y + 1, x + 1, y + 1);
}
if (maze[x][y].wst) {
mf.line(x, y, x, y + 1);
}
if (maze[x][y].est) {
mf.line(x + 1, y, x + 1, y + 1);
}
}
}
delay(LONG);
}
private void delay(int t) {
// sleep until the next time we're allowed to draw
long millis = System.currentTimeMillis();
if (millis < nextDraw) {
try {
Thread.sleep(nextDraw - millis);
} catch (InterruptedException e) {
System.out.println("Error sleeping");
}
millis = nextDraw;
}
// when are we allowed to draw again
nextDraw = millis + t;
}
private void drawCircle(Color c, double x, double y, double size) {
mf.setFillColor(c);
mf.filledCircle(x + 0.5, y + 0.5, size);
8. }
public void findShortestPath() {
// Your code goes here!!!!!
}
}
class MazeCell {
// nth, sth, est, wst used to identify walls - true indicates wall present
boolean nth, sth, wst, est;
// used to indicate that a cell has already been processed
boolean visited;
// used to facilitate finding the neighbors of a cell
int row, col;
public MazeCell(int i, int j) {
row = i;
col = j;
// All walls are initially present for every cell
nth = sth = est = wst = true;
// Initially no cells have been visited
visited = false;
}
}
class MazeMap {
MazeCell nFromCenter = null;
MazeMap nMinus1FromCenter = null;
}
--------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------
public class MazeApp extends Application
{
// default canvas size is DEFAULT_SIZE-by-DEFAULT_SIZE
private static final int DEFAULT_SIZE = 768;
private int width = DEFAULT_SIZE;
private int height = DEFAULT_SIZE;
// The graphics context is needed to enable drawing on the canvas
private GraphicsContext gc;
9. // boundary of drawing canvas, 0% border
// private static final double BORDER = 0.05;
private static final double BORDER = 0.00;
private double xmin, ymin, xmax, ymax;
public static void main(String[] args)
{
launch(args);
}
@Override
public void start(Stage primaryStage)
{
Group root = new Group();
Canvas canvas = new Canvas(width, height);
gc = canvas.getGraphicsContext2D();
gc.setLineWidth(2);
gc.setFill(Color.WHITE);
gc.fillRect(0, 0, width, height);
root.getChildren().add(canvas);
TextInputDialog tid = new TextInputDialog();
tid.setTitle("Maze Size");
tid.setHeaderText("Enter maze size between 10 and 50");
tid.showAndWait();
int size = Integer.parseInt(tid.getResult());
if (size > 50)
size = 50;
if (size < 10)
size = 10;
primaryStage.setTitle("Maze Application");
primaryStage.setScene(new Scene(root));
primaryStage.setResizable(false);
// Make sure that the application goes away when then window is closed
primaryStage.setOnCloseRequest(e -> System.exit(0));
primaryStage.show();
10. Maze maze = new Maze(this, size);
// Must solve the maze in a separate thread or else
// the GUI wont update until the end.....
Thread solver = new Thread(
new Runnable () {
public void run()
{
while(true)
{
maze.buildAndDrawMaze();
maze.findShortestPath();
try
{
Thread.sleep(5000);
}
catch(Exception e) { }
gc.setFill(Color.WHITE);
gc.fillRect(0, 0, width, height);
}
}
});
solver.start();
}
/**
* Sets the pen color to the specified color.
*
* @param color the color to make the pen
*/
public void setPenColor(Color color) {
gc.setStroke(color);
}
/**
* Sets the pen color to the specified color.
*
* @param color the color to make the pen
11. */
public void setFillColor(Color color) {
gc.setFill(color);
}
/**
* Sets the x-scale to the specified range.
*
* @param min the minimum value of the x-scale
* @param max the maximum value of the x-scale
* @throws IllegalArgumentException if {@code (max == min)}
*/
public void setXscale(double min, double max) {
double size = max - min;
if (size == 0.0) {
throw new IllegalArgumentException("the min and max are the same");
}
xmin = min - BORDER * size;
xmax = max + BORDER * size;
}
/**
* Sets the y-scale to the specified range.
*
* @param min the minimum value of the y-scale
* @param max the maximum value of the y-scale
* @throws IllegalArgumentException if {@code (max == min)}
*/
public void setYscale(double min, double max) {
double size = max - min;
if (size == 0.0) {
throw new IllegalArgumentException("the min and max are the same");
}
ymin = min - BORDER * size;
ymax = max + BORDER * size;
}
// helper functions that scale from user coordinates to screen coordinates and back
private double scaleX(double x) {
12. return width * (x - xmin) / (xmax - xmin);
}
private double scaleY(double y) {
return height * (ymax - y) / (ymax - ymin);
}
private double factorX(double w) {
return w * width / Math.abs(xmax - xmin);
}
private double factorY(double h) {
return h * height / Math.abs(ymax - ymin);
}
private double userX(double x) {
return xmin + x * (xmax - xmin) / width;
}
private double userY(double y) {
return ymax - y * (ymax - ymin) / height;
}
/**
* Draws a line segment between (x0,
* y0) and (x1,
* y1).
*
* @param x0 the x-coordinate of one endpoint
* @param y0 the y-coordinate of one endpoint
* @param x1 the x-coordinate of the other endpoint
* @param y1 the y-coordinate of the other endpoint
*/
public void line(double x0, double y0, double x1, double y1) {
gc.strokeLine(scaleX(x0), scaleY(y0), scaleX(x1), scaleY(y1));
}
/**
* Draws one pixel at (x, y). This method is private
* because pixels depend on the display. To achieve the same effect, set the
* pen radius to 0 and call {@code point()}.
*
* @param x the x-coordinate of the pixel
13. * @param y the y-coordinate of the pixel
*/
private void pixel(double x, double y) {
gc.fillRect((int) Math.round(scaleX(x)), (int) Math.round(scaleY(y)), 1, 1);
}
/**
* Draws a filled circle of the specified radius, centered at (x,
* y).
*
* @param x the x-coordinate of the center of the circle
* @param y the y-coordinate of the center of the circle
* @param radius the radius of the circle
* @throws IllegalArgumentException if {@code radius} is negative
*/
public void filledCircle(double x, double y, double radius) {
double xs = scaleX(x);
double ys = scaleY(y);
double ws = factorX(2 * radius);
double hs = factorY(2 * radius);
if (ws <= 1 && hs <= 1) {
pixel(x, y);
} else {
gc.fillOval(xs - ws / 2, ys - hs / 2, ws, hs);
}
}
} Maze Application
Solution
public class Maze {
private int N; // dimension of maze
private MazeCell[][] maze;
private Random rand = new Random();
// Used to signal the maze has been solved
private boolean done;
// time in milliseconds (from currentTimeMillis()) when we can draw again
14. // used to control the frame rate
private long nextDraw = -1;
private MazeApp mf;
// Define constants for the circle size
private final double BIG = 0.375;
private final double SMALL = 0.25;
// Define constants for the delay times
private final int SHORT = 30;
private final int LONG = 500;
public Maze(MazeApp ma, int n) {
N = n;
mf = ma;
mf.setXscale(0, N + 2);
mf.setYscale(0, N + 2);
}
public void buildAndDrawMaze() {
createMaze();
buildMaze();
drawMaze();
}
// create the initial data structures that contain the maze data
private void createMaze() {
maze = new MazeCell[N + 2][N + 2];
for (int i = 0; i < N + 2; i++) {
for (int j = 0; j < N + 2; j++) {
maze[i][j] = new MazeCell(i, j);
}
}
// initialize border cells as already visited
for (int x = 0; x < N + 2; x++) {
maze[x][0].visited = true;
maze[x][N + 1].visited = true;
}
for (int y = 0; y < N + 2; y++) {
maze[0][y].visited = true;
maze[N + 1][y].visited = true;
15. }
}
// build the maze
private void buildMaze(int x, int y) {
maze[x][y].visited = true;
// while there is an unvisited neighbor
while (!maze[x][y + 1].visited || !maze[x + 1][y].visited
|| !maze[x][y - 1].visited || !maze[x - 1][y].visited) {
// pick random neighbor (could use Knuth's trick instead)
while (true) {
int r = rand.nextInt(4);
if (r == 0 && !maze[x][y + 1].visited) {
maze[x][y].nth = false;
maze[x][y + 1].sth = false;
buildMaze(x, y + 1);
break;
} else if (r == 1 && !maze[x + 1][y].visited) {
maze[x][y].est = false;
maze[x + 1][y].wst = false;
buildMaze(x + 1, y);
break;
} else if (r == 2 && !maze[x][y - 1].visited) {
maze[x][y].sth = false;
maze[x][y - 1].nth = false;
buildMaze(x, y - 1);
break;
} else if (r == 3 && !maze[x - 1][y].visited) {
maze[x][y].wst = false;
maze[x - 1][y].est = false;
buildMaze(x - 1, y);
break;
}
}
}
}
// build the maze starting from lower left
16. private void buildMaze() {
buildMaze(1, 1);
// Make sure visited is reset to false
for (int x = 1; x < N + 1; x++) {
for (int y = 1; y < N + 1; y++) {
maze[x][y].visited = false;
}
}
// delete some random walls
for (int i = 0; i < N; i++) {
int x = 1 + rand.nextInt(N - 1);
int y = 1 + rand.nextInt(N - 1);
maze[x][y].nth = maze[x][y + 1].sth = false;
}
}
// draw the initial maze
private void drawMaze() {
drawCircle(Color.RED, N / 2, N / 2, BIG);
drawCircle(Color.RED, 1, 1, BIG);
// Draw the walls in black
mf.setPenColor(Color.BLACK);
for (int x = 1; x <= N; x++) {
for (int y = 1; y <= N; y++) {
if (maze[x][y].sth) {
mf.line(x, y, x + 1, y);
}
if (maze[x][y].nth) {
mf.line(x, y + 1, x + 1, y + 1);
}
if (maze[x][y].wst) {
mf.line(x, y, x, y + 1);
}
if (maze[x][y].est) {
mf.line(x + 1, y, x + 1, y + 1);
}
}
17. }
delay(LONG);
}
private void delay(int t) {
// sleep until the next time we're allowed to draw
long millis = System.currentTimeMillis();
if (millis < nextDraw) {
try {
Thread.sleep(nextDraw - millis);
} catch (InterruptedException e) {
System.out.println("Error sleeping");
}
millis = nextDraw;
}
// when are we allowed to draw again
nextDraw = millis + t;
}
private void drawCircle(Color c, double x, double y, double size) {
mf.setFillColor(c);
mf.filledCircle(x + 0.5, y + 0.5, size);
}
public void findShortestPath() {
// Your code goes here!!!!!
}
}
class MazeCell {
// nth, sth, est, wst used to identify walls - true indicates wall present
boolean nth, sth, wst, est;
// used to indicate that a cell has already been processed
boolean visited;
// used to facilitate finding the neighbors of a cell
int row, col;
public MazeCell(int i, int j) {
row = i;
col = j;
18. // All walls are initially present for every cell
nth = sth = est = wst = true;
// Initially no cells have been visited
visited = false;
}
}
class MazeMap {
MazeCell nFromCenter = null;
MazeMap nMinus1FromCenter = null;
}
---------------------------------------------------------------------------------------
public class MazeApp extends Application
{
// default canvas size is DEFAULT_SIZE-by-DEFAULT_SIZE
private static final int DEFAULT_SIZE = 768;
private int width = DEFAULT_SIZE;
private int height = DEFAULT_SIZE;
// The graphics context is needed to enable drawing on the canvas
private GraphicsContext gc;
// boundary of drawing canvas, 0% border
// private static final double BORDER = 0.05;
private static final double BORDER = 0.00;
private double xmin, ymin, xmax, ymax;
public static void main(String[] args)
{
launch(args);
}
@Override
public void start(Stage primaryStage)
{
Group root = new Group();
Canvas canvas = new Canvas(width, height);
gc = canvas.getGraphicsContext2D();
gc.setLineWidth(2);
gc.setFill(Color.WHITE);
gc.fillRect(0, 0, width, height);
19. root.getChildren().add(canvas);
TextInputDialog tid = new TextInputDialog();
tid.setTitle("Maze Size");
tid.setHeaderText("Enter maze size between 10 and 50");
tid.showAndWait();
int size = Integer.parseInt(tid.getResult());
if (size > 50)
size = 50;
if (size < 10)
size = 10;
primaryStage.setTitle("Maze Application");
primaryStage.setScene(new Scene(root));
primaryStage.setResizable(false);
// Make sure that the application goes away when then window is closed
primaryStage.setOnCloseRequest(e -> System.exit(0));
primaryStage.show();
Maze maze = new Maze(this, size);
// Must solve the maze in a separate thread or else
// the GUI wont update until the end.....
Thread solver = new Thread(
new Runnable () {
public void run()
{
while(true)
{
maze.buildAndDrawMaze();
maze.findShortestPath();
try
{
Thread.sleep(5000);
}
catch(Exception e) { }
gc.setFill(Color.WHITE);
20. gc.fillRect(0, 0, width, height);
}
}
});
solver.start();
}
/**
* Sets the pen color to the specified color.
*
* @param color the color to make the pen
*/
public void setPenColor(Color color) {
gc.setStroke(color);
}
/**
* Sets the pen color to the specified color.
*
* @param color the color to make the pen
*/
public void setFillColor(Color color) {
gc.setFill(color);
}
/**
* Sets the x-scale to the specified range.
*
* @param min the minimum value of the x-scale
* @param max the maximum value of the x-scale
* @throws IllegalArgumentException if {@code (max == min)}
*/
public void setXscale(double min, double max) {
double size = max - min;
if (size == 0.0) {
throw new IllegalArgumentException("the min and max are the same");
}
xmin = min - BORDER * size;
21. xmax = max + BORDER * size;
}
/**
* Sets the y-scale to the specified range.
*
* @param min the minimum value of the y-scale
* @param max the maximum value of the y-scale
* @throws IllegalArgumentException if {@code (max == min)}
*/
public void setYscale(double min, double max) {
double size = max - min;
if (size == 0.0) {
throw new IllegalArgumentException("the min and max are the same");
}
ymin = min - BORDER * size;
ymax = max + BORDER * size;
}
// helper functions that scale from user coordinates to screen coordinates and back
private double scaleX(double x) {
return width * (x - xmin) / (xmax - xmin);
}
private double scaleY(double y) {
return height * (ymax - y) / (ymax - ymin);
}
private double factorX(double w) {
return w * width / Math.abs(xmax - xmin);
}
private double factorY(double h) {
return h * height / Math.abs(ymax - ymin);
}
private double userX(double x) {
return xmin + x * (xmax - xmin) / width;
}
private double userY(double y) {
return ymax - y * (ymax - ymin) / height;
}
22. /**
* Draws a line segment between (x0,
* y0) and (x1,
* y1).
*
* @param x0 the x-coordinate of one endpoint
* @param y0 the y-coordinate of one endpoint
* @param x1 the x-coordinate of the other endpoint
* @param y1 the y-coordinate of the other endpoint
*/
public void line(double x0, double y0, double x1, double y1) {
gc.strokeLine(scaleX(x0), scaleY(y0), scaleX(x1), scaleY(y1));
}
/**
* Draws one pixel at (x, y). This method is private
* because pixels depend on the display. To achieve the same effect, set the
* pen radius to 0 and call {@code point()}.
*
* @param x the x-coordinate of the pixel
* @param y the y-coordinate of the pixel
*/
private void pixel(double x, double y) {
gc.fillRect((int) Math.round(scaleX(x)), (int) Math.round(scaleY(y)), 1, 1);
}
/**
* Draws a filled circle of the specified radius, centered at (x,
* y).
*
* @param x the x-coordinate of the center of the circle
* @param y the y-coordinate of the center of the circle
* @param radius the radius of the circle
* @throws IllegalArgumentException if {@code radius} is negative
*/
public void filledCircle(double x, double y, double radius) {
double xs = scaleX(x);
double ys = scaleY(y);