CS计算机代考程序代写 “””Wumpus World.

“””Wumpus World.

COMP3620/6320 Artificial Intelligence
The Australian National University
Authors: COMP-3620 team
Date: 2021

Student Details
—————
Student Name: Peng Wang
Student Number: u6253304
Date: 07/05/2021
“””
import argparse
import os
import sys

def process_command_line_arguments() -> argparse.Namespace:
“””Parse the command line arguments and return an object with attributes
containing the parsed arguments or their default values.
“””
import json

parser = argparse.ArgumentParser()

parser.add_argument(“-i”, “–input”, dest=”input”, metavar=”INPUT”,
type=str, help=”Input file with the Wumpus World parameters and observations (MANDATORY)”)
parser.add_argument(“-a”, “–action”, dest=”action”, metavar=”ACTION”,
type=str, choices=[“north”, “south”, “east”, “west”],
help=”Action to be tested for safety (MANDATORY)”)
parser.add_argument(“-o”, “–output”, dest=”output”, metavar=”OUTPUT”, default=’wumpus_outputs’,
help=”Output folder (default: %(default)s)”)

args = parser.parse_args()
if args.action is None:
raise SystemExit(“Error: No action was specified.”)

if args.input is None:
raise SystemExit(“Error: No input file was specified.”)

if not os.path.exists(args.input):
raise SystemExit(
“Error: Input file ‘{}’ does not exist”.format(args.input))

try:
with open(args.input) as instream:
args.domain_and_observations = json.load(instream)
except IOError:
raise SystemExit(“Error: could not open file {}”.format(args.input))

return args

def main():
# Processes the arguments passed through the command line
args = process_command_line_arguments()

# The name of the action to test
action = args.action

# The path of the directory that will contain the generated CSP files
output_path = args.output

# The description of the Wumpus World features and sequence of observations
# resulting from the agent actions.
dao = args.domain_and_observations
n_rows = dao[“rows”]
n_columns = dao[“columns”]
n_wumpuses = dao[“wumpuses”]
n_pits = dao[“pits”]
observations = dao[“observations”]

# YOUR CODE HERE

print(args.input)

outpath = str(args.input).split(“/”)
outpath = outpath[-1].split(“.”)
outpath = outpath[0]
outpatha = output_path + “/” + outpath + “_” + args.action + “_a.csp”

locs = []
x = []
for i in observations:
location = i[‘location’]
locs.append(location)
percepts = i[‘percepts’]

# Wumpus nearby
if ‘Stench’ in percepts:

loc = [location[0]+1, location[1]]
if not loc in locs and not loc in x and loc[0]>0 and loc[0]<=n_rows and loc[1]>0 and loc[1]<=n_columns: x.append(loc) loc = [location[0], location[1]+1] if not loc in locs and not loc in x and loc[0]>0 and loc[0]<=n_rows and loc[1]>0 and loc[1]<=n_columns: x.append(loc) loc = [location[0], location[1]-1] if not loc in locs and loc not in x and loc[0]>0 and loc[0]<=n_rows and loc[1]>0 and loc[1]<=n_columns: x.append(loc) loc = [location[0]-1, location[1]] if not loc in locs and loc not in x and loc[0]>0 and loc[0]<=n_rows and loc[1]>0 and loc[1]<=n_columns: x.append(loc) # write file with open(outpatha, "w+") as out_file: print(outpatha) outpathb = output_path + "/" + outpath + "_" + args.action + "_b.csp" with open(outpathb, "w+") as out_file: print(outpathb) if __name__ == '__main__': main()