# WIN_COMBINATIONS = [(0,1,2),(4,5,6)] ''' Enter position 2 R R __ R G G G Enter position 4 R R G R __ G G Enter position 5 R R G R G __ G Enter position 3 R R G __ G R G Enter position 1 R __ G R G R G Enter position 0 __ R G R G R G Enter position 2 G R __ R G R G Enter position 4 G R G R __ R G Enter position 6 G R G R G R __ Enter position 5 G R G R G __ R Enter position 3 G R G __ G R R Enter position 1 G __ G R G R R Enter position 2 G G __ R G R R Enter position 4 G G G R __ R R Enter position 3 G G G __ R R R You won ''' def swapPositions(board, pre_position, new_pos): b = board # b[pre_position], b[new_pos] = b[new_pos], b[pre_position] temp = b[pre_position] b[pre_position] = b[new_pos] b[new_pos] = temp def print_board(board): for i in board: print(str(i), end=" ") def check_win(board): b = board if b[4] == "R" and b[4] == "R" and b[4] == "R": if b[3] == "__": return True return False return False def update_board(board, pos): # pos is new position pre_position = board.index('__') print(pre_position) if pre_position: # swaping swapPositions(board, pre_position, pos) def verify_move(board, pos): #True if can move # if pos in range(0, 7): # return True # else: return True def enter_move(board): pos = int ( input("\nEnter position: ") ) while not verify_move(board, pos): print ("Invalid position") pos = int ( input("\nEnter position: ") ) return pos def game_stuck(board): #True if no one can move return False def game(): board = ["R","R","R","__","G","G","G"] moves = 0 print_board(board) #you can define the hares positions as 1,1,1 and -1,-1,-1 or "R","R","R" and "G","G","G" #fill the list board according with the representation you prefer while (True): pos = enter_move(board) update_board(board, pos) print_board(board) if check_win(board): return True, moves if game_stuck(board): return False, moves moves += 1 result, moves = game() if result: print (f"You won with {moves} moves") else: print ("You are stuck")