An elementary navigation simulated in Java

19
An Elementary An Elementary Navigation Navigation Simulated in Java Simulated in Java Presented by Jinho D. Choi

Transcript of An elementary navigation simulated in Java

Page 1: An elementary navigation simulated in Java

An Elementary NavigationAn Elementary NavigationSimulated in JavaSimulated in Java

Presented by Jinho D. Choi

Page 2: An elementary navigation simulated in Java

Artificial IntelligenceArtificial Intelligence

Artificial Intelligence- A branch of computer science dealing with the simulation of intelligent behavior in computers

Artificially Intelligent Car- A car that can move safely without human driving

Simulation- An examination of a problem often not subject to direct experimentation

Page 3: An elementary navigation simulated in Java

Solving a mazeSolving a maze Maze

- A confusing intricate network of passages

Brain vs. Recursive Algorithm Base part

- Whether or not you reach the exit Recursive part

- Where to go in order to reach the exit

- Moving to an empty cell- Backtracking

Page 4: An elementary navigation simulated in Java

boolean solveMaze(var maze, var location){ if (reach the goal)

return true; else {

// moving to an empty cellif ((down-cell is empty) || (right-cell is empty) || (up-cell is empty) || (left-cell is empty)){ maze[location] = ‘X’; // mark the location

  if (down-cell is empty)

return solveMaze(maze, down-cell); else if (right-cell is empty)

return solveMaze(maze, right-cell); else if (up-cell is empty)

return solveMaze(maze, up-cell); else if (left-cell is empty)

return solveMaze(maze, left-cell);}// backtrackingelse if ((down-cell is marked) || (right-cell is marked) ||

(up-cell is marked) || (left-cell is marked)){ maze[location] = ‘#’; // block the location

  if (down-cell is marked)

return solveMaze(maze, down-cell); else if (right-cell is marked)

return solveMaze(maze, right-cell); else if (up-cell is marked)

return solveMaze(maze, up-cell); else if (left-cell is marked)

return solveMaze(maze, left-cell); else

return false; // path does not exist}

}}

Page 5: An elementary navigation simulated in Java

Solving a maze with the fixed entry and exitSolving a maze with the fixed entry and exit

‘Finding an empty cell’ vs. ‘Backtracking’ Right, Down direction vs. Left, Up direction

r, cr

r+ 1

r-1

c c+ 1c-1.***.....**.***....****.*.**.*.*.******...******.

Page 6: An elementary navigation simulated in Java

boolean solveMaze(int r, int c){ if (r == MAX-1 && c == MAX-1)

return true; // reaches the exit else if (maze[r+1][c]=='.') || (maze[r-1][c]=='.') ||

(maze[r][c+1]=='.') || (maze[r][c-1]=='.')) {

maze[r][c] = '+'; // moves to an empty cell

if (maze[r+1][c] == '.') r++;else if (maze[r][c+1] == '.') c++;else if (maze[r-1][c] == '.') r--;else if (maze[r][c-1] == '.') c--;

} else {

maze[r][c] = '-'; // backtracks

if (maze[r+1][c] == '+') r++;else if (maze[r][c+1] == '+') c++;else if (maze[r-1][c] == '+') r--;else if (maze[r][c-1] == '+') c--;else return false; // no path exists

}

return solveMaze(r, c);}

Examples 1.1

Page 7: An elementary navigation simulated in Java

Solving a maze with the unfixed entry and exitSolving a maze with the unfixed entry and exit

Unfixed Entry- Can be located at any cell before the program begins

Ordering in backtracking- Left, Up, Right, Down- Code 1.1- Example 1.2- Example 1.3

Page 8: An elementary navigation simulated in Java

Finding the best path through a mazeFinding the best path through a maze

Priority of 4 directions- right, down, up, left- Example 1.4

Permutation of 4 numbers- Code 1.2

Convert numbers to directions- (0, 1, 2, 3) to (up, down right, left)- Code 1.3

Count the steps- Code 1.4 Example 1.5

Page 9: An elementary navigation simulated in Java

Driving on a street I (A single Driving on a street I (A single car)car)

Map- A representation usually on a flat surface of the whole or a part of an area

Speed limit, stop signs, traffic signals

Page 10: An elementary navigation simulated in Java

Speed limitsSpeed limits

Cruise control Physics Problems

- Acceleration & Deceleration

- Rotational Energy

- Frictions

- Example 2.1

Page 11: An elementary navigation simulated in Java

Visiting a placeVisiting a place

Map of ‘Jinho City’- Coe, Eby, H Mart, and St. Lukes

Representations- building, null, up, right, down, and left

Database for places Code 2.1 Example 2.2

int iMap[][] = {{0, 0, 4, 1, 0, 0, 2, 0, 0},

{0, 1, 4, 1, 4, 2, 2, 1, 0},

{5, 5, 4, 5, 5, 5, 5, 5, 5},

{3, 3, 4, 3, 3, 3, 2, 3, 3},

{0, 5, 4, 0, 0, 0, 2, 1, 1},

{0, 3, 4, 0, 0, 0, 2, 5, 0},

{1, 1, 4, 0, 0, 0, 2, 3, 0},

{0, 0, 4, 2, 4, 1, 2, 0, 0},

{0, 0, 3, 3, 3, 3, 2, 1, 0}};

Page 12: An elementary navigation simulated in Java

Stop signsStop signs

Only one object- No need for stop signs

Location of stop signs Pause for ½ second Example 2.3

Page 13: An elementary navigation simulated in Java

Traffic signalsTraffic signals

Properties- Horizontal & Vertical- Take turns about 10 sec.- Sense 2 blocks before

Database for traffic signals- Code 2.2

Synchronization- Code 2.3

Example 2.4

Page 14: An elementary navigation simulated in Java

Driving on a street II (Multiple Driving on a street II (Multiple cars)cars)

A good beginning for an artificial intelligent car Less flexibility vs. more safety Convenient for humans, beneficial for society

Page 15: An elementary navigation simulated in Java

Three moving objectsThree moving objects

Object 1, Object 2, and Object 3

Database for the objects- Code 3.1

Keeps the traffic signals- Code 3.2

Example 3.1

Page 16: An elementary navigation simulated in Java

Visiting a place against 3 other objectsVisiting a place against 3 other objects

Chance for the intersections- Code 3.3

Stop signs- Check if the street is clear- Code 3.4

Example 3.2

Page 17: An elementary navigation simulated in Java

Day and night situationsDay and night situations

Turn on the headlights

Slow down

Example 3.3

Page 18: An elementary navigation simulated in Java

AppendixAppendixBlackjack Chess

4 / 4 Puzzle Elephant Spinout

Page 19: An elementary navigation simulated in Java

Thanks for coming to my Thanks for coming to my presentationpresentation

http://www.public.coe.edu/organizations/ComputerClub/