Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

EECS 281: Project 1 - Puzzle Solver

Due Tuesday September 19, 2023 at 11:59 PM

Overview

EECS281GamesM is developing a puzzle game that they want to bring to the market. They've

already built the engine and designed thousands of maze levels, but they realized that they're

not sure how to solve many of them! What's worse, they think some of them may be unsolvable!

You are tasked with developing a C++ program that will take as input a level map to try and

solve, and some command line options indicating how your program will behave. Your solution    will read the map and confirm that the input is valid, then attempt to solve the puzzle. Finally, it   will output information about the puzzle's solvability and a description of the puzzle's solution (if one exists).

Learning Objectives

These are the skills and concepts encountered in this project:

2D/3D Maze: read, store, access, and write

· Breadth first search (BFS w/ queue)

· Depth first search (DFS w/ stack)

· Map  and  coordinate  list  mode  output

· Create custom data structures for efficient storage and access

·  Use  getopt long()  to  handle  command  line  inputs

· Use  std::cin  and  std::cout  to   handle   input  and  output

· Use  std::cerr  to  handle  error  messages

Use  std::vector<>  to  store  and  access  data

Use std::deque<> to store and access data

Command Line Input

Your solution will run from the command line, in the spirit of the Unix tradition. This includes using  command  line  options  and  redirection  of standard  input  (cin).

Modifying Behavior

Programs often offer options that can change how they work at runtime. These are specified at     the command line in the form of either "short options", which are a single character following a    single hyphen (eg.-o)or"long options", which use full words following a double hyphen (eg.-  -a-long-option ). Multiple short options can be combined (eg.-al is equivalent to -a -1). Both short and long options can also accept arguments, which allow a custom value to be associated    with an option. Each option can independently prohibit, require, or optionally accept arguments.

Q: Why both short and long options?

A¹:There are only 52 different single letter options, but an infinite number of long options can be created.

A2: Two programs can implement the same functionality using different options (eg.-R or -r for --recursive ), but full words are more easily remembered.

A3: Short options are quick and easy to type at the command line, and when programs are used in scripts, long options make scripts more readable.

The solution to this problem must accept both short and long options. Some options will be implemented with no arguments, and others will be implemented with required arguments.

Clarification: An option with a required argument is still optional and might not be specified at the command line, but if it is specified, an argument must be provided.

The complicated task of parsing options and arguments is made easier with a classic library

 that provides both getopt() for handling short options only, and getopt long()   for handling short and long options. A helpful reference can be found at the getopt  man page.

Puzzle Options

Your program, puzzle , should accept the following command line options:

--help/-h

This option prohibits arguments and causes the program to print a helpful message of your own design, and then return 0 to exit.

--queue/-q

This option prohibits arguments and directs the program to use a search container that behaves like a queue, performing a breadth first search (exactly one of stack or queue must be specified, exactly once)

--stack/-s

This option prohibits arguments and directs the program to use a search container that

behaves like a stack, performing a depth first search (exactly one of stack or queue must be specified, exactly once)

●  --output       {TYPE}/-0       {TYPE}

This option requires an argument,{TYPE}, that must be either map or list ,and directs the program to print solution output in the specified format (see Output )

If the --output flag isn't provided to your program, then your program should act as though -- output map was provided.

You are only required to error check a subset of the command line inputs (see Errors You Must Check For), but you might find it helpful during testing to account for all of the possible cases and print a descriptive error message (e.g. if the filename is not provided, or the file cannot be opened).

A The autograder uses a mix of short and long options in different orders. Do not rely on

any option being in any fixed location in argv[], and make sure that your solution can handle both long and short options equivalently.

Legal Command Line Examples

$./puzzle  --queue  -o  map  < spec-simple.txt >  output.txt

$ ./puzzle  -o  map  -q< spec-simple.txt >  output.txt

$./puzzle  -qo  map  < spec-simple.txt >  output.txt

$./puzzle  -q  --output  map  < spec-simple.txt >  output.txt

$./puzzle   -q< spec-simple.txt >   output.txt

Run the program using a search container that behaves like a queue to perform a breadth-first   search and output the results in map format; Input is redirected to cin from spec-simple.txt, and  output  is  redirected  from  cout  to  output.txt.

$./puzzle   -so   list   < spec-simple.txt

$./puzzle   --stack   --output   list   < spec-simple.txt

$./puzzle    --output    list    --stack< spec-simple.txt

Run the program using a search container that behaves like a stack to perform a depth-first

search and output the results in list format; Input is redirected to cin from spec-simple.txt, and output is printed to the screen ( cout ).

$./puzzle     --help

$./puzzle    -h

Prints a helpful message and exits.

When redirecting output to a file, you can use diff to compare the output to a file

containing the expected output. For example, if you have a file solution.txt containing the

expected output, you can run the following command to compare the output of your

program to the expected output:

1 $ ·/puzzle --queue -o map < spec-simple.txt > output.txt

2 $ diff solution.txt output.txt

Illegal Command Line Examples

$./puzzle  --stack  --queue  < spec-simple.txt

Both stack and queue modes specified.

$./puzzle  -o  map  -o  list< spec-simple.txt

Both map and list output modes specified.

$./puzzle  -o  < spec-simple.txt

No argument provided to the output mode option.

Input

A puzzle is a maze presented as a two dimensional map that is received through standard input. Your program will not open or read any files. When testing your program from the command   line on CAEN, MacOS terminal, or WSL terminal, you can use a feature of your shell called input  redirection using <, which converts to contents of a file to fill standard input that can be read in the program by using cin.

./puzzle < some-input-file.txt

Input redirection can also be used from within your IDE, but is accomplished differently for each environment. Get help on Project O and Lab 1, check https://eecs280.org, or visit other online     resources to get redirection working with your IDE of choice.

Each valid map will use a 2D coordinate system with at least one row and one column, include a starting location and a target, and composes a predefined set of characters.

Valid Characters

The map characters and what they represent:

· @:the starting location (valid maps will have exactly one)

· ?:the target (valid maps will have exactly one)

· .:an empty floor space

#:a wall that blocks player movement

A,B,.,  z:a  colored  door  that  blocks  player  movement  when  closed

● a,b,., z:a colored button that closes all doors of all other colors, and opens all doors of the matching color

^:a trapped button that closes all doors of all colors

Doors and Buttons

Each map has a fixed number of available colors, 0≤N≤26, for doors and buttons that is

included in the file. The first N letters of the English alphabet are used to represent the colors of doors and buttons. There may be zero or more buttons (lower case letters) of each color, and

zero or more doors (upper case letters) of each color, and there may be zero or more trapped buttons(^).

Buttons (both trapped and colored) can be active or inactive. When a button is inactive your solution should treat it as open floor. Colored buttons begin each game active and trapped buttons begin each game inactive.

Players of the game are unable to view button colors, so your solution must always press any

active button you encounter. Pressing any button will close all open doors in the puzzle, then if it