示例#1
0
def process_file(filename):
    parser = InputParser()
    parser.parse("in/" + filename + ".in")
    manager = CacheManager()
    manager.videos = parser.getVideos()
    manager.caches = parser.getCaches()
    manager.endpoints = parser.getEndPoints()
    manager.requests = parser.getRequests()
    manager.FillCaches()

    outputstring = manager.OutputString()
    outputfile = open("out/" + filename + ".out", 'w')
    outputfile.write(outputstring)
示例#2
0
def startGame(board, playerSide, ai):
    parser = InputParser(board, playerSide)
    while True:
        print()
        print(board)
        print()
        if board.isCheckmate():
            if board.currentSide == playerSide:
                print("Checkmate, you lost")
            else:
                print("Checkmate! You won!")
            return

        if board.isStalemate():
            if board.currentSide == playerSide:
                print("Stalemate")
            else:
                print("Stalemate")
            return

        if board.currentSide == playerSide:
            # printPointAdvantage(board)
            move = None
            command = input("It's your move." " Type '?' for options. ? ")
            if command.lower() == 'u':
                undoLastTwoMoves(board)
                continue
            elif command.lower() == '?':
                printCommandOptions()
                continue
            elif command.lower() == 'l':
                printAllLegalMoves(board, parser)
                continue
            elif command.lower() == 'r':
                move = getRandomMove(board, parser)
            elif command.lower() == 'exit' or command.lower() == 'quit':
                return
            try:
                move = parser.parse(command)
            except ValueError as error:
                print("%s" % error)
                continue
            makeMove(move, board)

        else:
            print("AI thinking...")
            move = ai.getBestMove()

            print(move)
            # TODO we have done check cordinate system returns

            # printAllLegalMoves(board, InputParser(board, False))

            # TODO we will hack to different notation
            move.notation = parser.notationForMove(move)
            print("Ai says", move.notation)
            makeMove(move, board)
            moveMotor(move)
示例#3
0
def process_file(filename):
    parser = InputParser()
    ridelist, bonus, simsteps, num_rows, num_cols, cars = parser.parse(
        "../input/" + filename + ".in")

    cmd = CommandCenter(ridelist, simsteps, cars, bonus)

    cmd.planCars()

    output = cmd.getOutput()
    outputfile = open("../output/" + filename + ".out", 'w')
    outputfile.write(output)
示例#4
0
def startGame(board, playerSide, ai):
    parser = InputParser(board, playerSide)
    while True:
        print()
        print(board)
        print()
        if board.isCheckmate():
            if board.currentSide == playerSide:
                print("Checkmate, you lost")
            else:
                print("Checkmate! You won!")
            return

        if board.isStalemate():
            if board.currentSide == playerSide:
                print("Stalemate")
            else:
                print("Stalemate")
            return

        if board.currentSide == playerSide:
            # printPointAdvantage(board)
            move = None
            command = input("It's your move."
                            " Type '?' for options. ? ")
            if command.lower() == 'u':
                undoLastTwoMoves(board)
                continue
            elif command.lower() == '?':
                printCommandOptions()
                continue
            elif command.lower() == 'l':
                printAllLegalMoves(board, parser)
                continue
            elif command.lower() == 'r':
                move = getRandomMove(board, parser)
            elif command.lower() == 'exit' or command.lower() == 'quit':
                return
            try:
                move = parser.parse(command)
            except ValueError as error:
                print("%s" % error)
                continue
            makeMove(move, board)

        else:
            print("AI thinking...")
            move = ai.getBestMove()
            move.notation = parser.notationForMove(move)
            makeMove(move, board)
示例#5
0
from InputParser import InputParser

if __name__ == "__main__":
    parser = InputParser()
    parser.parse("Inputfiles/small.in")
示例#6
0
import sys
from InputParser import InputParser

flag = True
command = ''

ip = InputParser('CenturyClub')

while(flag):
	sys.stdout.write('>>>')
	command = raw_input()
	if(command == 'exit'):
		flag = False
	else:
		print ip.parse(command.split(" "))
示例#7
0
def startGame(board, playerSide, ai):
    parser = InputParser(board, playerSide)
    previous_count = 0
    count = 0
    while True:
        if len(open(op_input).readlines()) == 0:
            break
        else:
            print("Please Clear the op_input.txt first!")
    while True:

        if board.isCheckmate():
            if board.currentSide == playerSide:
                print("--------------------")
                print("AI: Today is a beautiful day!")
                print("--------------------")
            else:
                print("--------------------")
                print("AI: NOOOOOOOOOOOOOOOOOOOOOOOOOO!")
                print("--------------------")
            return

        if board.isStalemate():
            if board.currentSide == playerSide:
                print("--------------------")
                print("AI: Live together? See you next time")
                print("--------------------")
            else:
                print("--------------------")
                print("AI: Live together? See you next time")
                print("--------------------")
            return

        if board.currentSide == playerSide:
            # printPointAdvantage(board)
            move = None
            command = input("It's your move." " Type '?' for options. ? ")
            if command.lower() == 'u':
                undoLastTwoMoves(board)
                continue
            elif command.lower() == '?':
                printCommandOptions()
                continue
            elif command.lower() == 'l':
                printAllLegalMoves(board, parser)
                continue
            elif command.lower() == 'r':
                move = getRandomMove(board, parser)
            elif command.lower() == 'exit' or command.lower() == 'quit':
                return
            try:
                move = parser.parse(command)
                print("move: ", command)
            except ValueError as error:
                print("%s" % error)
                continue
            move = getRandomMove(board, parser)

            while True:
                previous_count = count
                count = len(open(op_input).readlines())
                if count - previous_count > 0:
                    with open(op_input) as f:
                        read_data = f.read().splitlines()
                        op_latest_input = read_data[-1]
                        print("--------------------")
                        print("BELOW IS YOUR MOVE")
                        print("--------------------")
                        move = parser.parse(op_latest_input)
                        f.closed
                    break
            makeMove(move, board)

        else:
            print("--------------------")
            print("AI: I will beat you!")
            print("--------------------")
            move = ai.getBestMove()
            move.notation = parser.notationForMove(move)
            makeMove(move, board)

            with open(AI_output, 'a+') as f:
                f.write(move.notation + '\n')
                f.closed
            # move = getRandomMove(board, parser)
        print(board)
示例#8
0
def main(args):
    parser = InputParser(args)  # (args.algoname, args.outfile) are required
    params = parser.parse(args.infile)
    algo_creator = Algorithm()
    algo = algo_creator.create(params)
    print (algo.run())