def get_move(self): '''(TippyGameState) -> TippyMove Prompt user and return a move. ''' return TippyMove(int(input('pick a row between 0 and n-1: ')), int(input('pick a column between 0 and n-1: ')))
def get_move(self): """ (TippyGameState) -> TippyMove Prompt user and return move. """ coords = input( "Where would you like to place your piece (in the form" + " 'xy')?") return TippyMove(int(coords[0]), int(coords[1]))
def get_move(self): """(TippyGameState) -> TippyMove Prompt user and return move. """ # Cannot provide docstring examples for get_move because this method # requires input from the user. x = input('Pick the x coordinate of a move: ') y = input('Pick the y coordinate of a move: ') return TippyMove([int(x), int(y)])
def possible_next_moves(self): """ (TippyGameState) -> list of TippyMove Return a possibly empty list of moves that are legal from the present state. """ legal_moves = [] for x in range(len(self.grid)): for y in range(len(self.grid[x])): if self.grid[x][y] == 0: legal_moves.append(TippyMove(x, y)) return legal_moves
def get_move(self): '''(TippyState) -> TippyMove Prompt user to make a move. Then return the as a tuple of coordinates. >>> s1 = TippyState('p1', grid_num=3) >>> s1.get_move() choose to place at row: 4 choose to place at column: 3 TippyMove((4, 3)) ''' i = int(input('choose to place at row: ')) j = int(input('choose to place at column: ')) return TippyMove((i, j))
def get_move(self): ''' (TippyGameState) -> TippyMove Prompt user and return move. ''' move = [] #first row or column taken as 1, then corrected in TippyMove size = len(self.current_state) move.append(int(input('Enter the row (1 to {}): '.format(size)))) move.append(int(input('Enter the column (1 to {}): '.format(size)))) return TippyMove(move)
def possible_next_moves(self): ''' (TippyGameState) -> list of TippyMove Return a (possibly empty) list of moves that are legal from the present state. >>> s1 = TippyGameState('p1', board=['-', '-', '-', '-', '-', '-', '-', '-', '-', '-'] >>> L1 = s1.possible_next_moves() >>> L2 = [TippyMove(0), TippyMove(1), TippyMove(2), TippyMove(3) TippyMove(4), TippyMove(5), TippyMove(6), TippyMove(7), TippyMove(8)] >>> len(L1) == len(L2) and all([m in L2 for m in L1]) True ''' return [ TippyMove(i) for i in range(len(self.board)) if self.board[i] == '-' ]
def possible_next_moves(self): ''' (TippyState) -> list of TippyMove Return a (possibly empty) list of moves that are legal from the present state. >>> s1 = TippyState('p1', grid_num = 3) >>> L1 = s1.possible_next_moves() >>> L2 = [TippyMove((1, 1)), TippyMove((1, 2)), TippyMove((1, 3)), TippyMove((2, 1)), TippyMove((2, 2)), TippyMove((2, 3)), TippyMove((3, 1)), TippyMove((3, 2)), TippyMove((3, 3))] >>> len(L1) == len(L2) and all([m in L2 for m in L1]) True ''' if self.winner('p1') or self.winner('p2'): return [] else: return [TippyMove((i, j)) for (i, j) in self._grid if self._grid[(i, j)] == ' ']
def find_tippies(self): """(FindTippy) -> Nonetype Go through all tippy routes on every single coord in self.board. Search for all possible tippy combinations, append them to self.all_tippies. Exclude any duplicate tippies. """ tippies = [] for x in range(len(self.board)): for y in range(len(self.board[x])): coords = [x, y] tippy_route = [[self.up, self.right, self.up], [self.up, self.left, self.up], [self.down, self.right, self.down], [self.down, self.left, self.down], [self.right, self.up, self.right], [self.right, self.down, self.right], [self.left, self.up, self.left], [self.left, self.down, self.left]] all_routes = [] for route in tippy_route: m = coords.copy() get_route = ([coords] + [c(m).copy() for c in route]).copy() if not ([] in get_route): get_route.sort() new_route = [] for i in range(len(get_route)): new_route.append(TippyMove(get_route[i])) all_routes += [new_route] possible_routes = all_routes for routes in possible_routes: if not routes in tippies: tippies += [routes] return tippies
def possible_next_moves(self): ''' (TippyGameState) -> list of TippyMove Return a (possibly empty) list of moves that are legal from the present state. >>> board = matrix(3) >>> t1 = TippyGameState('p1', board) >>> L1 = t1.possible_next_moves() >>> L2 = [TippyMove(0, 0), TippyMove(0, 1), TippyMove(0, 2), \ TippyMove(1, 0), TippyMove(1, 1), TippyMove(1, 2), TippyMove(2, 0), \ TippyMove(2, 1), TippyMove(2, 2)] >>> (len(L1) == len(L2)) True >>> (all([m in L2 for m in L1])) True ''' return [ TippyMove(i, j) for i in range(len(self.board)) for j in range(len(self.board)) if self.board[i][j] == '_' ]
def possible_next_moves(self): ''' (TippyGameState) -> list of TippyMove Return a (possibly empty) list of moves that are legal from the present state. >>> s1 = TippyGameState('p1') >>> s2 = s1.apply_move(TippyMove([1,1])) >>> s2.possible_next_moves() [TippyMove([1, 2]), TippyMove([1, 3]), TippyMove([2, 1]), TippyMove([2, 2]), TippyMove([2, 3]), TippyMove([3, 1]), TippyMove([3, 2]), TippyMove([3, 3])] ''' moves = [] if not (self.winner('p1') or self.winner('p2')): for i in range(len(self.current_state)): for j in range(len(self.current_state)): if self.current_state[i][j] == ' ': moves.append(TippyMove([i + 1, j + 1])) # the TippyMove representation starts at 1 return moves
def possible_next_moves(self): """(TippyGameState) -> list of TippyMove Return a (possibly empty) list of moves that are legal from the present state. >>> tippygame = TippyGameState('p1') >>> tippygame.possible_next_moves() == [TippyMove([0, 0]),\ TippyMove([1, 0]), TippyMove([2, 0]), TippyMove([0, 1]),\ TippyMove([1, 1]), TippyMove([2, 1]), TippyMove([0, 2]),\ TippyMove([1, 2]), TippyMove([2, 2])] True """ possible_moves = [] if self.winner('p1') or self.winner('p2'): return [] else: for x in range(self.n): for y in range(self.n): if self.board[x][y] is None: possible_moves.append(TippyMove([y, x])) return possible_moves
def get_move(self): '''(TippyGameState) -> TippyMove Prompt user and return move. ''' return TippyMove(int(input('Your turn( 0 to n*n -1): ')))