def test_diag_LU(self): self.assertEquals(Pos(algebra_to_cartesian("a1")).diag("LU", 5), []) self.assertEquals(Pos(algebra_to_cartesian("a8")).diag("LU", 5), []) print(Pos(algebra_to_cartesian("h8")).diag("LU", 5)) self.assertEquals(Pos(algebra_to_cartesian("h8")).diag("LU", 5), [])
def read_file(filename): map = None with open(filename) as f: lines = f.readlines() first_line = True counter = 0 for line in lines: elements = line.split(" ") int_elements = [int(el) for el in elements] if first_line: first_line = False map = Map(int_elements[0], int_elements[1], int_elements[2], int_elements[3], int_elements[4], int_elements[5]) else: trip = Trip(counter, Pos(int_elements[0], int_elements[1]), Pos(int_elements[2], int_elements[3]), int_elements[4], int_elements[5]) map.add_trip(trip) counter += 1 return map
def test_Rook1(self): board = Board() Board.populate_board(board) b = Rook("ddd", Pos("h1"), board) self.assertEqual(b.move_piece(Pos("h5")), True) self.assertRaises(Exception, b.move_piece, Pos("a3"))
def draw_walls(self, canvas: Canvas) -> None: head = self.snake.head for x in range(-1, WIDTH + 1): Pos(x, -1).draw(canvas, head, 'white') Pos(x, HEIGHT).draw(canvas, head, 'white') for y in range(-1, HEIGHT + 1): Pos(-1, y).draw(canvas, head, 'white') Pos(WIDTH, y).draw(canvas, head, 'white')
def test_Queen(self): board = Board() Board.populate_board(board) b = Queen("ddd", Pos("f1"), board) self.assertEqual(b.move_piece(Pos("h1")), True) b = Queen("ddd", Pos("f1"), board) self.assertRaises(InvalidMoveException, b.move_piece, Pos("h2"))
def test_knight_hops(self): self.assertEquals( Pos(algebra_to_cartesian("b1")).knight_hops("RU"), [[2, 5]]) print("8888", Pos(algebra_to_cartesian("b1")).knight_hops("RD")) print("8888", Pos(algebra_to_cartesian("b1")).knight_hops("RU")) print("8888", Pos(algebra_to_cartesian("b1")).knight_hops("LU")) print("8888", Pos(algebra_to_cartesian("b1")).knight_hops("LD"))
def test_knight(self): board = Board() Board.populateBoard(board) b = Knight("ddd", Pos("b1"), board) board.update(b) print("####################################") print(b.move_piece(Pos("d2")))
def setMovement(self, duration, dir): dir = Pos(dir) new_x = self.pos[0] // 16 + dir[0] new_y = self.pos[1] // 16 + dir[1] if self.currentMap.bounds.checkBounds( new_x, new_y, dir) and self.npcmanager.checkBounds( Pos(new_x, new_y)): self.remainingDuration = duration self.displacement = dir * 16 // duration self.moving = True
def __init__(self, currentMap, npcmanager): self.pos = Pos(0, 0) self.texturemap = get_texture("player-kaori") self.textures = { 'downidle': (0, 0), 'down1': (32, 0), 'down2': (64, 0), 'upidle': (0, 32), 'up1': (32, 32), 'up2': (64, 32), 'rightidle': (0, 64), 'right1': (32, 64), 'right2': (64, 64), 'leftidle': (0, 96), 'left1': (32, 96), 'left2': (64, 96), 'run_down1': (96, 0), 'run_down2': (128, 0), 'run_down3': (160, 0), 'run_up1': (96, 32), 'run_up2': (128, 32), 'run_up3': (160, 32), 'run_right1': (96, 64), 'run_right2': (128, 64), 'run_right3': (160, 64), 'run_left1': (96, 96), 'run_left2': (128, 96), 'run_left3': (160, 96), } self.animations = { 'idle_north': ['upidle'], 'idle_east': ['rightidle'], 'idle_south': ['downidle'], 'idle_west': ['leftidle'], 'walk_north': ['up2', 'upidle', 'up1', 'upidle'], 'walk_east': ['right2', 'rightidle', 'right1', 'rightidle'], 'walk_south': ['down2', 'downidle', 'down1', 'downidle'], 'walk_west': ['left2', 'leftidle', 'left1', 'leftidle'], 'run_north': ['run_up2', 'run_up1', 'run_up3', 'run_up1'], 'run_east': ['run_right2', 'run_right1', 'run_right3', 'run_right1'], 'run_south': ['run_down2', 'run_down1', 'run_down3', 'run_down1'], 'run_west': ['run_left2', 'run_left1', 'run_left3', 'run_left1'], } self.currentStance = 'downidle' self.setAnimation('idle_south', 1) self.displacement = Pos(0, 0) self.remainingDuration = 0 self.currentMap = currentMap self.npcmanager = npcmanager self.trainerdata = pkm.Trainer('Player') self.trainerdata.party.append(pkm.Pokemon('Charmander')) self.trainerdata.party[0].setlevel(4) self.moving = False self.direction = 'south'
def next_pos(self, direction: Direction) -> Pos: """ Find and return next position in the given direction. This function does NOT check for the validity of the move. :param direction: Direction of the move (left, right, up, down) :return: Brick's next position/orientation in the given direction. """ # nextpos based on current position params. nextpos = Pos(self.pos.x, self.pos.y, self.pos.orientation) # Update nextpos position object params based on current orientation and the direction of next move. # In a Pos object: # x value always points to the left block for horizontal lying brick. # y value always points to the upper block for vertical lying brick. if self.pos.orientation is Orientation.STANDING: if direction is Direction.UP: nextpos.y -= 2 nextpos.orientation = Orientation.VERTICAL_LYING if direction is Direction.DOWN: nextpos.y += 1 nextpos.orientation = Orientation.VERTICAL_LYING if direction is Direction.LEFT: nextpos.x -= 2 nextpos.orientation = Orientation.HORIZONTAL_LYING if direction is Direction.RIGHT: nextpos.x += 1 nextpos.orientation = Orientation.HORIZONTAL_LYING elif self.pos.orientation is Orientation.HORIZONTAL_LYING: if direction is Direction.UP: nextpos.y -= 1 if direction is Direction.DOWN: nextpos.y += 1 if direction is Direction.LEFT: nextpos.x -= 1 nextpos.orientation = Orientation.STANDING if direction is Direction.RIGHT: nextpos.x += 2 nextpos.orientation = Orientation.STANDING elif self.pos.orientation is Orientation.VERTICAL_LYING: if direction is Direction.UP: nextpos.y -= 1 nextpos.orientation = Orientation.STANDING if direction is Direction.DOWN: nextpos.y += 2 nextpos.orientation = Orientation.STANDING if direction is Direction.LEFT: nextpos.x -= 1 if direction is Direction.RIGHT: nextpos.x += 1 return nextpos
def crush(self, p0, p1): if type(p1) == Vel: p1 = p0 + p1 pld = Pos(self.left, self.bot) prd = Pos(self.left + self.width, self.bot) plu = Pos(self.left, self.bot + self.height) pru = Pos(self.left + self.width, self.bot + self.height) return (self.crush_hline(pld, prd, p0, p1) or self.crush_hline(plu, pru, p0, p1) or self.crush_vline(pld, plu, p0, p1) or self.crush_vline(prd, pru, p0, p1))
def test_diag_LU(self): self.assertEquals(Pos(algebra_to_cartesian("a1")).diag("LU", 5), []) self.assertEquals(Pos(algebra_to_cartesian("a8")).diag("LU", 5), []) """self.assertEquals( Pos(algebra_to_cartesian("h1")).diag("LU", 5), [[6, 6], [5, 5], [4, 4], [3, 3], [2, 2]], ) """ print(Pos(algebra_to_cartesian("h8")).diag("LU", 5)) self.assertEquals(Pos(algebra_to_cartesian("h8")).diag("LU", 5), [])
def test_board(self): board = Board() board.populateBoard() p = Knight("ddd", Pos("b8"), board) board.update(p, Pos("a4")) # bypasses the move piece allows illegal moves board.printBoardOnScreen() obj, objname = board.piece_from_algebraic_coord("a4") self.assertIsInstance(obj, Knight) print(obj)
def test_diag_RU(self): self.assertEquals( Pos(algebra_to_cartesian("a1")).diag("RU", 5), [[1, 6], [2, 5], [3, 4], [4, 3], [5, 2]], ) self.assertEquals(Pos(algebra_to_cartesian("a8")).diag("RU", 5), []) self.assertEquals(Pos(algebra_to_cartesian("h1")).diag("RU", 5), []) self.assertEquals(Pos(algebra_to_cartesian("h8")).diag("RU", 5), [])
def observe(self, buffer_slice: np.ndarray) -> None: for cell in self.snake.body: self.set_pixel(buffer_slice, cell, CHANNEL_OBSTACLE) for apple in self.apples: self.set_pixel(buffer_slice, apple, CHANNEL_APPLE) for x in range(-1, WIDTH + 1): self.set_pixel(buffer_slice, Pos(x, -1), CHANNEL_OBSTACLE) self.set_pixel(buffer_slice, Pos(x, HEIGHT), CHANNEL_OBSTACLE) for y in range(-1, HEIGHT + 1): self.set_pixel(buffer_slice, Pos(-1, y), CHANNEL_OBSTACLE) self.set_pixel(buffer_slice, Pos(WIDTH, y), CHANNEL_OBSTACLE)
def checkTriggers(self, playerState: Player): pX, pY = playerState.getPos() for configMonster in self.config: tX, tY = [int(i) for i in configMonster["trigger"].split()] if (pX == tX and pY == tY and not configMonster["spawned"]): configMonster["spawned"] = True mX, mY = [int(i) for i in configMonster["location"].split()] if configMonster["type"] == "Slime": self.monsters.append( Slime(Pos(mX, mY), configMonster["level"])) elif configMonster["type"] == "DemonKing": self.monsters.append(DemonKing(Pos(mX, mY)))
def test_Knight1(self): board = Board() Board.populateBoard(board) b = Knight("ddd", Pos("b1"), board) board.update(b) self.assertEqual(b.move_piece(Pos("a2")), False) b = Knight("ddd", Pos("b1"), board) board.update(b) self.assertEqual(b.move_piece(Pos("a3")), True)
def __init__(self, size, pos=Pos(0, 0), border=0, spacing=0, orientation=orientation.VERTICAL, scaling=styles.FREE): super(ListLayout, self).__init__(size, pos, border) self.next_child_origin = Pos(self.origin.x + self.pos.x + self.border, self.origin.y + self.pos.y + self.border) self.orientation = orientation self.spacing = spacing self.scaling = scaling
def test_Bishop1(self): board = Board() Board.populateBoard(board) b = Bishop("ddd", Pos("c5"), board) board.update(b) self.assertEqual(b.move_piece(Pos("h3")), False) b = Bishop("ddd", Pos("c5"), board) board.update(b) self.assertEqual(b.move_piece(Pos("d4")), True)
def test_knight_hops(self): # knight_pos = Pos(algebra_to_cartesian("b1")) # self.assertEquals((knight_pos).knight_hops("RU"), []) self.assertEquals( Pos(algebra_to_cartesian("b1")).knight_hops("RU"), [[2, 5]]) # self.assertEquals(knight_pos).knight_hops("RD", [121]) # self.assertEquals(knight_pos).knight_hops("LU", [1]) # self.assertEquals(knight_pos).knight_hops("LD", [1]) # print(knight_pos.knight_hops()) print("8888", Pos(algebra_to_cartesian("b1")).knight_hops("RD")) print("8888", Pos(algebra_to_cartesian("b1")).knight_hops("RU")) print("8888", Pos(algebra_to_cartesian("b1")).knight_hops("LU")) print("8888", Pos(algebra_to_cartesian("b1")).knight_hops("LD"))
def test_pos_slide_withboard(self): pos = Pos("a3") print(pos.slide("U", 3)) board = Board() board.populateBoard() pos = Pos("a1") print(pos.slide("U", 2, board)) pos = Pos("h1") print(pos.slide("U", 2, board))
def test_Bishop1(self): board = Board() Board.populate_board(board) # b = Bishop("ddd", Pos("b8"), board) # self.assertEqual(b.move_piece(Pos("a7")), True) b = Bishop("ddd", Pos("c5"), board) board.update(b) # self.assertRaises(InvalidMoveException, b.move_piece, Pos("h3")) self.assertEqual(b.move_piece(Pos("h3")), False) b = Bishop("ddd", Pos("c5"), board) board.update(b) self.assertEqual(b.move_piece(Pos("d4")), True)
def move(color): valid_move = False while not valid_move: print("%s moves now: " % color.upper()) curr_algebraic_coord = input("Enter the current piece location >") next_algebraic_coord = input("Enter the goto location >") if curr_algebraic_coord == "end" or next_algebraic_coord == "end": break pieceObj, _ = board.piece_from_algebraic_coord(curr_algebraic_coord) if pieceObj: # there is a piece there if pieceObj.color == color: valid_move = pieceObj.move_piece(Pos(next_algebraic_coord)) if valid_move: f = open("pastgames.txt", "a") f.write(color.upper() + " : " + curr_algebraic_coord + " " + next_algebraic_coord + " \n") # f.write(" it went in the else") f.close() if not valid_move: print("Invalid move " + curr_algebraic_coord + " cannot move to " + next_algebraic_coord) else: print("%s moves " % color.upper()) else: print("No object at that place") Board.printBoardOnScreen(board)
def __init__(self, posx, posy, index, map): self._map = map self._pos = Pos(posx, posy) self._index = index self._name = "P" + str(index) # the healing power self._power = random.randint(0, self._HEAL_CAP - 6) + 5
def is_queen_at_diagonal(self, pos: Pos, queens_pos: Dict[int, Pos]): # assume, pos has a queen on it. up_right = [-1, +1] down_right = [+1, +1] up_left = [-1, -1] down_left = [+1, -1] directions = [up_right, down_right, up_left, down_left] for ( i, j, ) in directions: next_row = pos.row + i next_col = pos.col + j while True: if next_row < 0 or next_row >= self.size or next_col < 0 or next_col >= self.size: break if Pos(next_row, next_col) in queens_pos.values(): return True next_row = next_row + i next_col = next_col + j return False
def is_queen_at_column(self, pos: Pos, queens_pos: Dict[int, Pos]): for row in range(self.size): if row == pos.row: continue if Pos(row, pos.col) in queens_pos.values(): return True return False
def __init__(self, posx, posy, index, map): self._map = map self._pos = Pos(posx, posy) self._index = index self._name = "W" + str(index) self._health = self._HEALTH_CAP self._magic_crystal = 10
def move(color): validMove = False # only enters while loop if its a valid move while not validMove: print("%s moves now: " % color.upper()) currAlgebraicCoord = input("Enter the current piece location >") nextAlgebraicCoord = input("Enter the goto location >") if currAlgebraicCoord == "end" or nextAlgebraicCoord == "end": break # type end to exit the program in command line pieceObj, _ = board.piece_from_algebraic_coord(currAlgebraicCoord) if pieceObj: # there is a piece there if pieceObj.color == color: validMove = pieceObj.move_piece(Pos(nextAlgebraicCoord)) # pieces are the same color if validMove: board.updateMoveOnFile(color, currAlgebraicCoord, nextAlgebraicCoord) # update the file if not validMove: # not a valid move # raise exception print("Invalid move " + currAlgebraicCoord + " cannot move to " + nextAlgebraicCoord) else: print("%s moves " % color.upper()) else: print("No object at that place") Board.printBoardOnScreen(board)
def get_un_occupied_position(self): randx = random.randint(0,self._DIMENSION-1) randy = random.randint(0,self._DIMENSION-1) while(self.lands[randx][randy].occupied_obj != None): randx = random.randint(0,self._DIMENSION-1) randy = random.randint(0,self._DIMENSION-1) return Pos(randx,randy)
def __init__(self, right, bottom, sym): super().__init__() self.values.append(Line(Pos(0, 0), Pos(right, 0), sym)) self.values.append(Line(Pos(right - 1, 0), Pos(right - 1, bottom), sym)) self.values.append( Line(Pos(0, bottom - 1), Pos(right, bottom - 1), sym)) self.values.append(Line(Pos(0, 0), Pos(0, bottom), sym))
def main(): my_pos = Pos("28a29a3c154e458298357f5bf9ff3676", "Giz9y4cM") employee_list = my_pos.employees() for emp in employee_list: print emp.id() print emp.first_name() print revenue_center_list = my_pos.revenue_centers() for rev in revenue_center_list: print rev.name() order_type_list = my_pos.order_types() for ord in order_type_list: print ord.name() table_list = my_pos.tables() for tab in table_list: print tab.name() my_pos.create_ticket(employee_list[0], order_type_list[0], revenue_center_list[0], table_list[0], 1, 'auto_ticket')
def setConnection(self, direction, node): if(direction >= 0 and direction <= 3): self.connections[Pos.inverse(direction)] = node node.connections[direction] = self;
#coding=utf-8 from pos import Pos #from publisher import get_topics # TODO: initialize a new Pos object # and test if it is initialized correctly test_pos = Pos('./test_root_dir2/') #TODO: replace print to assert publishers = test_pos.get_publishers() '''print len(publishers) # 3 for current test fixture for publisher in publishers: print publisher.get_name() #print publisher topics = publisher.get_topics() #print topics for topic in topics: print topic.get_name() print topic.get_version() print topic.get_data_profile()'''