Select Git revision
main.py 2.72 KiB
"""
COMP30024 Artificial Intelligence, Semester 1, 2021
Project Part A: Searching
This script contains the entry point to the program (the code in
`__main__.py` calls `main()`). Your solution starts here!
"""
import sys
import json
# If you want to separate your code into separate files, put them
# inside the `search` directory (like this one and `util.py`) and
# then import from them like this:
from search.util import print_board, print_slide, print_swing
def main():
try:
with open(sys.argv[1]) as file:
data = json.load(file)
except IndexError:
print("usage: python3 -m search path/to/input.json", file=sys.stderr)
sys.exit(1)
# We can put the code to read the file NOT in the try/except statement because
# if the file couldn't be read the process would end anyway
# data is a dictionary with keys "upper", "lower" and "block"
# pieces in dictionary, blocks in set, we can use if position in setblocks
dictpieces = {}
setblocks = set()
initialpiecesupper = data["upper"]
initialpieceslower = data["lower"]
initialblocks = data["block"]
# Will edit to handle duplicate pieces soon
for piece in initialpiecesupper:
dictpieces[piece[0].upper] = (piece[1],piece[2])
for piece in initialpieceslower:
dictpieces[piece[0]] = (piece[1],piece[2])
for block in initialblocks:
setblocks.add((block[1],block[2]))
# TODO:
# Find and print a solution to the board configuration described
# by `data`.
# Why not start by trying to print this configuration out using the
# `print_board` helper function? (See the `util.py` source code for
# usage information).
# Our upper pieces are R, P and S, lower pieces are r, p and s
# We will convert both to lower case letters and check each case
# Would be nice to use comparator but can't have r>s>p>r using it
# Return 1 if piecea wins, 2 if pieceb wins and 0 if neither win
def piece_collision(piecea, pieceb) -> int:
piecea = piecea.lower()
pieceb = pieceb.lower()
if piecea == "r":
if pieceb == "s":
return 1
elif pieceb == "p":
return 2
elif piecea == "s":
if pieceb == "p":
return 1
elif pieceb == "r":
return 2
elif piecea == "p":
if pieceb == "r":
return 1
elif pieceb == "s":
return 2
return 0
# We may have to edit this to strip numbers later
# We will have dictionary containing pieces
# This is so we don't have to search the entire board every time
# we need to find pieces
# Blocks can be stored in a separate list
# Other option is to have dictionary of entire board
#Sample dictionary
sample_dict = {
"R": (0, -2),
"s": (-1, 1)
}