def __init__(self): self.pawn1 = pawn("White", "Atlanta") self.pawn2 = pawn("Pink", "Atlanta") self.pawn3 = pawn("Grey", "Atlanta") self.pawn4 = pawn("Blue", "Atlanta") self.pawnList = [self.pawn1, self.pawn2, self.pawn3, self.pawn4] self.diseaseDeck = DiseaseDeck() self.currentPawnIndex = 0 self.board = Pandemic() self.cureDeck = CureDeck() self.colorList = ["red", "blue", "yellow", "black"] self.thingsCured = [False, False, False, False] self.oldGraveyards = [] self.epidemicTrack = [2, 2, 2, 3, 3, 4] self.epidemicCounter = 0 for count in range(3, 0, -1): for i in range(3): card = self.diseaseDeck.draw() self.board.pandemic.node[card]['cubes'] = count for i in range(2): self.pawn1.addCard(self.cureDeck.draw()) self.pawn2.addCard(self.cureDeck.draw()) self.pawn3.addCard(self.cureDeck.draw()) self.pawn4.addCard(self.cureDeck.draw()) self.cureDeck.insertEpidemics() self.board.printInfected() self.printPawnLocations()
def main(argv=None): """Command line interface for pawn. :param argv: A list containing arguments with which to invoke pawn. If None (the default) sys.argv will be used. :type argv: list :returns: None :rtype: None """ argv = sys.argv[1:] if argv is None else argv parser = argparse.ArgumentParser( prog="pawn.py", description="A programming language made from combining " "AWK, Python and awesomeness", epilog="Copyright 2016 iLoveTux - all rights reserved") parser.add_argument("script", nargs="?", default=None, help="The Pawn script to execute") parser.add_argument("files", nargs=argparse.REMAINDER, help="The input file(s) which to examine") args = parser.parse_args(argv) kwargs = { "script": args.script, "files": args.files, } pawn(**kwargs)
def test_accepts_a_script_file(self, mock_open, mock_exists, mock_isfile): mock_out = StringIO() sys.stdout = mock_out expected = test_data.read() test_data.seek(0) pawn.pawn("/tmp/script", test_data) mock_out.seek(0) results = mock_out.read() self.assertEqual(expected, results) sys.stdout = sys.__stdout__
def test_accepts_filename(self, mock_open): mock_out = StringIO() sys.stdout = mock_out script = u"{print(LINE)}" expected = test_data.read() test_data.seek(0) pawn.pawn(script, "/tmp/sample") mock_out.seek(0) results = mock_out.read() self.assertEqual(expected, results) sys.stdout = sys.__stdout__
def addPawns(self, NbrPawns): if self.color == 'white': self.pawns['K'] = pawn('white', 'King', 0, 0) for i in range(1, (NbrPawns - 1) // 3 + 1): self.pawns['P' + str(i)] = pawn('white', 'pawn', 0, 0) else: #two third of the pawns are black for i in range(1, (NbrPawns - 1) * 2 // 3 + 1): self.pawns['P' + str(i)] = pawn('black', 'Pawn', 0, 0)
def test_accepts_multiple_input_files(self, mock_open): mock_out = StringIO() sys.stdout = mock_out script = u"{print(LINE)}" expected = test_data.read() expected = expected + expected test_data.seek(0) pawn.pawn(script, [test_data, test_data_2]) mock_out.seek(0) results = mock_out.read() self.assertEqual(expected, results) sys.stdout = sys.__stdout__
def test_default_pattern(self): """The default pattern should match on every line """ mock_out = StringIO() sys.stdout = mock_out script = u"{print(LINE)}" expected = test_data.read() test_data.seek(0) pawn.pawn(script, test_data) mock_out.seek(0) results = mock_out.read() sys.stdout = sys.__stdout__ self.assertEqual(expected, results)
def __init__(self, colorChoice): self.playerColor = colorChoice self.pawnList = [] self.pawnScores = [] # These are the scores for individual pawns. for i in range(3): self.pawnList.append(pawn.pawn(colorChoice)) self.pawnScores.append(0)
def test_patterns(self): mock_out = StringIO() sys.stdout = mock_out script = u""" only{ print(LINE) } Pawn{ print("Found Pawn") } """ expected = "\n".join(("This is only a test", "Found Pawn\n")) pawn.pawn(script, test_data) mock_out.seek(0) results = mock_out.read() self.assertEqual(expected, results) sys.stdout = sys.__stdout__
def input(self): self.player_a={} self.player_b={} print("No of rows and columns") self.row=int(input()) self.col=int(input()) self.a=self.col self.b=self.col self.x = [[empty for i in range(self.row)] for j in range(self.col)] self.display() print("Player A Input") col=self.col for i in range(self.col): p=input() if(p[0]=="P"): char=pawn(col-1,i,"A"," A-"+p,self.row,self.col) self.x[col-1][i]=char self.player_a[p]=[col-1,i] elif(p[0]=="H"): char=hero1(col-1,i,"A"," A-"+p,self.row,self.col) self.x[col-1][i]=char self.player_a[p]=[col-1,i] elif(p[0]=="T"): char=hero2(col-1,i,"A"," A-"+p,self.row,self.col) self.x[col-1][i]=char self.player_a[p]=[col-1,i] self.display() print("Player B Input") for i in range(col): p=input() if(p[0]=="P"): char=pawn(0,i,"B"," B-"+p,self.row,self.col) self.x[0][i]=char self.player_b[p]=[0,i] elif(p[0]=="H"): char=hero1(0,i,"B"," B-"+p,self.row,self.col) self.x[0][i]=char self.player_b[p]=[0,i] elif(p[0]=="T"): char=hero2(0,i,"B"," B-"+p,self.row,self.col) self.x[0][i]=char self.player_b[p]=[0,i] self.display()
def test_BEGIN(self): mock_out = StringIO() sys.stdout = mock_out script = u""" BEGIN{ print("BEGIN") } only{ print(LINE) } """ expected = "\n".join(( "BEGIN", "This is only a test\n", )) pawn.pawn(script, test_data) mock_out.seek(0) results = mock_out.read() self.assertEqual(expected, results) sys.stdout = sys.__stdout__
def input(self, row, col, inp, board, player): if (inp[0] == "P"): p = pawn(row, col, player + inp, player) board.pos(row, col, p, player) elif (inp[0] == "H"): p = hero2(row, col, player + inp, player) board.pos(row, col, p, player) elif (inp[0] == "T"): p = hero1(row, col, player + inp, player) board.pos(row, col, p, player) board.display()
def __init__(self): self.chessboard = { "a1" : rook("white", "a1"), "a2" : pawn("white", "a2"), "a7" : pawn("black", "a7"), "a8" : rook("black", "a8"), "b1" : knight("white", "b1"),"b2" : pawn("white", "b2"), "b7" : pawn("black", "b7"), "b8" : knight("black", "b8"), "c1" : bishop("white", "c1"),"c2" : pawn("white", "c2"), "c7" : pawn("black", "c7"), "c8" : bishop("black", "c8"), "d1" : queen("white", "d1"), "d2" : pawn("white", "d2"), "d7" : pawn("black", "d7"), "d8" : queen("black", "d8"), "e1" : king("white", "e1"), "e2" : pawn("white", "e2"), "e7" : pawn("black", "e7"), "e8" : king("black", "e8"), "f1" : bishop("white", "f1"),"f2" : pawn("white", "f2"), "f7" : pawn("black", "f7"), "f8" : bishop("black", "f8"), "g1" : knight("white", "g1"),"g2" : pawn("white", "g2"), "g7" : pawn("black", "g7"), "g8" : knight("black", "g8"), "h1" : rook("white", "h1"), "h2" : pawn("white", "h2"), "h7" : pawn("black", "h7"), "h8" : rook("black", "h8"), }
def __init__(self): pos = 0 col = pos % 8 row = pos // 8 reso = col % 2 count = 1 board = np.zeros([8, 8], dtype=int) posBoard = np.zeros([8, 8], dtype=int) self.board = board self.posBoard = posBoard pawns = [] self.pawns = pawns finish = False while finish == False: if row < 3: col = pos % 8 row = pos // 8 reso = col % 2 if (row == 0) | (row == 2): if col == 8 - 1: self.posBoard[row][col] = pos pos += 1 elif reso == 0: self.board[row][col] = count pawns.insert( count, pawn(0, pos, self.board, count, self.posBoard)) self.posBoard[row][col] = pos pos += 1 count += 1 else: self.posBoard[row][col] = pos pos += 1 elif row == 1: if reso == 1: self.board[row][col] = count pawns.insert( count, pawn(0, pos, self.board, count, self.posBoard)) self.posBoard[row][col] = pos pos += 1 count += 1 else: self.posBoard[row][col] = pos pos += 1 elif (row == 3) | (row == 4): self.posBoard[row][col] = pos pos += 1 col = pos % 8 row = pos // 8 elif row > 4 & row < 8: col = pos % 8 row = pos // 8 reso = col % 2 if (row == 5) | (row == 7): if (col == 8 - 1) & (row == 5): self.board[row][col] = count pawns.insert( count, pawn(1, pos, self.board, count, self.posBoard)) self.posBoard[row][col] = pos pos += 1 count += 1 elif (col == 8 - 1) & (row == 7): self.board[row][col] = count pawns.insert( count, pawn(1, pos, self.board, count, self.posBoard)) self.posBoard[row][col] = pos pos += 1 count += 1 finish = True elif reso == 1: self.board[row][col] = count pawns.insert( count, pawn(1, pos, self.board, count, self.posBoard)) self.posBoard[row][col] = pos pos += 1 count += 1 else: self.posBoard[row][col] = pos pos += 1 elif (row == 6): if col == 8 - 1: self.posBoard[row][col] = pos pos += 1 elif reso == 0: self.board[row][col] = count pawns.insert( count, pawn(1, pos, self.board, count, self.posBoard)) self.posBoard[row][col] = pos pos += 1 count += 1 else: self.posBoard[row][col] = pos pos += 1