Question

Using c++, use a 4x4 maze(for ex this as input: THE NUMBER OF ROOMS DOORS LISTED...

Using c++, use a 4x4 maze(for ex this as input:

THE NUMBER OF ROOMS
DOORS LISTED IN ORDER: NORTH, EAST, SOUTH, WEST FOR EACH ROOM: 0 = NO DOORS

0 = 0100
1 = 0111
2 = 0111
3 = 0001
4 = 0100
5 = 1011
6 = 1010
7 = 0010
8 = 0110
9 = 1001
10 = 1100
11 = 1001
12 = 1100
13 = 0101
14 = 0101
15 = 0001 ),

Create 3 functions,

1st function uses an adjacency linked list to represent the graph

2nd fuction Prints out vertices (room numbers) on the shortest entry-exit path.

3rd fuction Prints out all verticies (room numbers) on all possible entry-exit path.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Random;

public enum Direction {
NORTH, EAST, SOUTH, WEST;
private static Random rnd = new Random();

static public Direction randomDirection() {
return Direction.values()[rnd.nextInt(4)];
}

  
public Direction rotate90() {
return values()[(ordinal() + 1) % 4];
}

  
public Direction rotate180() {
return values()[(ordinal() + 2) % 4];
}

  
public Direction rotate270() {
return values()[(ordinal() + 3) % 4];
}

public Boolean isHorizontal() {
return this == EAST || this == WEST;
}

public Boolean isVertical() {
return this == NORTH || this == SOUTH;
}

public int dx(int steps) {
if (this == EAST) {
return steps;
}
if (this == WEST) {
return -steps;
}
return 0;
}

public int dy(int steps) {
if (this == NORTH) {
return steps;
}
if (this == SOUTH) {
return -steps;
}
return 0;
}

public int forwards_x(int n) {
if (this == EAST) {
return n + 1;
}
if (this == WEST) {
return n - 1;
}
return n;
}

public int forwards_y(int n) {
if (this == NORTH) {
return n + 1;
}
if (this == SOUTH) {
return n - 1;
}
return n;
}

public int backwards_x(int n) {
if (this == EAST) {
return n - 1;
}
if (this == WEST) {
return n + 1;
}
return n;
}

public int backwards_y(int n) {
if (this == NORTH) {
return n - 1;
}
if (this == SOUTH) {
return n + 1;
}
return n;
}

public int left_x(int n) {
if (this == NORTH) {
return n - 1;
}
if (this == SOUTH) {
return n + 1;
}
return n;
}

public int left_y(int n) {
if (this == EAST) {
return n + 1;
}
if (this == WEST) {
return n - 1;
}
return n;
}

public int right_x(int n) {
if (this == NORTH) {
return n + 1;
}
if (this == SOUTH) {
return n - 1;
}
return n;
}

public int right_y(int n) {
if (this == EAST) {
return n - 1;
}
if (this == WEST) {
return n + 1;
}
return n;
}
}

Add a comment
Know the answer?
Add Answer to:
Using c++, use a 4x4 maze(for ex this as input: THE NUMBER OF ROOMS DOORS LISTED...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • We have learned a famous shift cipher called Caesar Cipher. Now if we are given a...

    We have learned a famous shift cipher called Caesar Cipher. Now if we are given a plain test: THE ART OF WARAnd key = 3 (a shift by 3 letters), please give the ciphertext Given an 8 bit block P = 10101111 and a key K = 01101011, please give the result of bitwise XOR between P and K Please give the left 2 shift of the 8 bit text 01100101 Use the given a permutation table 23614857 to define...

  • Arduino. DEC HEX BIN(4-bits) Introducing ARDUINO 0 0 0000 1 1 0001 2 2 0010 3...

    Arduino. DEC HEX BIN(4-bits) Introducing ARDUINO 0 0 0000 1 1 0001 2 2 0010 3 3 0011 4 4 0100 5 5 0101 How many 1/0 of Port-D? How many usable 1/0 of Port-D, if Serial-Communication is in-used? What is the Arduino's pin assignment of ATMEL's PC5, PB3, & PD1*? What is the ATMEL's pin assignment of Arduino's D13*, D1, & D19? To complete the table about Number System Conversion (shown your step) 6 6 0110 7 7 0111...

  • Please show work! 2. Now, give it a try by converting the binary number 01110110 to...

    Please show work! 2. Now, give it a try by converting the binary number 01110110 to decimal by filling in the same table in step 1 r of 2 Pov 128 64 32 16 Cumulative Amount 4. Now, you give it a try by converting the decimal number 131 to binary by filling in the table Power of 2 128 32 16 Bit Amount Remaining 6. Use the binary to hexadecimal table to convert the binary number 01101111 to hexadecimal...

  • I'm working on a java program where I'm supposed to convert 4 bit binary into decimal....

    I'm working on a java program where I'm supposed to convert 4 bit binary into decimal. I went with if statements and tried to use an else to print out an error message if the user enters a number that isn't a binary number but it prints no matter what. (so, it prints that it's a vowel and that it's not a vowel) 1 import java.util.Scanner; 2 3 public class HomeworkTwoQ2 4 { 5 6 public static void main(String[] args)...

  • HW3: Problem 1: (first, study the example-1 in page-6) A computer uses 8-bit for FLP (1...

    HW3: Problem 1: (first, study the example-1 in page-6) A computer uses 8-bit for FLP (1 bit for sign, 4 bit for exponent with excess-7 rep. (see table below), rest for magnitude). Assume 0000 and 1111 in exponent field are reserved for denormalization. 6 Decimal 0 Unsigned 0000 Excess-7 Reserved used as -6 in unnormalized 1 0001 -6 2 0010 -5 3 0011 -4 4 0100 -3 5 0101 -2 0110 -1 7 0111 0 9 Decimal 8 Unsigned 1000...

  • I need little help with C language. I need to pass what I get from HexToBin(char*...

    I need little help with C language. I need to pass what I get from HexToBin(char* hexdec) into char* input so that what I got there it should pass it as string array parametr. Example: Enter IEEE-Hex: 40200000 Equivalent Binary value is : 01000000001000000000000000000000 Decimal Number: 2.5 #include <stdio.h> void HexToBin(char* hexdec) {    long int i = 0;    while (hexdec[i]) {        switch (hexdec[i]) {        case '0':            printf("0000");            break;...

  • the w 2. This problem explores the use of a one-time pad version of t In...

    the w 2. This problem explores the use of a one-time pad version of t In this scheme, the key is a stream of random numbers between 0 and example, if the key is 3 19 5..., then the first letter of plaintext is encrypted with a shift of 3 letters, the second with a shift of 19 letters, the third with a shift of 5 letters, and so on. a. Encrypt the plaintext sendmoremoney with the key stream 9...

  • The place values for the eight binary digits used in IPv4 addressing are as follows: 128,...

    The place values for the eight binary digits used in IPv4 addressing are as follows: 128, 64, 32, 16, 8, 4, 2, 1. Expand this range to include an additional four bits. Do this by recording the place values for 211, 210, 29, and 28. 1111 Express the decimal value 2001 in binary by placing 1s in the binary positions requiring the addition of the corresponding place value. Place 0s in the binary positions where the corresponding place value should...

  • bug fix of python here's the program: import binascii file = open("nibbles.txt", "r") count = 1...

    bug fix of python here's the program: import binascii file = open("nibbles.txt", "r") count = 1 bytes = "" message = "" for i, line in enumerate(file): startIndex = line.index('(') endIndex = line.index(')') co = line[startIndex:endIndex+1] # (-1.35, 2.30) coordinates = line[startIndex+1:endIndex] # -1.35, 2.30 comma = coordinates.index(',') iVoltage = coordinates[0:comma] iv = float(iVoltage) qVoltage = coordinates[comma+2:] qv = float(qVoltage)    if iv >= 0 and iv <= 2 and qv >= 0 and qv <= 2: point = "1101"...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT